Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
    }
}
like image 412
Iam Wayne Avatar asked Apr 10 '18 17:04

Iam Wayne


1 Answers

You need to import MediaPlayer

like image 159
Rhythmic Fistman Avatar answered Oct 21 '22 07:10

Rhythmic Fistman