Created
March 10, 2020 19:09
-
-
Save ChrisMash/57141446fc18771e541571f89a5cc1c5 to your computer and use it in GitHub Desktop.
A SwiftUI View to display an AVPlayer's currentTime from PlayerTimeObserver's publisher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import AVFoundation | |
struct PlayerTimeView: View { | |
let timeObserver: PlayerTimeObserver | |
@State private var currentTime: TimeInterval = 0 | |
var body: some View { | |
Text("\(Utility.formatSecondsToHMS(currentTime))") | |
.onReceive(timeObserver.publisher) { time in | |
self.currentTime = time | |
} | |
} | |
} | |
// Create elsewhere like so: | |
PlayerTimeView(timeObserver: PlayerTimeObserver(player: player)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hiya, how would I use this with a video. I'm quite new so sorry for the potentially straight forward question. If I wanted to stream a video from a URL ie. This one. I would also like to do something like: if current time is X (ie. 10 seconds) then pause video etc... Thanks in advance