Created
April 3, 2024 16:09
-
-
Save bpmarkowitz/d5953120d28bca6e0de49cc800d6985b to your computer and use it in GitHub Desktop.
Simple Swift UI Video Player
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
// | |
// ContentView.swift | |
// | |
// Created by Ben Markowitz | |
// | |
import SwiftUI | |
import AVKit | |
struct ContentView: View { | |
private let player = AVPlayer(url: URL(string:"Your Video URL.m3u8")!) | |
var body: some View { | |
ZStack(alignment: .bottomTrailing) { | |
VideoPlayer(player: player) | |
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity) | |
.onAppear() { | |
player.play() | |
} | |
.onDisappear() { | |
player.pause() | |
} | |
}.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity) | |
.edgesIgnoringSafeArea(.all) | |
}//end body | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Absolutely amazing. Thanks for sharing!