停止播放目标c的声音?

时间:2013-02-17 20:08:39

标签: ios objective-c avaudioplayer

- (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时它会播放另一首曲目。那么我就有两条曲目在互相播放。我怎么能让它停下来?

1 个答案:

答案 0 :(得分:2)

将您的AVAudioPlayer实例存储在属性中,并在希望它停止播放时将其命名为stop方法。