Translate

Friday, April 6, 2012

How to play an audio file on launch of IOS application?


Apple provided a very good framework called 'AVFoundation' provides an Objective-C interface for  managing and playing the audio-visual media in your IOS applications.
Please follow the below steps to integrate the audio file to your project:
1. Add the 'AVFoundation.framework' to your frameworks folder in the project.
2. Add the statement  #import <AVFoundation/AVFoundation.h>
3. Add the file 'Output.aif' (an audio file) to your project.
4. Have the following snippet of code in your viewDidLoad method

    
NSString *path = [[NSBundle mainBundle] pathForResource:@"Output" ofType:@"aif"];  
    
AVAudioPlayer *theAudio = 
        [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];  
    
theAudio.delegate = self;  
    
[theAudio play];

5. Run the application. You will start listening the music.

No comments:

Post a Comment