mirror of
https://github.com/dirtydishes/dreamio.git
synced 2026-06-06 21:38:15 +00:00
fix native playback build blockers
This commit is contained in:
parent
d28540ce98
commit
b15e4d640e
5 changed files with 48 additions and 2 deletions
|
|
@ -54,7 +54,7 @@ final class DreamioWebViewController: UIViewController {
|
|||
private var lastNativePlaybackURL: URL?
|
||||
|
||||
private static let streamCandidateScript = WKUserScript(
|
||||
source: """
|
||||
source: #"""
|
||||
(() => {
|
||||
if (window.__dreamioStreamBridgeInstalled) {
|
||||
return;
|
||||
|
|
@ -181,7 +181,7 @@ final class DreamioWebViewController: UIViewController {
|
|||
|
||||
inspectMedia(document);
|
||||
})();
|
||||
""",
|
||||
"""#,
|
||||
injectionTime: .atDocumentStart,
|
||||
forMainFrameOnly: false
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,24 +1,34 @@
|
|||
import UIKit
|
||||
|
||||
#if canImport(MobileVLCKit)
|
||||
import MobileVLCKit
|
||||
#endif
|
||||
|
||||
final class VLCNativePlaybackBackend: NSObject, NativePlaybackBackend {
|
||||
let view = UIView()
|
||||
var onReady: (() -> Void)?
|
||||
var onFailure: ((Error) -> Void)?
|
||||
|
||||
#if canImport(MobileVLCKit)
|
||||
private let mediaPlayer = VLCMediaPlayer()
|
||||
#endif
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
#if canImport(MobileVLCKit)
|
||||
mediaPlayer.delegate = self
|
||||
#endif
|
||||
view.backgroundColor = .black
|
||||
}
|
||||
|
||||
func prepare(in viewController: UIViewController) {
|
||||
#if canImport(MobileVLCKit)
|
||||
mediaPlayer.drawable = view
|
||||
#endif
|
||||
}
|
||||
|
||||
func play(request: NativePlaybackRequest) {
|
||||
#if canImport(MobileVLCKit)
|
||||
let media = VLCMedia(url: request.playbackURL)
|
||||
var headers = ["Referer": request.referer]
|
||||
if let userAgent = request.userAgent {
|
||||
|
|
@ -36,14 +46,20 @@ final class VLCNativePlaybackBackend: NSObject, NativePlaybackBackend {
|
|||
|
||||
mediaPlayer.media = media
|
||||
mediaPlayer.play()
|
||||
#else
|
||||
onFailure?(NativePlaybackError.backendUnavailable)
|
||||
#endif
|
||||
}
|
||||
|
||||
func stop() {
|
||||
#if canImport(MobileVLCKit)
|
||||
mediaPlayer.stop()
|
||||
mediaPlayer.media = nil
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if canImport(MobileVLCKit)
|
||||
extension VLCNativePlaybackBackend: VLCMediaPlayerDelegate {
|
||||
func mediaPlayerStateChanged(_ aNotification: Notification) {
|
||||
switch mediaPlayer.state {
|
||||
|
|
@ -56,3 +72,4 @@ extension VLCNativePlaybackBackend: VLCMediaPlayerDelegate {
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue