gpt4 book ai didi

iphone - 使用MPMusicPlayerController播放MPMediaItemCollection,如何获取播放结束时的事件

转载 作者:行者123 更新时间:2023-12-03 19:40:29 25 4
gpt4 key购买 nike

我正在使用 MPMusicPlayerController 播放 MPMediaItemCollection 中的 MPMediaItems。当 MPMediaItem 播放完毕时,如何触发事件?

最佳答案

注册MPMusicPlayerControllerPlaybackStateDidChangeNotification通知:

[notificationCenter addObserver:self selector:@selector(handlePlaybackStateChanged:) name:MPMusicPlayerControllerPlaybackStateDidChangeNotification object:self.musicPlayer];

并告诉您的 musicPlayerController 生成这些通知:

[self.musicPlayerController beginGeneratingPlaybackNotifications];

handlePlaybackStateChanged:中,您可以检查musicPlayerController的playbackState属性:

- (void)handlePlaybackStateChanged:(NSNotitication*)notification
{
if (self.musicPlayerController.playbackState == MPMusicPlaybackStateStopped ||
self.musicPlayerController.playbackState == MPMusicPlaybackStateInterrupted ||
self.musicPlayerController.playbackState == MPMusicPlaybackStatePaused) {
// do your stuff
}
}

关于iphone - 使用MPMusicPlayerController播放MPMediaItemCollection,如何获取播放结束时的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4024147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com