2015-06-04 51 views
0

我是最新的Xcode版本。我正在使用以下代碼重新啓動我的背景音樂。但是這些代碼不會重新啓動背景音樂。AVAudioPlayer沒有重新啓動bg音樂?

NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"game" ofType:@"wav"]; 
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath]; 
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil]; 
[player stop]; 
player.currentTime = 0; 
[player play]; 
+0

什麼是不工作的意思?你有錯誤嗎? – thegrinner

+0

我沒有收到錯誤。但是每次當我點擊開始按鈕時,音樂都會一直播放。 –

回答

1

要使用AVAudioPlayer,您需要一個強大的參考。嘗試將播放器設置爲控制器的屬性,然後使用[self.player play]

0

將AVAudioPlayer聲明爲.h文件。