-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPlayerView.swift
More file actions
48 lines (42 loc) · 1.28 KB
/
PlayerView.swift
File metadata and controls
48 lines (42 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// PlayerView.swift
//
//
// Created by Michael on 19/1/2023.
//
import SwiftUI
import AVKit
import os
public struct PlayerView: View {
private static let logger = Logger(
subsystem: Bundle.main.bundleIdentifier!,
category: String(describing: PlayerView.self)
)
@ObservedObject private var session: AdBeaconingSession
public init(session: AdBeaconingSession) {
self.session = session
}
public var body: some View {
VStack {
VideoPlayer(player: session.player, videoOverlay: {
if session.isShowDebugOverlay {
VideoOverlayView(playerObserver: session.playerObserver)
}
})
#if os(iOS)
.aspectRatio(CGSize(width: 16, height: 9), contentMode: .fit)
#else
.frame(height: 360)
#endif
.onReceive(session.$automaticallyPreservesTimeOffsetFromLive, perform: { enabled in
session.reload(with: session.sessionInfo.manifestUrl,
isAutomaticallyPreservesTimeOffsetFromLive: enabled)
})
}
}
}
struct PlayerView_Previews: PreviewProvider {
static var previews: some View {
PlayerView(session: createSampleSession() ?? AdBeaconingSession())
}
}