Having trouble with MusicKit sample app provided by Apple

社会主义新天地 提交于 2019-12-08 03:30:18

问题


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()
    }
}

回答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.



来源:https://stackoverflow.com/questions/45080188/having-trouble-with-musickit-sample-app-provided-by-apple

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!