Reputation: 5558
Summary
I am currently trying to set an app-wide default metadata for every time it plays audio. Currently, only the URL of the audio streaming is shown on the Control Centre and the Lockscreen. I am trying to my own custom values; however, I can't get it to work. It may be worth noting that the audio is playing through a UIWebView
.
(Continued below screenshot)
ViewController.swift
import UIKit
import AVFoundation
import MediaPlayer
class ViewController: UIViewController, UIWebViewDelegate, UIScrollViewDelegate {
var mPlayer: MPMediaItem!
override func viewDidLoad() {
super.viewDidLoad()
let image = UIImage(named: "Artwork")!
let artwork = MPMediaItemArtwork.init(boundsSize: image.size, requestHandler: { (size) -> UIImage in
return image
})
let nowPlaying: NSDictionary = [MPMediaItemPropertyTitle: "Song",
MPMediaItemPropertyArtist: "Artist",
MPMediaItemPropertyArtwork: artwork]
MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlaying as? [String : Any]
}
}
Upvotes: 0
Views: 624
Reputation: 9392
You have to initialize the MPMediaItemArtwork with its initializer
let image = UIImage(named: "Artwork")!
let artwork = MPMediaItemArtwork.init(boundsSize: image.size, requestHandler: { (size) -> UIImage in
return image
})
Upvotes: 2