Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
398 changes: 398 additions & 0 deletions Demo/Demo-visionOS/Demo-visionOS.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"idiom" : "vision",
"scale" : "2x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"info" : {
"author" : "xcode",
"version" : 1
},
"layers" : [
{
"filename" : "Front.solidimagestacklayer"
},
{
"filename" : "Middle.solidimagestacklayer"
},
{
"filename" : "Back.solidimagestacklayer"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"idiom" : "vision",
"scale" : "2x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"idiom" : "vision",
"scale" : "2x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
71 changes: 71 additions & 0 deletions Demo/Demo-visionOS/Demo-visionOS/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import SwiftUI

struct ContentView: View {
@ObservedObject var coordinator = MPVMetalPlayerView.Coordinator()
@State var loading = false


var body: some View {
VStack {
MPVMetalPlayerView(coordinator: coordinator)
.play(URL(string: "https://github.com/mpvkit/video-test/raw/master/resources/HDR10_ToneMapping_Test_240_1000_nits.mp4")!)
.onPropertyChange{ player, propertyName, propertyData in
switch propertyName {
case MPVProperty.pausedForCache:
loading = propertyData as! Bool
default: break
}
}
}
.overlay {
VStack {
Spacer()
ScrollView(.horizontal) {
HStack {
Button {
coordinator.play(URL(string: "https://vjs.zencdn.net/v/oceans.mp4")!)
} label: {
Text("h264").frame(width: 130, height: 100)
}
Button {
coordinator.play(URL(string: "https://github.com/mpvkit/video-test/raw/master/resources/h265.mp4")!)
} label: {
Text("h265").frame(width: 130, height: 100)
}
Button {
coordinator.play(URL(string: "https://github.com/mpvkit/video-test/raw/master/resources/pgs_subtitle.mkv")!)
} label: {
Text("subtitle").frame(width: 130, height: 100)
}
Button {
coordinator.play(URL(string: "https://github.com/mpvkit/video-test/raw/master/resources/hdr.mkv")!)
} label: {
Text("HDR").frame(width: 130, height: 100)
}
Button {
coordinator.play(URL(string: "https://github.com/mpvkit/video-test/raw/master/resources/DolbyVision_P5.mp4")!)
} label: {
Text("DV_P5").frame(width: 130, height: 100)
}
Button {
coordinator.play(URL(string: "https://github.com/mpvkit/video-test/raw/master/resources/DolbyVision_P8.mp4")!)
} label: {
Text("DV_P8").frame(width: 130, height: 100)
}
}
}
}
}
.overlay(overlayView)
.preferredColorScheme(.dark)
}

@ViewBuilder
private var overlayView: some View {
if loading {
ProgressView()
} else {
EmptyView()
}
}
}
11 changes: 11 additions & 0 deletions Demo/Demo-visionOS/Demo-visionOS/Demo_visionOSApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import SwiftUI

@main
struct Demo_visionOSApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
.defaultSize(width: 1280, height: 720)
}
}
11 changes: 11 additions & 0 deletions Demo/Demo-visionOS/Demo-visionOS/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Foundation

@MainActor
public protocol MPVPlayerDelegate: AnyObject {
func propertyChange(mpv: OpaquePointer, propertyName: String, data: Any?)
}
14 changes: 14 additions & 0 deletions Demo/Demo-visionOS/Demo-visionOS/Player/MPVProperty.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Foundation

struct MPVProperty {
static let videoParamsColormatrix = "video-params/colormatrix"
static let videoParamsColorlevels = "video-params/colorlevels"
static let videoParamsPrimaries = "video-params/primaries"
static let videoParamsGamma = "video-params/gamma"
static let videoParamsSigPeak = "video-params/sig-peak"
static let videoParamsSceneMaxR = "video-params/scene-max-r"
static let videoParamsSceneMaxG = "video-params/scene-max-g"
static let videoParamsSceneMaxB = "video-params/scene-max-b"
static let pause = "pause"
static let pausedForCache = "paused-for-cache"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import Foundation
import SwiftUI

struct MPVMetalPlayerView: UIViewControllerRepresentable {
@ObservedObject var coordinator: Coordinator

func makeUIViewController(context: Context) -> some UIViewController {
let mpv = MPVMetalViewController()
mpv.playDelegate = coordinator
mpv.playUrl = coordinator.playUrl

context.coordinator.player = mpv
return mpv
}

func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {
}

public func makeCoordinator() -> Coordinator {
coordinator
}

func play(_ url: URL) -> Self {
coordinator.playUrl = url
return self
}

func onPropertyChange(_ handler: @escaping (MPVMetalViewController, String, Any?) -> Void) -> Self {
coordinator.onPropertyChange = handler
return self
}

@MainActor
public final class Coordinator: MPVPlayerDelegate, ObservableObject {
weak var player: MPVMetalViewController?

var playUrl : URL?
var onPropertyChange: ((MPVMetalViewController, String, Any?) -> Void)?

func play(_ url: URL) {
player?.loadFile(url)
}

func propertyChange(mpv: OpaquePointer, propertyName: String, data: Any?) {
guard let player else { return }

self.onPropertyChange?(player, propertyName, data)
}
}
}
Loading