Search code examples
ios11xcode9-betaswift4

Ambiguous use of play of MPMusicPlayerController in iOS11, swift4


I'm running the Apple iOS11 example Adding Content to Apple Music on Xcode Version 9.0 beta 3 (9M174d).

I get a Ambiguous use of 'play() in

/adding-content-to-apple-music/AppleMusicSample/Controllers/MusicPlayerManager.swift:78:9: Ambiguous use of 'play()'

The suggested solutions to explicitly define the selector in order to avoid the ambiguity like:

let play = #selector(musicPlayerController.play)

did not work in this case.

The MPMusicPlayerController instance in the MusicPlayerManager class is defined as

let musicPlayerController = MPMusicPlayerController.systemMusicPlayer 

and then referred like

func beginPlayback(itemID: String) {
        musicPlayerController.setQueue(with: [itemID])

        musicPlayerController.play()
    }

I have put the code for the MusicPlayerManager class here.


Solution

  • Write

        (musicPlayerController as MPMediaPlayback).play()