From 1acddc7b3e644511892b64dedad30e422f569476 Mon Sep 17 00:00:00 2001 From: yicheng <11733500+yichengchen@users.noreply.github.com> Date: Sat, 2 Nov 2024 10:43:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E7=9B=B4=E6=92=AD?= =?UTF-8?q?=E5=BC=B9=E5=B9=95=E5=BC=80=E5=85=B3=E4=B8=8D=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Player/CommonPlayerViewController.swift | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) 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 }