diff --git a/BilibiliLive/Component/Player/CommonPlayerViewController.swift b/BilibiliLive/Component/Player/CommonPlayerViewController.swift index f5654d8..4325ff9 100644 --- a/BilibiliLive/Component/Player/CommonPlayerViewController.swift +++ b/BilibiliLive/Component/Player/CommonPlayerViewController.swift @@ -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) { @@ -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 { @@ -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 }