mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
Add YouTube scrubbing thumbnails
This commit is contained in:
@@ -8,7 +8,7 @@ import SyncCore
|
||||
import UniversalMediaPlayer
|
||||
|
||||
protocol WebEmbedImplementation {
|
||||
func setup(_ webView: WKWebView, userContentController: WKUserContentController, evaluateJavaScript: @escaping (String) -> Void, updateStatus: @escaping (MediaPlayerStatus) -> Void, onPlaybackStarted: @escaping () -> Void)
|
||||
func setup(_ webView: WKWebView, userContentController: WKUserContentController, evaluateJavaScript: @escaping (String, ((Any?) -> Void)?) -> Void, updateStatus: @escaping (MediaPlayerStatus) -> Void, onPlaybackStarted: @escaping () -> Void)
|
||||
|
||||
func play()
|
||||
func pause()
|
||||
@@ -73,7 +73,7 @@ final class WebEmbedPlayerNode: ASDisplayNode, WKNavigationDelegate {
|
||||
return self.readyValue.get()
|
||||
}
|
||||
|
||||
private let impl: WebEmbedImplementation
|
||||
let impl: WebEmbedImplementation
|
||||
|
||||
private let intrinsicDimensions: CGSize
|
||||
private let webView: WKWebView
|
||||
@@ -118,8 +118,8 @@ final class WebEmbedPlayerNode: ASDisplayNode, WKNavigationDelegate {
|
||||
}
|
||||
self.view.addSubview(self.webView)
|
||||
|
||||
self.impl.setup(self.webView, userContentController: userContentController, evaluateJavaScript: { [weak self] js in
|
||||
self?.evaluateJavaScript(js: js)
|
||||
self.impl.setup(self.webView, userContentController: userContentController, evaluateJavaScript: { [weak self] js, completion in
|
||||
self?.evaluateJavaScript(js: js, completion: completion)
|
||||
}, updateStatus: { [weak self] status in
|
||||
self?.statusValue.set(status)
|
||||
}, onPlaybackStarted: { [weak self] in
|
||||
@@ -168,12 +168,15 @@ final class WebEmbedPlayerNode: ASDisplayNode, WKNavigationDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
private func evaluateJavaScript(js: String) {
|
||||
private func evaluateJavaScript(js: String, completion: ((Any?) -> Void)?) {
|
||||
self.queue.async { [weak self] in
|
||||
if let strongSelf = self {
|
||||
let impl = {
|
||||
strongSelf.webView.evaluateJavaScript(js, completionHandler: { (_, _) in
|
||||
strongSelf.webView.evaluateJavaScript(js, completionHandler: { (result, _) in
|
||||
strongSelf.semaphore.signal()
|
||||
if let completion = completion {
|
||||
completion(result)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user