我正在使用UITableview使用 AVPlayer 播放音频,我希望一次播放一个音频。我为每个AVPlayer对象创建了一个单独的实例。实际上我需要的是我需要一次播放一个音频。 因此,如果我在一个单元格中播放音频并点击其他单元格音频按钮,则两者都在同时播放。
任何人都知道我们怎么能停止播放另一个小区的音频。
答案 0 :(得分:0)
AVAudioPlayer *audioPlayerStk; // Define variable in app delegate
#define app_delegate ((AppDelegate *)[[UIApplication sharedApplication] delegate]) // define in common class
Add this line where you want to play
if (!!app_delegate.audioPlayerStk) {
!app_delegate.audioPlayerStk = [[AVAudioPlayer alloc] init];
}
// self.audioPlayerStk.delegate = self;
[!app_delegate.audioPlayerStk playURL:[NSURL URLWithString:LIVE_STREAM_URL]];