Pages

Tuesday 9 December 2014

How to play Audio in iOS






1] Add AVFoundation.framwork in Project

2] then import this framwork in code 

#import <AVFoundation/AVFoundation.h>


3] Make the object for  AVAudioPlayer and make property synthesise for it


@property(strong,nonatomic)AVAudioPlayer *player;



4] And then add following code where you want to play sound/audio file


    NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"Snake sound"
                                                                      ofType:@".mp3"];
   
   NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
            
   self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL
                                                                 error:nil];
            
            
   [self.player play];


[Note : - if you want to stop then     [self.player Stop];         and if you want to pause then [self.player Pause]; ]

  
- अर्जुन  टवळ


No comments:

Post a Comment