[英]Problem in playing sound in application?
我開發了一個簡單的游戲應用程序,可以在其中播放帶有UIView動畫的聲音。
theAudioPlayer = [[AVAudioPlayer alloc] init];
[theAudioPlayer initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"pageTurn"] ofType:@"mp3"]] error:NULL];
[theAudioPlayer play];
其中,AudioPlayer是AVAudioPlayer類的實例對象。 現在我的問題是當我在UIViews動畫的聲音變為靜音的10-15分鍾后玩游戲時,它再也無法播放了,為什么?
感謝您發送查看我的問題。
首先,加載代碼不必要地復雜。 您只應初始化播放器一次,然后直接從捆綁軟件中獲取示例URL:
theAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:
[[NSBundle mainBundle] URLForResource:@"pageTurn" ofType:@"mp3"] error:NULL];
如果能夠單獨解決問題(考慮到多次初始化),我不會感到驚訝。 如果不是,那很有可能,您如何釋放播放器? 你完全釋放它嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.