- (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时它会播放另一首曲目。那么我就有两条曲目在互相播放。我怎么能让它停下来?
答案 0 :(得分:2)
将您的AVAudioPlayer
实例存储在属性中,并在希望它停止播放时将其命名为stop
方法。