我是Swift开发的新手,我正在尝试使用以下方法在锁定屏幕上播放/暂停多个音频文件:
remoteControlReceived
但是它只允许我添加一次,这意味着我只能控制一个音频文件,但我希望其他2个音频文件在锁定屏幕上启用播放/暂停。
以下是我正在使用的代码:
// Playback controls
override func remoteControlReceived(with event: UIEvent?) {
if let event = event {
if event.type == .remoteControl {
switch event.subtype {
case .remoteControlPlay: audioPlayer.play()
case . remoteControlPause: audioPlayer.pause()
default: print("Done")
}
}
}
}
override func remoteControlReceived0(with event: UIEvent?) {
if let event = event {
if event.type == .remoteControl {
switch event.subtype {
case .remoteControlPlay: audioPlayer1.play()
case . remoteControlPause: audioPlayer1.pause()
default: print("Done")
}
}
}
}
func remoteControlReceived(with event: UIEvent?) {
if let event = event {
if event.type == .remoteControl {
switch event.subtype {
case .remoteControlPlay: audioPlayer2.play()
case . remoteControlPause: audioPlayer2.pause()
default: print("Done")
}
}
}
}
答案 0 :(得分:0)
但是它只允许我添加一次,这意味着我只能控制一个音频文件,但我希望其他2个音频文件在锁定屏幕上启用播放/暂停
您不能。它仅引用正在播放的项目。