Skip to content

Instantly share code, notes, and snippets.

@bpmarkowitz
Created April 3, 2024 16:09
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bpmarkowitz/d5953120d28bca6e0de49cc800d6985b to your computer and use it in GitHub Desktop.
Save bpmarkowitz/d5953120d28bca6e0de49cc800d6985b to your computer and use it in GitHub Desktop.
Simple Swift UI Video Player
//
// 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()
}
}
@codybrom
Copy link

codybrom commented Apr 4, 2024

Absolutely amazing. Thanks for sharing!

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