停止播放目标c的声音?
问题描述:
- (void)viewDidLoad {
[super viewDidLoad];
[audioPlayer stop];
NSString *Path = [[NSBundle mainBundle] pathForResource:@"Keep the Shoes Moving" ofType: @"m4a"];
NSURL *URL = [[NSURL alloc] initFileURLWithPath: Path];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:URL error:&error];
audioPlayer.numberOfLoops = -1;
[audioPlayer play];
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; }
这会发生什么,每次我回到这个viewController它播放另一个轨道。那么我有两个音轨互相播放。我将如何得到这个停止?停止播放目标c的声音?
答
将您的AVAudioPlayer
实例存储在一个属性中,并在您希望它停止播放时将其称为stop
方法。
非常感谢您的帮助。你可以请进一步解释,因为我是一个开始的编码器。我知道AVAudioPlayer是什么,但是通过将其称为停止方法意味着什么。你的意思是“[audioPlayer停止];”?如果这是你的意思,我在viewDidLoad的开头称之为。我应该改变它吗?谢谢你的帮助。 – user1807869 2013-02-17 20:45:28
你有没有设法解决这个问题?我有同样的问题,'stop'永远不会被调用,因为我已经在这里解释它:http://stackoverflow.com/questions/20164873/avaudioplayer-is-always-nill-and-its-isplaying-property-is -always-false-the-fil 我即将声明一个全局变量并使用它,但我很乐意为此找到更好的解决方案。 – Neeku 2013-11-25 16:08:24