Having trouble with MusicKit sample app provided by Apple
Asked Answered
R

1

1

I am trying to build "Adding Content to Apple Music”, Music Kit sample app provided by Apple, on Xcode 9 beta 3. However I am having 4 errors like this : three “Ambiguous use of 'play()’” errors and one “Ambiguous use of 'pause()’”

Please tell me how to fix this if you already solved this problem.

func beginPlayback(itemCollection: MPMediaItemCollection) {
    musicPlayerController.setQueue(with: itemCollection)

    //Ambiguous use of 'play()’
    musicPlayerController.play()
}

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

    //Ambiguous use of 'play()’
    musicPlayerController.play()
}

// MARK: Playback Control Methods

func togglePlayPause() {
    if musicPlayerController.playbackState == .playing {

        //Ambiguous use of 'pause()’
        musicPlayerController.pause()
    } else {

        //Ambiguous use of 'play()’
        musicPlayerController.play()
    }
}
Ricer answered 13/7, 2017 at 12:8 Comment(0)
R
1

I have found a similar question in the Apple's Dev Forums:

MPMusicPlayerController Swift4 - Ambiguous Use of Play

According to an entry writing a fix to work around the issue, you need to change this line in MusicPlayerManager.swift:

let musicPlayerController = MPMusicPlayerController.systemMusicPlayer

(musicPlayerController's type becomes MPMusicPlayerController & MPSystemMusicPlayerController with this code.)

To:

let musicPlayerController: MPMusicPlayerController = MPMusicPlayerController.systemMusicPlayer

(musicPlayerController is explicitly annotated as MPMusicPlayerController.)


In my opinion this is a bug of Swift related to SE-0156 Class and Subtype existentials and you should better send a bug report to Apple or swift.org.

Reis answered 13/7, 2017 at 13:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.