Skip to content

Commit

Permalink
feat: refactor the commonplayerViewController and remove subclassing …
Browse files Browse the repository at this point in the history
…AVPlayerViewController (#109)

* tmp: add NewCommonPlayerViewController

* feat: add plugins

* feat: support pip

* feat: add playlist and speed changer plugin

* feat: live use new player

* remove old commonPlayer

* 添加港澳台解锁支持

* misc: rename NewCommonPlayerViewController.swift

* 修复投屏
  • Loading branch information
yichengchen authored Jun 11, 2024
1 parent be8dce4 commit 5875f08
Show file tree
Hide file tree
Showing 33 changed files with 1,647 additions and 849 deletions.
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

0 comments on commit 5875f08

Please sign in to comment.