gpt4 book ai didi

ios - addObserver forkeypath 在 MPMusicPlayerController 中不起作用

转载 作者:行者123 更新时间:2023-11-28 22:12:12 25 4
gpt4 key购买 nike

我正在使用以下代码来了解当前播放 时间。但是当我使用 MPMusicPlayerController 播放歌曲时它不起作用。请帮我解决这个问题。任何想法或建议都将不胜感激

[self addObserver:self forKeyPath:@"musicPlayer.currentPlaybackTime" options:0 context:nil];

歌曲播放代码

MPMediaItemCollection *collection = [[MPMediaItemCollection alloc] initWithItems:[NSArray arrayWithObject:song]];
[musicPlayer setQueueWithItemCollection:collection];

[musicPlayer prepareToPlay];
[musicPlayer setNowPlayingItem:song];
//[self.musicPlayer setVolume:volumeSlider.value];
[musicPlayer play];

最佳答案

正如 Volker 所说,该属性(property)不符合 KVO。请参阅此处的文档以了解要监听的 nsnotification 事件。还要确保你打电话

[musicplayer beginGeneratingPlaybackNotifications]

[musicplayer endGeneratingPlaybackNotifications]

作为引用,这些是由 mpmusicplayercontroller 发布的通知:

MPMusicPlayerControllerPlaybackStateDidChangeNotification
MPMusicPlayerControllerNowPlayingItemDidChangeNotification
MPMusicPlayerControllerPlaybackStateDidChangeNotification
MPMusicPlayerControllerNowPlayingItemDidChangeNotification

https://developer.apple.com/library/ios/documentation/mediaplayer/reference/MPMusicPlayerController_ClassReference/Chapters/Reference.html#//apple_ref/occ/instm/MPMusicPlayerController/beginGeneratingPlaybackNotifications

关于ios - addObserver forkeypath 在 MPMusicPlayerController 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22609382/

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