如何分辨MPNowPlayingInfoCenter羯羊或不正在播放的音乐或暂停? [英] How to tell the MPNowPlayingInfoCenter wether or not the music is playing or paused?

查看:496
本文介绍了如何分辨MPNowPlayingInfoCenter羯羊或不正在播放的音乐或暂停?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法使iOS的显示远程音频控制正确的播放/暂停按钮。我确实收到遥控器的事件,并设置 nowPlayingInfo 词典的所有值。

I can't seem to make iOS show the correct play / pause button in the remote audio controls. I do receive the remote control events and set all values of the nowPlayingInfo dictionary.

一切正常,我甚至看到了锁定屏幕上封面照片。除暂停/播放键。它总是看起来即使我的 AVAudioPlayer 播放暂停。不管它发出播放状态的暂停事件。

Everything works fine and I even see a cover photo on the lock screen. Except the pause/play button. It always looks like pause even if my AVAudioPlayer is playing. It sends a pause event regardless of playback state.

我怎么能通知AVAudioPlayer暂停iOS和它现在应该显示在遥控器的按钮栏播放按钮?

How can I notify iOS that AVAudioPlayer is paused and that it should now show a play button in the remote control buttons bar?

推荐答案

请确保您设置MPNowPlayingInfoPropertyPlaybackRate财产。 0.0以表示暂停,1.0F指示播放。您还需要当你改变这些值来设置MPNowPlayingInfoPropertyElapsedPlaybackTime。例如code其中updateMetadata是适用这些改变MPNowPlayingInfoCenter.nowPlayingInfo字典的功能。这表明在中心的播放暂停。

Make sure that you're setting the MPNowPlayingInfoPropertyPlaybackRate property. 0.0f to indicate paused, 1.0f to indicate playing. You'll also need to set the MPNowPlayingInfoPropertyElapsedPlaybackTime when you change these values. Example code where updateMetadata is a function that applies those changes to the MPNowPlayingInfoCenter.nowPlayingInfo dictionary. This would indicate to the center that the player is paused.

       [self updateMetadata:[NSDictionary dictionaryWithObjectsAndKeys:
                          [NSNumber numberWithDouble:audioFile.player.currentTime] , MPNowPlayingInfoPropertyElapsedPlaybackTime,
                          [NSNumber numberWithFloat:0.0f], MPNowPlayingInfoPropertyPlaybackRate,
                          nil]];

这篇关于如何分辨MPNowPlayingInfoCenter羯羊或不正在播放的音乐或暂停?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆