polish iOS study flow
This commit is contained in:
@@ -1,7 +1,37 @@
|
||||
import AVFoundation
|
||||
import Combine
|
||||
import Foundation
|
||||
|
||||
@MainActor
|
||||
final class PlayerCoordinator: ObservableObject {
|
||||
let player: AVPlayer
|
||||
|
||||
@Published var isPlaying = false
|
||||
@Published var playbackPositionMs: Int = 0
|
||||
|
||||
init(previewURL: URL = URL(string: "https://cdn.example.com/hermes/sample-event/master.m3u8")!) {
|
||||
self.player = AVPlayer(url: previewURL)
|
||||
self.player.actionAtItemEnd = .pause
|
||||
}
|
||||
|
||||
func prepareForPreview() {
|
||||
player.seek(to: .zero)
|
||||
player.play()
|
||||
isPlaying = true
|
||||
}
|
||||
|
||||
func play() {
|
||||
player.play()
|
||||
isPlaying = true
|
||||
}
|
||||
|
||||
func pause() {
|
||||
player.pause()
|
||||
isPlaying = false
|
||||
}
|
||||
|
||||
func restart() {
|
||||
player.seek(to: .zero)
|
||||
play()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import AVKit
|
||||
import SwiftUI
|
||||
|
||||
struct StudyVideoPlayerView: View {
|
||||
@ObservedObject var coordinator: PlayerCoordinator
|
||||
|
||||
var body: some View {
|
||||
VideoPlayer(player: coordinator.player)
|
||||
.frame(maxWidth: .infinity)
|
||||
.frame(height: 224)
|
||||
.clipShape(RoundedRectangle(cornerRadius: HermesTheme.cornerRadius, style: .continuous))
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: HermesTheme.cornerRadius, style: .continuous)
|
||||
.stroke(HermesTheme.accent.opacity(0.12), lineWidth: 1)
|
||||
)
|
||||
.background(HermesTheme.surfaceElevated)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user