Skip to content

Commit

Permalink
fix: 修正直播弹幕开关不显示
Browse files Browse the repository at this point in the history
  • Loading branch information
yichengchen committed Nov 2, 2024
1 parent b420caa commit 1acddc7
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions BilibiliLive/Component/Player/CommonPlayerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ class CommonPlayerViewController: UIViewController {
}

func addPlugin(plugin: CommonPlayerPlugin) {
if activePlugins.contains(where: { $0 == plugin }) {
return
}
plugin.addViewToPlayerOverlay(container: playerVC.contentOverlayView!)
activePlugins.append(plugin)
plugin.playerDidLoad(playerVC: playerVC)
if let player = playerVC.player, playerVC.transportBarCustomMenuItems.isEmpty == false {
updateMenus()
}
}

func removePlugin(plugin: CommonPlayerPlugin) {
Expand All @@ -65,6 +71,15 @@ class CommonPlayerViewController: UIViewController {
alertController.addAction(actionOk)
present(alertController, animated: true, completion: nil)
}

func updateMenus() {
var menus = [UIMenuElement]()
activePlugins.forEach {
let newMenus = $0.addMenuItems(current: &menus)
menus.append(contentsOf: newMenus)
}
playerVC.transportBarCustomMenuItems = menus
}
}

extension CommonPlayerViewController {
Expand All @@ -80,12 +95,7 @@ extension CommonPlayerViewController {
if let playItem = player.currentItem {
observePlayerItem(playItem)
}
var menus = [UIMenuElement]()
activePlugins.forEach {
let newMenus = $0.addMenuItems(current: &menus)
menus.append(contentsOf: newMenus)
}
playerVC.transportBarCustomMenuItems = menus
updateMenus()
} else {
rateObserver = nil
}
Expand Down

0 comments on commit 1acddc7

Please sign in to comment.