Sign in to follow this  

[iPhone] AVAudioPlayer and SoundEffect only work in simulator

Recommended Posts

I've tried AVAudioPlayer and now SoundEffect (from Apple sample code) and both work fine in simulator but not on my iPhone (software version 4.2.1).

Any ideas why?

And tell me if there's a better site to ask this question.

EDIT: I also asked on [url=""][/url] and [url=""]https://discussions..../thread/3258943[/url].

Share this post

Link to post
Share on other sites
I started a new OpenGL ES project and added AVFoundation framework and

[code]#import <AVFoundation/AVAudioPlayer.h>
#import <AudioToolbox/AudioServices.h>[/code]


[code]- (void) viewDidLoad

NSString* soundFilePath = [[NSBundle mainBundle] pathForResource: @"csva" ofType: @"caf"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
NSError *error = nil;
AVAudioPlayer* sound = [[AVAudioPlayer alloc] initWithContentsOfURL: fileURL error: &error];

NSLog(@"error: %@ (%@)", error, error.userInfo);
NSLog(@"no error");

sound.delegate = self;
sound.volume = 1.0f;
[sound prepareToPlay];
[fileURL release];
[sound play];

and added /sounds/ to the project, but it still doesn't work on my iPhone.

Here is the project:


SOLVED: my phone ring switch was set to mute.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this