Last active
June 27, 2021 14:00
-
-
Save ChrisMash/06bc5309583e8f0e3628e12f62f8361d to your computer and use it in GitHub Desktop.
iOS 14's new VideoPlayer View is here!
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 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() | |
| } | |
| } | |
| } |
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
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! ;)