使用场景:
tabelView多个cell携带音乐播放.包含音乐库音乐/Bundle中的音乐播放.使用到了MPMusicPlayerController
与AVAudioPlayer
类.
抛出问题
以下代码会把系统音乐播放器给停掉
if (self.audioPlayer.isPlaying) {
[self.audioPlayer stop];
}
问题代码
if (self.audioPlayer.isPlaying) {
[self.audioPlayer stop];
}
// 停止喇叭闪动
[self.alarmTimer invalidate];
self.alarmTimer = nil;
self.menu.isAlarming = NO;
[self restoreAlarmBtuttonState];
MPMusicPlayerController *musicVc = [MPMusicPlayerController systemMusicPlayer];
if (musicVc.playbackState == MPMusicPlaybackStatePlaying) {
// 其他cell还在用系统播放器,不能停止
if ([self.superVc judgeCellIsAlarmSystemMusic]) {
return ;
}
[musicVc stop];
}
解决问题
// 停止喇叭闪动
[self.alarmTimer invalidate];
self.alarmTimer = nil;
self.menu.isAlarming = NO;
[self restoreAlarmBtuttonState];
MPMusicPlayerController *musicVc = [MPMusicPlayerController systemMusicPlayer];
if (musicVc.playbackState == MPMusicPlaybackStatePlaying) {
// 其他cell还在用系统播放器,不能停止
if ([self.superVc judgeCellIsAlarmSystemMusic]) {
return ;
}
[musicVc stop];
} else {
if (self.audioPlayer.isPlaying) {
[self.audioPlayer stop];
}
}
网友评论