Is there a public way to force MPNowPlayingInfoCenter to show podcast controls?

后端 未结 5 1669
无人及你
无人及你 2020-11-30 17:43

I would like Control Center (via MPNowPlayingInfoCenter) to show the forward 15 seconds / back 15 seconds controls that Apple shows with podcasts, like so:

5条回答
  •  爱一瞬间的悲伤
    2020-11-30 18:07

    For Swift developers

    import MediaPlayer
    
    let rcc = MPRemoteCommandCenter.shared()
    
    let skipBackwardCommand = rcc.skipBackwardCommand
    skipBackwardCommand.isEnabled = true
    skipBackwardCommand.addTarget(handler: skipBackward)
    skipBackwardCommand.preferredIntervals = [42]
    
    let skipForwardCommand = rcc.skipForwardCommand
    skipForwardCommand.isEnabled = true
    skipForwardCommand.addTarget(handler: skipForward)
    skipForwardCommand.preferredIntervals = [42]
    
    func skipBackward(_ event: MPRemoteCommandEvent) -> MPRemoteCommandHandlerStatus {
        guard let command = event.command as? MPSkipIntervalCommand else {
            return .noSuchContent
        }
    
        let interval = command.preferredIntervals[0]
    
        print(interval) //Output: 42
    
        return .success
    }
    
    func skipForward(_ event: MPRemoteCommandEvent) -> MPRemoteCommandHandlerStatus {
        guard let command = event.command as? MPSkipIntervalCommand else {
            return .noSuchContent
        }
    
        let interval = command.preferredIntervals[0]
    
        print(interval) //Output: 42
    
        return .success
    }
    

    Other command would be the similar and they can be checked here

提交回复
热议问题