2015-06-04 53 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文件。