I have an app on the store since one year, and few persons owning an iPhone 4S tell me that sounds are not playing on their devices. (they do not hear anything, either with earphones or with internal speaker)
I have still tested on real devices (iPhone 3G, 3GS, 4, ipod 1G, 2G, 3G, 4G, ipad 1,2,3) and all seems correct. Sounds are playing.
(tested on various OS : iOS 3.1.2 –> 6.0, and it works also in simulator)
Unfortunately i have not myself an iphone 4S for testing, so it’s very hard to know what’s wrong with this particular device.
Could it be a problem with iPhone sound settings ?
But maybe it’s a problem regarding my code ?
So, here is the code i use to play sounds.
Is it correct ?
in the .h …:
@private AVAudioPlayer* myPlayer;
in the .m …:
-(IBAction)playMySound{
playerPlay = YES; // it's a bool variable used at an other place in the code
NSString *path;
if((path = [[NSBundle mainBundle]
pathForResource:[NSString stringWithFormat:@"%d", idsound ]
ofType:@"m4a"
inDirectory:@"sounds"]))
{
NSURL *url = [NSURL fileURLWithPath:path];
NSError *error;
myPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
if (myPlayer == nil) {[myPlayer release]; return;}
myPlayer.delegate = self;
[myPlayer play];
}
else return;
}
Any advice would be appreciated !
You code is really weird:
Here you correctly create the player:
The you check if it is
nil, still correct.But then you call
releaseon a nil object, which wil do nothing since the object is nil:This should be a bit better: