Skip to content

Instantly share code, notes, and snippets.

@ChrisMash
Last active June 27, 2021 14:00
Show Gist options
  • Select an option

  • Save ChrisMash/06bc5309583e8f0e3628e12f62f8361d to your computer and use it in GitHub Desktop.

Select an option

Save ChrisMash/06bc5309583e8f0e3628e12f62f8361d to your computer and use it in GitHub Desktop.
iOS 14's new VideoPlayer View is here!
import SwiftUI
import AVKit
struct VideoView: View {
private let player = AVPlayer(url: URL(string: "https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8")!)
var body: some View {
VideoPlayer(player: player)
.onAppear() {
// Start the player going, otherwise controls don't appear
player.play()
}
.onDisappear() {
// Stop the player when the view disappears
player.pause()
}
}
}
@Aiyush-G

Copy link
Copy Markdown

How can I do something like, if the current time in video is X seconds (ie 5) then pause the video? Cheers, this would help lots! ;)

@ChrisMash

Copy link
Copy Markdown
Author

Hi, this gist (and the other one you commented on) are supporting material for my series of blogs on using AVPlayer in SwiftUI: https://link.medium.com/I0fFtbHOqhb

Hopefully reading those will answer your question, but feel free to ask any follow up questions if anything is unclear!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment