摘要
我目前正在尝试为每次播放音频时设置应用范围的默认元数据。目前,只有音频流的URL显示在控制中心和锁屏上。我正在尝试自己的自定义值;但是,我无法让它发挥作用。值得注意的是,音频正在播放UIWebView
。
(续下面的截图)
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]
}
}
答案 0 :(得分:2)
您必须使用其初始化程序
初始化MPMediaItemArtworklet image = UIImage(named: "Artwork")!
let artwork = MPMediaItemArtwork.init(boundsSize: image.size, requestHandler: { (size) -> UIImage in
return image
})