Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: refactor the commonplayerViewController and remove subclassing AVPlayerViewController #109

Merged
merged 10 commits into from
Jun 11, 2024
108 changes: 98 additions & 10 deletions BilibiliLive.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "f89b743e598074e66556cd063dd1258c33483d783163efc65f648349cece8790",
"originHash" : "45c5c9267c8c84275fa647f629e1033e605b18efefc17e781b907af506eb5385",
"pins" : [
{
"identity" : "alamofire",
Expand Down
42 changes: 42 additions & 0 deletions BilibiliLive/Component/Player/AVPlayerMetaUtils.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// AVPlayerMetaUtils.swift
// BilibiliLive
//
// Created by yicheng on 2024/6/6.
//

import AVKit
import Kingfisher

enum AVPlayerMetaUtils {
static func setPlayerInfo(title: String?, subTitle: String?, desp: String?, pic: URL?, player: AVPlayer) async {
let desp = desp?.components(separatedBy: "\n").joined(separator: " ")
let mapping: [AVMetadataIdentifier: Any?] = [
.commonIdentifierTitle: title,
.iTunesMetadataTrackSubTitle: subTitle,
.commonIdentifierDescription: desp,
]
var metas = mapping.compactMap { createMetadataItem(for: $0, value: $1) }

player.currentItem?.externalMetadata = metas

if let pic = pic,
let resource = try? await KingfisherManager.shared.retrieveImage(with: Kingfisher.ImageResource(downloadURL: pic)),
let data = resource.image.pngData(),
let item = createMetadataItem(for: .commonIdentifierArtwork, value: data)
{
metas.append(item)
player.currentItem?.externalMetadata = metas
}
}

static func createMetadataItem(for identifier: AVMetadataIdentifier, value: Any?) -> AVMetadataItem? {
if value == nil { return nil }
let item = AVMutableMetadataItem()
item.identifier = identifier
item.value = value as? NSCopying & NSObjectProtocol
// Specify "und" to indicate an undefined language.
item.extendedLanguageTag = "und"
return item.copy() as? AVMetadataItem
}
}
Loading
Loading