有没有办法获取上一首 iPod 歌曲的信息?
我试图在下一首歌曲开始播放之前存储歌曲(MPMediaItem)的播放头时间。你会怎么做?
是否有类似 MPMusicPlayerControllerNowPlayingItemDidChangeNotification
的东西会在歌曲更改之前触发?
I'm trying to store the playhead time of a song (MPMediaItem) before the next song begins to play. How would you do that?
Is there something like MPMusicPlayerControllerNowPlayingItemDidChangeNotification
which fires before the song changes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
简单:当歌曲更改时,将变量
foo
设置为当前时间,并将另一个变量bar
设置为新歌曲的当前播放时间(通常为0.0
。)当歌曲再次发生变化时,从当前时间减去foo
的值,然后加上bar
的值;结果是刚刚播放的歌曲的最终偏移量。您还必须处理快进、快退、停止和暂停,但您可以通过监视播放状态并查询歌曲的当前播放时间来根据需要保持同步来做到这一点。
Simple: When the song changes, set a variable
foo
somewhere to the current time, and set another variablebar
to the new song's current playback time (usually gonna be0.0
.) When the song changes again, subtract the value offoo
from the current time, then add the value ofbar
; the result is the final offset of the song that was just being played.You'll also have to handle fast forward, rewind, stop, and pause, but you can do that by monitoring the playback state and querying the song's current playback time to keep yourself in sync as needed.
我认为,今天不存在这样的通知(歌曲更改前通知)。
我只找到两个可以监听歌曲状态变化的通知。
苹果文档:
http://developer.apple .com/library/ios/#documentation/mediaplayer/reference/MPMusicPlayerController_ClassReference/Reference/Reference.html
I do'nt think, there is such notification(Notify before song change) exist today.
I just find only two notification which can be listen for songs change state.
Apple Documentation:
http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPMusicPlayerController_ClassReference/Reference/Reference.html
我认为在媒体项目更改之前没有通知。最好的方法似乎是使用计时器不断地将值从媒体播放器复制到变量来存储 NSTimeInterval,直到媒体项更改或媒体播放器状态更改。
I think there is no notification before media item is changed. The best way seems to use a timer to constantly copying the value from media player to a variable to store NSTimeInterval, until media item is changed or media player state is changed.