我正在尝试通过AVPlayer向Airplay播放AAC-64流,但是未显示曲目的图片和名称。我该怎么办?
播放器代码如下。我将数据放在MPNowPlayingInfoCenter中,但没有任何变化。
class Player {
let radio = AVPlayer()
var currentStation:RadioStation?
func playStation(station : RadioStation) {
self.currentStation = station
stop()
let playerItem = AVPlayerItem(url: URL.init(string: station.stationStreamURL)!)
radio.replaceCurrentItem(with: playerItem)
radio.play()
updateLockScreen()
}
func play() {
let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setActive(true)
try audioSession.setCategory(AVAudioSessionCategoryPlayback)
} catch {}
self.radio.play()
}
func stop() {
self.radio.pause()
}
func updateLockScreen() {
if let track = currentStation?.getCurrentTrack() {
Alamofire.request(track.artworkURL, method: .get)
.responseImage{ response in
debugPrint(response)
var info : [String: AnyObject] = [MPMediaItemPropertyArtist: track.artist as AnyObject,
MPMediaItemPropertyTitle: track.title as AnyObject]
if let image = response.result.value {
print("image downloaded: \(image)")
info[MPMediaItemPropertyArtwork] = MPMediaItemArtwork(image: image)
}
MPNowPlayingInfoCenter.default().nowPlayingInfo = info
}
}
}
}