使用Apple提供的MusicKit示例应用程序时遇到问题

时间:2017-07-13 12:08:57

标签: swift ios11 xcode9-beta swift4 apple-musickit

我正在尝试在Xcode 9 beta 3上为Apple提供的Music Kit示例应用程序“添加内容到Apple Music”。但是我有4个这样的错误:三个“模糊地使用'play()'”错误和一个“模糊地使用'pause()'”

如果你已经解决了这个问题,请告诉我如何解决这个问题。

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 个答案:

答案 0 :(得分:1)

我在Apple的开发论坛中发现了一个类似的问题:

MPMusicPlayerController Swift4 - Ambiguous Use of Play

根据编写修复程序以解决此问题的条目,您需要在MusicPlayerManager.swift中更改此行:

let musicPlayerController = MPMusicPlayerController.systemMusicPlayer

musicPlayerController的类型变为MPMusicPlayerController & MPSystemMusicPlayerController此代码。)

要:

let musicPlayerController: MPMusicPlayerController = MPMusicPlayerController.systemMusicPlayer

musicPlayerController明确注释为MPMusicPlayerController。)

在我看来,这是与SE-0156 Class and Subtype existentials相关的Swift错误,您最好向Appleswift.org发送错误报告。