Skip to content

Commit

Permalink
fix: 修复弹幕mask延迟
Browse files Browse the repository at this point in the history
  • Loading branch information
yichengchen committed Jun 16, 2024
1 parent d2c9b38 commit 2a10772
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions BilibiliLive/Component/Player/Plugins/MaskViewPugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class MaskViewPugin: NSObject, CommonPlayerPlugin {
weak var maskView: UIView?
var maskProvider: MaskProvider
private var observer: Any?
private let queue = DispatchQueue(label: "plugin.mask")
private var videoOutput: AVPlayerItemVideoOutput?

init(maskView: UIView, maskProvider: MaskProvider) {
Expand All @@ -26,19 +25,12 @@ class MaskViewPugin: NSObject, CommonPlayerPlugin {
}

let timePerFrame = CMTime(value: 1, timescale: CMTimeScale(maskProvider.preferFPS()))

observer = player.addPeriodicTimeObserver(forInterval: timePerFrame, queue: queue) {
observer = player.addPeriodicTimeObserver(forInterval: timePerFrame, queue: .main) {
[weak self] time in
guard let self, let maskView, !maskView.isHidden else { return }
maskProvider.getMask(for: time, frame: maskView.frame) {
[weak maskView] maskLayer in
if Thread.isMainThread {
maskView?.layer.mask = maskLayer
} else {
DispatchQueue.main.async {
maskView?.layer.mask = maskLayer
}
}
maskView?.layer.mask = maskLayer
}
}
}
Expand Down

0 comments on commit 2a10772

Please # to comment.