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 amJeanice Coogan
*Aw, this was a really nice post. In idea I would like to put in writing like this additionally – taking time and actual effort to make a very good article… but what can I say… I procrastinate alot and by no means seem to get something done.
March 27th, 2011 at 2:22 pmRoselia Luoto
You completed certain nice points there. I did a search on the theme and found mainly people will consent with your blog.
April 15th, 2011 at 9:53 amdzień matki
I will right away grab your rss as I can not find your e-mail subscription link or newsletter service. Do you’ve any? Kindly let me know in order that I could subscribe. Thanks.
May 5th, 2011 at 1:43 pmsklep elektryczny
whoah this blog is wonderful i love reading your posts. Keep up the great work! You know, lots of people are looking around for this info, you can aid them greatly.
August 18th, 2011 at 2:16 amMuzyka
That’s one of the most interesting websites I’ve read since I remember! You make it attractive and easy to understand - I love the way you do it. Keep on!
August 24th, 2011 at 2:31 amAnthony
Here is an example of an App that shows an mp3 list, you select one and it plays it. With progress bar, play, pause button.
https://github.com/toptierlabs/Mp3Player
October 4th, 2011 at 1:22 pm