我在设置 MPNowPlayingInfoCenter 的 currentTime 和 songLength 时遇到问题。这是我的代码:
func updateNowPlayingCenter (title: String, artist: String, albumArt: AnyObject, currentTime: NSNumber, songLength: NSNumber, PlaybackRate: Double){
var songInfo: Dictionary <NSObject, AnyObject> = [
MPMediaItemPropertyTitle as NSObject: title as AnyObject,
MPMediaItemPropertyArtist as NSObject: artist as AnyObject,
MPMediaItemPropertyArtwork as NSObject: ???,
MPNowPlayingInfoPropertyElapsedPlaybackTime as NSObject: currentTime,
MPMediaItemPropertyPlaybackDuration as NSObject: songLength,
MPNowPlayingInfoPropertyPlaybackRate as NSObject: PlaybackRate as AnyObject
]
MPNowPlayingInfoCenter.default().nowPlayingInfo = songInfo as [NSObject : AnyObject] as! [String : Any]
}
这里是我在 viewWillAppear 中设置属性的地方:
updateNowPlayingCenter(title: titleText[thisSong], artist: authorText[thisSong], albumArt: ??? as AnyObject, currentTime: ???, songLength: ???, PlaybackRate: 1.0)
我尝试使用 audioPlayer.currentTime 和 audioPlayer.duration,但它不起作用。我该怎么做呢?另外,我不知道如何设置 MPMediaItemPropertyArtwork 的图像。我的资产中有文件,图像名称等于 titleText[thisSong]。如果你也能帮助我,那就太棒了!谢谢!