From f1f6359a61d66e18422d11cedb786dcdc9fa60da Mon Sep 17 00:00:00 2001 From: hydewww Date: Sun, 16 Jul 2023 03:38:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E5=BC=B9=E5=B9=95?= =?UTF-8?q?=E5=B1=8F=E8=94=BD=E7=AD=89=E7=BA=A7&=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E6=97=B6=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Player/CommonPlayerViewController.swift | 15 ++++++++++++--- BilibiliLive/Component/Settings.swift | 6 ++++++ .../Component/Video/VideoDanmuProvider.swift | 3 +++ .../Vendor/DanmakuKit/DanmakuTextCellModel.swift | 2 +- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/BilibiliLive/Component/Player/CommonPlayerViewController.swift b/BilibiliLive/Component/Player/CommonPlayerViewController.swift index c4a6195c..8a99a75d 100644 --- a/BilibiliLive/Component/Player/CommonPlayerViewController.swift +++ b/BilibiliLive/Component/Player/CommonPlayerViewController.swift @@ -169,6 +169,15 @@ class CommonPlayerViewController: AVPlayerViewController { } menus.append(danmuAction) + let danmuDurationMenu = UIMenu(title: "弹幕展示时长", options: [.displayInline, .singleSelection], children: [4, 6, 8].map { dur in + UIAction(title: "\(dur) 秒", state: dur == Settings.danmuDuration ? .on : .off) { _ in Settings.danmuDuration = dur } + }) + let danmuAILevelMenu = UIMenu(title: "弹幕屏蔽等级", options: [.displayInline, .singleSelection], children: [Int32](1 ... 10).map { level in + UIAction(title: "\(level)", state: level == Settings.danmuAILevel ? .on : .off) { _ in Settings.danmuAILevel = level } + }) + let danmuSettingMenu = UIMenu(title: "弹幕设置", image: UIImage(systemName: "keyboard.badge.ellipsis"), children: [danmuDurationMenu, danmuAILevelMenu]) + menus.append(danmuSettingMenu) + let debugEnableImage = UIImage(systemName: "terminal.fill") let debugDisableImage = UIImage(systemName: "terminal") let debugAction = UIAction(title: "Debug", image: debugEnable ? debugEnableImage : debugDisableImage) { @@ -203,7 +212,7 @@ class CommonPlayerViewController: AVPlayerViewController { PlaySpeed(name: "2X", value: 2)] let speedActions = playSpeedArray.map { playSpeed in - UIAction(title: playSpeed.name, state: player?.rate ?? 1 == playSpeed.value ? .on : .off) { [weak self] action in + UIAction(title: playSpeed.name, state: player?.rate ?? 1 == playSpeed.value ? .on : .off) { [weak self] _ in self?.player?.currentItem?.audioTimePitchAlgorithm = .timeDomain if #available(tvOS 16.0, *) { self?.selectSpeed(AVPlaybackSpeed(rate: playSpeed.value, localizedName: playSpeed.name)) @@ -286,7 +295,7 @@ class CommonPlayerViewController: AVPlayerViewController { private func fetchDebugInfo() -> String { let bitrateStr: (Double) -> String = { bit in - return String(format: "%.2fMbps", bit / 1024.0 / 1024.0) + String(format: "%.2fMbps", bit / 1024.0 / 1024.0) } guard let log = player?.currentItem?.accessLog() else { return "no log" } @@ -375,7 +384,7 @@ extension CommonPlayerViewController: AVPlayerViewControllerDelegate { return false } - @objc func playerViewControllerShouldAutomaticallyDismissAtPictureInPictureStart(_ playerViewController: AVPlayerViewController) -> Bool { + @objc func playerViewControllerShouldAutomaticallyDismissAtPictureInPictureStart(_: AVPlayerViewController) -> Bool { return true } diff --git a/BilibiliLive/Component/Settings.swift b/BilibiliLive/Component/Settings.swift index edc3c92f..248b0b12 100644 --- a/BilibiliLive/Component/Settings.swift +++ b/BilibiliLive/Component/Settings.swift @@ -33,6 +33,12 @@ enum Settings { @UserDefaultCodable("Settings.danmuSize", defaultValue: .size_36) static var danmuSize: DanmuSize + @UserDefaultCodable("Settings.danmuAILevel", defaultValue: 1) + static var danmuAILevel: Int32 + + @UserDefaultCodable("Settings.danmuDuration", defaultValue: 8) + static var danmuDuration: Double + @UserDefault("Settings.losslessAudio", defaultValue: false) static var losslessAudio: Bool diff --git a/BilibiliLive/Component/Video/VideoDanmuProvider.swift b/BilibiliLive/Component/Video/VideoDanmuProvider.swift index 097cd40f..1ef4b9e3 100644 --- a/BilibiliLive/Component/Video/VideoDanmuProvider.swift +++ b/BilibiliLive/Component/Video/VideoDanmuProvider.swift @@ -17,6 +17,7 @@ struct Danmu: Codable { var fontSize: Int32 = 25 var color: UInt32 = 16_777_215 var isUp: Bool = false + var aiLevel: Int32 = 0 init(dm: DanmakuElem) { text = dm.content @@ -24,6 +25,7 @@ struct Danmu: Codable { mode = dm.mode fontSize = dm.fontsize color = dm.color + aiLevel = dm.weight } init(upDm dm: CommandDm) { @@ -165,6 +167,7 @@ class VideoDanmuProvider { let dm = dms[danmuIdx] guard dm.time < time else { break } danmuIdx += 1 + if dm.aiLevel < Settings.danmuAILevel { continue } onShowDanmu?(DanmakuTextCellModel(dm: dm)) } } diff --git a/BilibiliLive/Vendor/DanmakuKit/DanmakuTextCellModel.swift b/BilibiliLive/Vendor/DanmakuKit/DanmakuTextCellModel.swift index 2f4e81b7..70a8fd33 100644 --- a/BilibiliLive/Vendor/DanmakuKit/DanmakuTextCellModel.swift +++ b/BilibiliLive/Vendor/DanmakuKit/DanmakuTextCellModel.swift @@ -25,7 +25,7 @@ class DanmakuTextCellModel: DanmakuCellModel, Equatable { var track: UInt? - var displayTime: Double = 8 + var displayTime: Double = Settings.danmuDuration var type: DanmakuCellType = .floating