Skip to content

Commit

Permalink
feat: #88 add AVContentProposalViewController to VideoPlayerViewContr…
Browse files Browse the repository at this point in the history
…oller
  • Loading branch information
yichengchen committed Nov 20, 2023
1 parent 92d4f9b commit e73441d
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 79 deletions.
4 changes: 4 additions & 0 deletions BilibiliLive.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
49389D6228AFEA2900B9DAFD /* VideoDanmuProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49389D6128AFEA2900B9DAFD /* VideoDanmuProvider.swift */; };
49389D8928B0A1B700B9DAFD /* UIViewController+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49389D8828B0A1B700B9DAFD /* UIViewController+Ext.swift */; };
49389D8C28B0A84500B9DAFD /* PersonalViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49389D8B28B0A84500B9DAFD /* PersonalViewController.swift */; };
49425E812B0B410400D8AEBF /* BLContentProposalViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49425E802B0B410400D8AEBF /* BLContentProposalViewController.swift */; };
494741C029002797005D6885 /* UserDefault+..swift in Sources */ = {isa = PBXBuildFile; fileRef = 494741BF29002797005D6885 /* UserDefault+..swift */; };
494741C329016CCE005D6885 /* MarqueeLabel in Frameworks */ = {isa = PBXBuildFile; productRef = 494741C229016CCE005D6885 /* MarqueeLabel */; };
494741C6290177BB005D6885 /* UpSpaceViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494741C5290177BB005D6885 /* UpSpaceViewController.swift */; };
Expand Down Expand Up @@ -116,6 +117,7 @@
49389D6128AFEA2900B9DAFD /* VideoDanmuProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoDanmuProvider.swift; sourceTree = "<group>"; };
49389D8828B0A1B700B9DAFD /* UIViewController+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+Ext.swift"; sourceTree = "<group>"; };
49389D8B28B0A84500B9DAFD /* PersonalViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersonalViewController.swift; sourceTree = "<group>"; };
49425E802B0B410400D8AEBF /* BLContentProposalViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BLContentProposalViewController.swift; sourceTree = "<group>"; };
494741BF29002797005D6885 /* UserDefault+..swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UserDefault+..swift"; sourceTree = "<group>"; };
494741C5290177BB005D6885 /* UpSpaceViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpSpaceViewController.swift; sourceTree = "<group>"; };
494741C72902C45D005D6885 /* Array+..swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Array+..swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -382,6 +384,7 @@
children = (
49E5F84F28AF73C500FAA3CE /* BilibiliVideoResourceLoaderDelegate.swift */,
F99D28E02619591300F8E66A /* CommonPlayerViewController.swift */,
49425E802B0B410400D8AEBF /* BLContentProposalViewController.swift */,
49FB8EE829208EBE0045D5DE /* SidxParseUtil.swift */,
);
path = Player;
Expand Down Expand Up @@ -607,6 +610,7 @@
F9D382B426359EF90070508F /* ApiRequest.swift in Sources */,
490EC3E9290CE23E001E00B6 /* BLSettingLineCollectionViewCell.swift in Sources */,
F9B57354260F5F7400771ED5 /* AppDelegate.swift in Sources */,
49425E812B0B410400D8AEBF /* BLContentProposalViewController.swift in Sources */,
F9EDADD3262AA421007CB99F /* VideoDetailViewController.swift in Sources */,
496400D32943431E0098ACA6 /* Logger.swift in Sources */,
F927ED8826103CFB00EAB8E3 /* DanmakuTextCell.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// BLContentProposalViewController.swift
// BilibiliLive
//
// Created by yicheng on 2023/11/20.
//

import AVKit
import UIKit

class BLContentProposalViewController: AVContentProposalViewController {
let nextButton = BLCustomTextButton()

override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(nextButton)
view.backgroundColor = UIColor.clear
nextButton.addTarget(self, action: #selector(actionAccept), for: .primaryActionTriggered)
nextButton.title = "下一个:" + (contentProposal?.title ?? "")
nextButton.titleFont = UIFont.systemFont(ofSize: 30)
nextButton.snp.makeConstraints { make in
make.right.equalToSuperview().offset(-50)
make.height.equalTo(60)
make.width.greaterThanOrEqualTo(200)
make.width.lessThanOrEqualTo(500)
make.bottom.equalToSuperview().multipliedBy(0.75)
}
}

@objc func actionAccept() {
dismissContentProposal(for: .accept, animated: true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class CommonPlayerViewController: AVPlayerViewController {
return ""
}

func loopDidChange() {}

func playerStatusDidChange() {
Logger.debug("player status: \(player?.currentItem?.status.rawValue ?? -1)")
switch player?.currentItem?.status {
Expand Down Expand Up @@ -156,6 +158,7 @@ class CommonPlayerViewController: AVPlayerViewController {
return item.copy() as? AVMetadataItem
}

// TODO: this should move out of common
private func setupPlayerMenu() {
var menus = [UIMenuElement]()
let danmuImage = UIImage(systemName: "list.bullet.rectangle.fill")
Expand Down Expand Up @@ -199,9 +202,10 @@ class CommonPlayerViewController: AVPlayerViewController {

// Create an action to enable looping playback.
let loopAction = UIAction(title: "循环播放", image: loopImage, state: Settings.loopPlay ? .on : .off) {
action in
[weak self] action in
action.state = (action.state == .off) ? .on : .off
Settings.loopPlay = action.state == .on
self?.loopDidChange()
}

let speedActions = PlaySpeed.blDefaults.map { playSpeed in
Expand Down
40 changes: 31 additions & 9 deletions BilibiliLive/Component/Video/VideoDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,8 @@ class VideoDetailViewController: UIViewController {
@IBAction func actionPlay(_ sender: Any) {
let player = VideoPlayerViewController(playInfo: PlayInfo(aid: aid, cid: cid, epid: epid, isBangumi: isBangumi))
player.data = data
if pages.count > 0, let index = pages.firstIndex(where: { $0.cid == cid }) {
let seq = pages.dropFirst(index).map({ PlayInfo(aid: aid, cid: $0.cid, epid: $0.epid, isBangumi: isBangumi) })
if seq.count > 0 {
let nextProvider = VideoNextProvider(seq: seq)
player.nextProvider = nextProvider
}
}
player.nextProvider = getContinouslyPlayProvider()

present(player, animated: true, completion: nil)
}

Expand Down Expand Up @@ -432,6 +427,32 @@ class VideoDetailViewController: UIViewController {
}
}

extension VideoDetailViewController {
func getContinouslyPlayProvider() -> VideoNextProvider? {
// 有分P,分P联播
if pages.count > 1, let index = pages.firstIndex(where: { $0.cid == cid }) {
let seq = pages.map({ PlayInfo(aid: aid, cid: $0.cid, epid: $0.epid, isBangumi: isBangumi, title: $0.part) })
let nextProvider = VideoNextProvider(seq: seq, startIndex: index)
return nextProvider
}

// 合集
if allUgcEpisodes.count > 0 {
let index = allUgcEpisodes.firstIndex { $0.cid == cid } ?? 0
let seq = allUgcEpisodes.map({ PlayInfo(aid: aid, cid: $0.cid, epid: 0, isBangumi: isBangumi, title: $0.title) })
return VideoNextProvider(seq: seq, startIndex: index)
}

// 推荐
if let recommand = data?.Related, recommand.count > 0 {
let seq = recommand.map({ PlayInfo(aid: $0.aid, cid: $0.cid, epid: 0, isBangumi: false, title: $0.title) })
return VideoNextProvider(seq: seq, startIndex: -1)
}

return nil
}
}

extension VideoDetailViewController: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
switch collectionView {
Expand All @@ -440,9 +461,10 @@ extension VideoDetailViewController: UICollectionViewDelegate {
let player = VideoPlayerViewController(playInfo: PlayInfo(aid: isBangumi ? page.page : aid, cid: page.cid, epid: page.epid, isBangumi: isBangumi))
player.data = isBangumi ? nil : data

let seq = pages.dropFirst(indexPath.item).map({ PlayInfo(aid: aid, cid: $0.cid, isBangumi: isBangumi) })
let seq = pages.map({ PlayInfo(aid: aid, cid: $0.cid, isBangumi: isBangumi, title: $0.part) })
// 分p选择,分p联播
if seq.count > 0 {
let nextProvider = VideoNextProvider(seq: seq)
let nextProvider = VideoNextProvider(seq: seq, startIndex: indexPath.item)
player.nextProvider = nextProvider
}
present(player, animated: true, completion: nil)
Expand Down
Loading

0 comments on commit e73441d

Please sign in to comment.