swiftavfoundationmpremotecommandcenter

MPRemoteCommandCenter Error in swift 4


I am trying to setup my app to use MPRemoteCommandCenter. I got this example from the document programming guide. I imported AVFoundation and even tried importing AVKIT, I am getting the error Use of unresolved identifier 'MPRemoteCommandCenter'. When I create an instance of MPRemoteCommandCenter.shared(). Any help would be appreciated.

func setupRemoteTransportControls() {

    // Get the shared MPRemoteCommandCenter
    let commandCenter = MPRemoteCommandCenter.shared()   Error //**Use of unresolved identifier 'MPRemoteCommandCenter'**

    // Add handler for Play Command
    commandCenter.playCommand.addTarget { [unowned self] event in
        if self.audioPlayer.rate == 0.0 {
            self.audioPlayer.play()
            return .success
        }
        return .commandFailed
    }

    // Add handler for Pause Command
    commandCenter.pauseCommand.addTarget { [unowned self] event in
        if self.audioPlayer.rate == 1.0 {
            self.audioPlayer.pause()
            return .success
        }
        return .commandFailed
    }
}

Solution

  • You need to import MediaPlayer