AVAudioPlayer on iPhone Simulator
With iPhone 2.2, AVAudioPlayer Class is introduced.
AVAudioPlayer simplifies making an object from a file, start/stop/pause media, volume control and looping.
You can find documentation of this class via Apple iPhone Developer site, here we will discuss an issue you’ll probably face while trying to use this class on simulator.
If you are facing problem, playing your media with AVAudioPlayer on Simulator.
Check your /Library/Quicktime directory.
Browse files in this directory and find third party add-ons like Perian, DivX etc.
Move these add-ons in to another folder while you are developing with AVAudioPlayer
Now Test your Application, AVAudioPlayer should run without any problem.
Don’t forget to move your add-ons back to Quicktime Directory after you finished development ;)
Here is a quick AVAudioPlayer usage example,
-(IBAction)playMovie:(id)sender{
NSString *newAudioFile = [[NSBundle mainBundle] pathForResource:@”MusicFile” ofType:@”mp3″];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:newAudioFile] error:NULL];
[audioPlayer setDelegate:self];
[audioPlayer prepareToPlay];
BOOL plays = [audioPlayer play];
}
Thanks to Mert Yentur, for discovering and sharing that issue.
Bests.
G.
If you enjoyed this post, make sure you subscribe to my RSS feed!
Flickr







Recent Posts
Subscribe to my blog
stationstops
bless you sir.
good god, how long would I have been a programmer without google?
March 30th, 2009 at 12:42 pmt
Oh man. I’ve been wrestling with this for DAYS. Thank you kind sir.
April 28th, 2009 at 12:27 pmRich
This is great…I never would have figured that out. Thanks!
May 22nd, 2009 at 7:00 pmHarinder
Thanks for this example.This is simplest and exaplainful
I have some other problem, and i think it is realted with AVAuidioPlayer class..
I am workin on an application that allows users to play and record Audio/Video.
But problem is that, functionality is working fine on simulator.. Its recording and playing too..
But on iPhone, its not playing the file, even though file is getting recorded..
Thanks in advance :)
August 17th, 2009 at 12:30 pmshiva
Hi,
I dont have any problem with AVAudioPlayer in simulator. But i am facing strange memory leak.
In simulator :
GeneralBlock-240,
SegmentMachO
in Device
GeneralBlock-3584
Could any one give me some sample code..
Thank you
August 25th, 2009 at 7:06 amshiva
Guvener Gokce
Hi Harinder,
It is hard to find out real problem without checking the code but I think you should check the recording format. Because When targeting the Simulator, if you are using SpeakHere sample of Apple, SpeakHere uses linear PCM regardless of the format specified in the code. May be you should try other recording formats and see the results :)
Other Recording formats:
kAudioFormatLinearPCM, kAudioFormatAppleLossless, kAudioFormatAppleIMA4, kAudioFormatiLBC, kAudioFormatULaw,kAudioFormatALaw
Hi Shiva,
I have created a sample application for you,
http://www.guvenergokce.com/codesample/AVAudioPlayerSample.zip
BTW you should also check Apple’s avTouch sample code.
http://developer.apple.com/iphone/library/samplecode/avTouch/index.html
Bests,
August 25th, 2009 at 4:28 pmG.
blacksheep
hi guvener,
i downloaded apple’s avTouch.zip, but errors showing up when compiling in these lines:
- (void)updateCurrentTime;
- (void)updateViewForPlayerState; : error: expected `{’ before ‘-’ token
- (void)updateViewForPlayerInfo; : error: expected `{’ before ‘-’ token
- (void)setupAudioSession; : error: expected `{’ before ‘-’ token
- (void)ffwd : error: expected `{’ before ‘-’ token
- (void)rewind : error: expected `{’ before ‘-’ token
- (void)awakeFromNib : error: expected `{’ before ‘-’ token
and i did not chance anything inside the code!
what is wrong there?
greetings
September 28th, 2009 at 8:47 amblacksheep
Xochitl Pooschke
Oh wow just what ya posted about really made me happier! (ok i know you’ll reckon im a retard haha!) You deserve to spend some time relaxing with some decent
April 20th, 2010 at 12:01 am