Swift 2 - 更改按钮 Background/Lock-Screen MediaPlayer
Swift 2 - Change buttons Background/Lock-Screen MediaPlayer
在我的应用程序中,我启用了背景音频,以便用户可以从锁定屏幕播放、暂停、跳过曲目。
但是一切正常,我找不到显示 next track
和 previous track
按钮的方法。
现在“MediaPlayer”显示不同的按钮(见附图)
在我的 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")
}
}
如何更改按钮以显示下一个和上一个按钮?
为了将来参考,可以使用:
Swift 2:
MPRemoteCommandCenter.sharedCommandCenter().skipBackwardCommand.enabled = false
MPRemoteCommandCenter.sharedCommandCenter().seekBackwardCommand.enabled = false
MPRemoteCommandCenter.sharedCommandCenter().skipForwardCommand.enabled = false
MPRemoteCommandCenter.sharedCommandCenter().seekForwardCommand.enabled = false
在我的应用程序中,我启用了背景音频,以便用户可以从锁定屏幕播放、暂停、跳过曲目。
但是一切正常,我找不到显示 next track
和 previous track
按钮的方法。
现在“MediaPlayer”显示不同的按钮(见附图)
在我的 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")
}
}
如何更改按钮以显示下一个和上一个按钮?
为了将来参考,可以使用:
Swift 2:
MPRemoteCommandCenter.sharedCommandCenter().skipBackwardCommand.enabled = false
MPRemoteCommandCenter.sharedCommandCenter().seekBackwardCommand.enabled = false
MPRemoteCommandCenter.sharedCommandCenter().skipForwardCommand.enabled = false
MPRemoteCommandCenter.sharedCommandCenter().seekForwardCommand.enabled = false