开发者

Problem in playing sound in application?

I developing simple game application in which i playing sound with UIView animation.

theAudioPlayer = [[AVAudioPlayer alloc] init];  

[theAudioPlayer initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"pageTurn"] ofType:@"mp3"]] error:NULL];

[theAudioPlayer play];

where theAudioPlayer is the instance object of AVAudioPlayer class. Now my problem is when i playing the game after 10-15 minutes during the animation of UIViews sound going to mute.It never play again, why?

Thanks for sending an viewing m开发者_C百科y question.


First, the loading code is needlessly complex. You should only initialize the player once and get the sample URL right from the bundle:

theAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:
    [[NSBundle mainBundle] URLForResource:@"pageTurn" ofType:@"mp3"] error:NULL];

I would not be surprised if that solved the problem alone (given the multiple initialization). And if it does not, which is quite probable, how do you release the player? Do you release it at all?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜