gpt4 book ai didi

mpmediapickercontroller - 如何获取 MPMediaPlaylist 的用户定义封面图片和描述?

转载 作者:行者123 更新时间:2023-12-04 08:43:35 27 4
gpt4 key购买 nike

我知道如何通过以下方式获得 MPMediaQuery 的标题:

MPMediaQuery *playlistsQuery = [MPMediaQuery playlistsQuery];

NSArray *items = [playlistsQuery collections];

MPMediaPlaylist *myPlaylist = items.firstObject;

NSLog(@"%@",myPlaylist.name); //"New playlist title"

有谁知道如何访问 MPMediaPlaylist 的封面和描述?

Screenshot - User created Playlist

最佳答案

获取描述很容易,只需使用

var descriptionText: String? { get }

来自 MPMediaPlaylist
要获取用户定义的图像,您必须使用私有(private) API,这是一个扩展,您可以使用它来获取存储在磁盘上的图像,或获取图像的 URL :
extension MPMediaPlaylist {
/**
User selected image for playlist stored on disk.
*/
var userImage: UIImage? {
guard let catalog = value(forKey: "artworkCatalog") as? NSObject else {
return nil
}

let sel = NSSelectorFromString("bestImageFromDisk")

guard catalog.responds(to: sel),
let value = catalog.perform(sel)?.takeUnretainedValue(),
let image = value as? UIImage else {
return nil
}
return image
}

/**
URL for playlist's image.
*/
var imageUrl: URL? {
if let catalog = value(forKey: "artworkCatalog") as? NSObject,
let token = catalog.value(forKey: "token") as? NSObject,
let url = token.value(forKey: "availableArtworkToken") as? String {
return URL(string: "https://is2-ssl.mzstatic.com/image/thumb/\(url)/260x260cc.jpg")
}
return nil
}
}

与往常一样,请记住,当 Apple 在后台更改内容或您的应用程序可能被 App Store 拒绝时,它可能随时停止工作。

关于mpmediapickercontroller - 如何获取 MPMediaPlaylist 的用户定义封面图片和描述?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34132956/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com