有没有办法获取上一首 iPod 歌曲的信息?

发布于 2024-10-24 04:35:02 字数 153 浏览 6 评论 0原文

我试图在下一首歌曲开始播放之前存储歌曲(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

人间☆小暴躁 2024-10-31 04:35:02

简单:当歌曲更改时,将变量 foo 设置为当前时间,并将另一个变量 bar 设置为新歌曲的当前播放时间(通常为 0.0。)当歌曲再次发生变化时,从当前时间减去foo的值,然后加上bar的值;结果是刚刚播放的歌曲的最终偏移量。

您还必须处理快进、快退、停止和暂停,但您可以通过监视播放状态并查询歌曲的当前播放时间来根据需要保持同步来做到这一点。

Simple: When the song changes, set a variable foo somewhere to the current time, and set another variable bar to the new song's current playback time (usually gonna be 0.0.) When the song changes again, subtract the value of foo from the current time, then add the value of bar; 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.

街角迷惘 2024-10-31 04:35:02

我认为,今天不存在这样的通知(歌曲更改前通知)。
我只找到两个可以监听歌曲状态变化的通知。

MPMusicPlayerControllerNowPlayingItemDidChangeNotification,
MPMusicPlayerControllerPlaybackStateDidChangeNotification,

苹果文档:

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.

MPMusicPlayerControllerNowPlayingItemDidChangeNotification,
MPMusicPlayerControllerPlaybackStateDidChangeNotification,

Apple Documentation:

http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPMusicPlayerController_ClassReference/Reference/Reference.html

梦一生花开无言 2024-10-31 04:35:02

我认为在媒体项目更改之前没有通知。最好的方法似乎是使用计时器不断地将值从媒体播放器复制到变量来存储 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文