0
- (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 时,都会发生这种情况,它会播放另一个音轨。所以我有两首曲目相互播放。我怎样才能让它停止?

4

1 回答 1

2

将您的AVAudioPlayer实例存储在一个属性中,并stop在您希望它停止播放时调用它的方法。

于 2013-02-17T20:12:12.743 回答