Fix youtube video controls visibility toggling

This commit is contained in:
Ilya Laktyushin 2020-10-28 06:35:35 +04:00
parent 0e9412fbc9
commit 32b7ac2a27
7 changed files with 37 additions and 0 deletions

View File

@ -29,6 +29,7 @@ public protocol UniversalVideoContentNode: class {
func addPlaybackCompleted(_ f: @escaping () -> Void) -> Int func addPlaybackCompleted(_ f: @escaping () -> Void) -> Int
func removePlaybackCompleted(_ index: Int) func removePlaybackCompleted(_ index: Int)
func fetchControl(_ control: UniversalVideoNodeFetchControl) func fetchControl(_ control: UniversalVideoNodeFetchControl)
func notifyPlaybackControlsHidden(_ hidden: Bool)
} }
public protocol UniversalVideoContent { public protocol UniversalVideoContent {
@ -319,6 +320,14 @@ public final class UniversalVideoNode: ASDisplayNode {
}) })
} }
public func notifyPlaybackControlsHidden(_ hidden: Bool) {
self.manager.withUniversalVideoContent(id: self.content.id, { contentNode in
if let contentNode = contentNode {
contentNode.notifyPlaybackControlsHidden(hidden)
}
})
}
@objc private func tapGesture(_ recognizer: UITapGestureRecognizer) { @objc private func tapGesture(_ recognizer: UITapGestureRecognizer) {
if case .ended = recognizer.state { if case .ended = recognizer.state {
self.decoration.tap() self.decoration.tap()

View File

@ -265,6 +265,7 @@ final class UniversalVideoGalleryItemNode: ZoomableContentGalleryItemNode {
private let overlayContentNode: UniversalVideoGalleryItemOverlayNode private let overlayContentNode: UniversalVideoGalleryItemOverlayNode
private var videoNode: UniversalVideoNode? private var videoNode: UniversalVideoNode?
private var videoNodeUserInteractionEnabled: Bool = false
private var videoFramePreview: FramePreview? private var videoFramePreview: FramePreview?
private var pictureInPictureNode: UniversalVideoGalleryItemPictureInPictureNode? private var pictureInPictureNode: UniversalVideoGalleryItemPictureInPictureNode?
private let statusButtonNode: HighlightableButtonNode private let statusButtonNode: HighlightableButtonNode
@ -555,6 +556,7 @@ final class UniversalVideoGalleryItemNode: ZoomableContentGalleryItemNode {
} }
} }
self.videoNode = videoNode self.videoNode = videoNode
self.videoNodeUserInteractionEnabled = disablePlayerControls || forceEnableUserInteraction
videoNode.isUserInteractionEnabled = disablePlayerControls || forceEnableUserInteraction videoNode.isUserInteractionEnabled = disablePlayerControls || forceEnableUserInteraction
videoNode.backgroundColor = videoNode.ownsContentNode ? UIColor.black : UIColor(rgb: 0x333335) videoNode.backgroundColor = videoNode.ownsContentNode ? UIColor.black : UIColor(rgb: 0x333335)
if item.fromPlayingVideo { if item.fromPlayingVideo {
@ -680,6 +682,10 @@ final class UniversalVideoGalleryItemNode: ZoomableContentGalleryItemNode {
if !content.enableSound { if !content.enableSound {
isPaused = false isPaused = false
} }
} else {
strongSelf.updateControlsVisibility(true)
strongSelf.controlsTimer?.invalidate()
strongSelf.controlsTimer = nil
} }
} }
seekable = value.duration >= 30.0 seekable = value.duration >= 30.0
@ -795,6 +801,9 @@ final class UniversalVideoGalleryItemNode: ZoomableContentGalleryItemNode {
override func controlsVisibilityUpdated(isVisible: Bool) { override func controlsVisibilityUpdated(isVisible: Bool) {
self.controlsTimer?.invalidate() self.controlsTimer?.invalidate()
self.controlsTimer = nil self.controlsTimer = nil
self.videoNode?.isUserInteractionEnabled = isVisible ? self.videoNodeUserInteractionEnabled : false
self.videoNode?.notifyPlaybackControlsHidden(!isVisible)
} }
private func updateDisplayPlaceholder(_ displayPlaceholder: Bool) { private func updateDisplayPlaceholder(_ displayPlaceholder: Bool) {

View File

@ -451,4 +451,7 @@ private final class NativeVideoContentNode: ASDisplayNode, UniversalVideoContent
self.postbox.mediaBox.cancelInteractiveResourceFetch(self.fileReference.media.resource) self.postbox.mediaBox.cancelInteractiveResourceFetch(self.fileReference.media.resource)
} }
} }
func notifyPlaybackControlsHidden(_ hidden: Bool) {
}
} }

View File

@ -448,4 +448,7 @@ private final class PlatformVideoContentNode: ASDisplayNode, UniversalVideoConte
func fetchControl(_ control: UniversalVideoNodeFetchControl) { func fetchControl(_ control: UniversalVideoNodeFetchControl) {
} }
func notifyPlaybackControlsHidden(_ hidden: Bool) {
}
} }

View File

@ -287,5 +287,8 @@ private final class SystemVideoContentNode: ASDisplayNode, UniversalVideoContent
func fetchControl(_ control: UniversalVideoNodeFetchControl) { func fetchControl(_ control: UniversalVideoNodeFetchControl) {
} }
func notifyPlaybackControlsHidden(_ hidden: Bool) {
}
} }

View File

@ -211,4 +211,10 @@ final class WebEmbedPlayerNode: ASDisplayNode, WKNavigationDelegate {
} }
} }
} }
func notifyPlaybackControlsHidden(_ hidden: Bool) {
if impl is YoutubeEmbedImplementation {
self.webView.isUserInteractionEnabled = !hidden
}
}
} }

View File

@ -184,4 +184,8 @@ final class WebEmbedVideoContentNode: ASDisplayNode, UniversalVideoContentNode {
func fetchControl(_ control: UniversalVideoNodeFetchControl) { func fetchControl(_ control: UniversalVideoNodeFetchControl) {
} }
func notifyPlaybackControlsHidden(_ hidden: Bool) {
self.playerNode.notifyPlaybackControlsHidden(hidden)
}
} }