问题
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