Somehow I'm not getting one aspect of xCode working on a mediaplayer.
When timedMetadata is changed the func is executed. I works for audioInfo.nowPlayingInfo. But when I try to update a UILabel on the screen to set the title and artist an error occurs. Updating the UILabel after pressing a button (pushButton) works. Same code. Different results.
override func observeValue(forKeyPath: String?, of: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if forKeyPath != "timedMetadata" { return }
let data: AVPlayerItem = of as! AVPlayerItem
for item in data.timedMetadata! {
if item.commonKey!.rawValue == "title" {
if let title = item.stringValue, !title.isEmpty {
let splitArray = title.components(separatedBy: " - ")
artiest = splitArray[0]
titel = splitArray[1]
} else {
titel = "Delta Radio"
artiest = "Muziek zonder flauwekul!"
}
}
}
/
/
updateMetaData = true
audioInfo.nowPlayingInfo = [MPMediaItemPropertyTitle: titel, MPMediaItemPropertyArtist:artiest, MPMediaItemPropertyAssetURL: deltaRadioURL!];
updateTitleArtist()
}
@IBAction func pushButton(_ sender: Any) {
self.artiestLabel.text = titel + " / " + artiest
}
func updateTitleArtist() {
self.artiestLabel.text = titel + " / " + artiest
updateMetaData = false
}I searched and read about threads. Tried it, but it won't work. Read about programmacilly making a UILabel. Tried it, but it won't work.
Who can help me out? I think I do not grasp some basic concept of xCode?