MPRemoteCommandCenter Error in swift 4
Asked Answered
A

1

9

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
    }
}
Amalgamate answered 10/4, 2018 at 17:44 Comment(0)
C
32

You need to import MediaPlayer

Curagh answered 10/4, 2018 at 17:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.