Swift 2 - 更改按钮背景/锁屏MediaPlayer

时间:2015-11-25 11:54:10

标签: ios audio mpnowplayinginfocenter

在我的应用程序中,我启用了背景音频,以便用户可以播放,暂停,从锁定屏幕跳过曲目。

但是一切正常,我找不到显示next trackprevious track按钮的方法。

现在`'MediaPlayer'显示不同的按钮(参见附图)

enter image description here

在我的AppDelegate.swift我有:

override func remoteControlReceivedWithEvent(event: UIEvent?) {
        if event!.type == UIEventType.RemoteControl {
            if event!.subtype == UIEventSubtype.RemoteControlPlay {
                print("received remote play")

            } else if event!.subtype == UIEventSubtype.RemoteControlPause {
                print("received remote pause")

            } else if event!.subtype == UIEventSubtype.RemoteControlTogglePlayPause {
                print("received toggle")

            }else if event!.subtype == UIEventSubtype.RemoteControlNextTrack{
                print("received next")

            }
        }

如何更改按钮以显示下一个和上一个按钮?

1 个答案:

答案 0 :(得分:1)

为了将来参考,可以使用以下方法完成:

斯威夫特2:

        MPRemoteCommandCenter.sharedCommandCenter().skipBackwardCommand.enabled = false
        MPRemoteCommandCenter.sharedCommandCenter().seekBackwardCommand.enabled = false
        MPRemoteCommandCenter.sharedCommandCenter().skipForwardCommand.enabled = false
        MPRemoteCommandCenter.sharedCommandCenter().seekForwardCommand.enabled = false