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
18 changes: 18 additions & 0 deletions Demo/Demo-iOS/Demo-iOS/Player/Metal/MPVMetalViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,24 @@ final class MPVMetalViewController: UIViewController {
let client = unsafeBitCast(ctx, to: MPVMetalViewController.self)
client.readEvents()
}, UnsafeMutableRawPointer(Unmanaged.passUnretained(self).toOpaque()))

setupNotification()
}

public func setupNotification() {
NotificationCenter.default.addObserver(self, selector: #selector(enterBackground), name: UIApplication.didEnterBackgroundNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(enterForeground), name: UIApplication.willEnterForegroundNotification, object: nil)
}

@objc public func enterBackground() {
// fix black screen issue when app enter foreground again
pause()
checkError(mpv_set_option_string(mpv, "vid", "no"))
}

@objc public func enterForeground() {
checkError(mpv_set_option_string(mpv, "vid", "auto"))
play()
}


Expand Down
2 changes: 2 additions & 0 deletions Demo/Demo-macOS/Demo-macOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 14.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.mpvkit.Demo-macOS";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -389,6 +390,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 14.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.mpvkit.Demo-macOS";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
18 changes: 18 additions & 0 deletions Demo/Demo-macOS/Demo-macOS/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct ContentView: View {
}
}
}
.focusable()
.overlay {
HStack {
VStack(alignment: .leading, spacing: 12) {
Expand All @@ -49,6 +50,11 @@ struct ContentView: View {
} label: {
Text("subtitle").frame(maxWidth: .infinity)
}
Button {
coordinator.play(URL(string: "https://framatube.org/static/streaming-playlists/hls/66fcff64-d8f9-49c1-8deb-011b115786de/73451ad8-d30e-4beb-aa92-3dba23ba07c8-720.m3u8")!)
} label: {
Text("hls").frame(maxWidth: .infinity)
}
Button {
coordinator.play(URL(string: "https://github.com/mpvkit/video-test/raw/master/resources/hdr.mkv")!)
} label: {
Expand Down Expand Up @@ -96,6 +102,18 @@ struct ContentView: View {
.onHover { hover in
showControlOverlay = hover
}
.onKeyPress(action: { key in
debugPrint("key: \(key.characters)")
return .handled
})
.onKeyPress(.leftArrow, action: {
coordinator.seek(relative: -10)
return .handled
})
.onKeyPress(.rightArrow, action: {
coordinator.seek(relative: 10)
return .handled
})
.overlay(overlayView)
.preferredColorScheme(.dark)
.ignoresSafeArea()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ struct MPVMetalPlayerView: NSViewControllerRepresentable {
self.pause = false
}

func seek(relative time: TimeInterval) {
player?.seek(relative: time)
}

func propertyChange(mpv: OpaquePointer, propertyName: String, data: Any?) {
guard let player else { return }
self.onPropertyChange?(player, propertyName, data)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Foundation
import AppKit
import CoreMedia
import Libmpv

// warning: metal API validation has been disabled to ignore crash when playing HDR videos.
Expand Down Expand Up @@ -102,10 +103,10 @@ final class MPVMetalViewController: NSViewController {
checkError(mpv_set_option_string(mpv, "gpu-context", "moltenvk"))
checkError(mpv_set_option_string(mpv, "hwdec", "videotoolbox"))
checkError(mpv_set_option_string(mpv, "ytdl", "no"))
// checkError(mpv_set_option_string(mpv, "target-colorspace-hint", "yes")) // HDR passthrough
// checkError(mpv_set_option_string(mpv, "tone-mapping-visualize", "yes")) // only for debugging purposes
// checkError(mpv_set_option_string(mpv, "profile", "fast")) // can fix frame drop in poor device when play 4k

// checkError(mpv_set_option_string(mpv, "target-colorspace-hint", "yes")) // HDR passthrough
// checkError(mpv_set_option_string(mpv, "tone-mapping-visualize", "yes")) // only for debugging purposes
// checkError(mpv_set_option_string(mpv, "profile", "fast")) // can fix frame drop in poor device when play 4k

checkError(mpv_initialize(mpv))

Expand Down Expand Up @@ -148,6 +149,10 @@ final class MPVMetalViewController: NSViewController {
setFlag("pause", true)
}

func seek(relative time: TimeInterval) {
command("seek", args: [String(time), "relative"])
}

private func getDouble(_ name: String) -> Double {
guard mpv != nil else { return 0.0 }
var data = Double()
Expand Down Expand Up @@ -194,7 +199,7 @@ final class MPVMetalViewController: NSViewController {
}
}



private func makeCArgs(_ command: String, _ args: [String?]) -> [String?] {
if !args.isEmpty, args.last == nil {
Expand Down
4 changes: 4 additions & 0 deletions Demo/Demo-macOS/Demo-macOS/Player/OpenGL/MPVOGLView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ final class MPVOGLView: NSOpenGLView {
command("loadfile", args: args)
}

func seek(relative time: TimeInterval) {
command("seek", args: [String(time), "relative"])
}

func getDouble(_ name: String) -> Double {
guard mpv != nil else { return 0.0 }
var data = Double()
Expand Down
4 changes: 4 additions & 0 deletions Demo/Demo-macOS/Demo-macOS/Player/OpenGL/MPVPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ struct MPVPlayerView: NSViewControllerRepresentable {
player?.loadFile(url)
}

func seek(relative time: TimeInterval) {
player?.seek(relative: time)
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ class MPVViewController: NSViewController {
func pause() {
self.glView.setFlag("pause", true)
}

func seek(relative time: TimeInterval) {
self.glView.seek(relative: time)
}
}
17 changes: 17 additions & 0 deletions Demo/Demo-tvOS/Demo-tvOS/Player/Metal/MPVMetalViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,25 @@ final class MPVMetalViewController: UIViewController {
let client = unsafeBitCast(ctx, to: MPVMetalViewController.self)
client.readEvents()
}, UnsafeMutableRawPointer(Unmanaged.passUnretained(self).toOpaque()))

setupNotification()
}

public func setupNotification() {
NotificationCenter.default.addObserver(self, selector: #selector(enterBackground), name: UIApplication.didEnterBackgroundNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(enterForeground), name: UIApplication.willEnterForegroundNotification, object: nil)
}

@objc public func enterBackground() {
// fix black screen issue when app enter foreground again
pause()
checkError(mpv_set_option_string(mpv, "vid", "no"))
}

@objc public func enterForeground() {
checkError(mpv_set_option_string(mpv, "vid", "auto"))
play()
}

func loadFile(
_ url: URL
Expand Down
4 changes: 2 additions & 2 deletions Sources/BuildScripts/XCFrameworkBuild/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ enum Library: String, CaseIterable {
case .libmpv:
return "v0.40.0"
case .FFmpeg:
return "n7.1.1"
return "n8.0"
case .openssl:
return "3.2.0"
case .gnutls:
Expand Down Expand Up @@ -654,7 +654,7 @@ private class BuildFFMPEG: BaseBuild {
"--disable-doc", "--disable-htmlpages", "--disable-manpages", "--disable-podpages", "--disable-txtpages",
// Component options:
"--enable-avcodec", "--enable-avformat", "--enable-avutil", "--enable-network", "--enable-swresample", "--enable-swscale",
"--disable-devices", "--disable-outdevs", "--disable-indevs", "--disable-postproc",
"--disable-devices", "--disable-outdevs", "--disable-indevs",
// ,"--disable-pthreads"
// ,"--disable-w32threads"
// ,"--disable-os2threads"
Expand Down
39 changes: 0 additions & 39 deletions Sources/BuildScripts/patch/FFmpeg/0001-hls-seek-patch-1.patch

This file was deleted.

78 changes: 0 additions & 78 deletions Sources/BuildScripts/patch/FFmpeg/0002-hls-seek-patch-2.patch

This file was deleted.

35 changes: 35 additions & 0 deletions Sources/BuildScripts/patch/libmpv/0003-fix-ffmpeg-n8.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
From 26b29fba02a2782f68e2906f837d21201fc6f1b9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= <kasper93@gmail.com>
Date: Fri, 28 Mar 2025 19:12:01 +0100
Subject: [PATCH] demux_mkv: fix compilation after deprecated definitions
removal

See: https://github.com/FFmpeg/FFmpeg/commit/822432769868da325ba03774df1084aa78b9a5a0
---
demux/demux_mkv.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c
index 135edcc23d82b..cc7ce3e98f4f6 100644
--- a/demux/demux_mkv.c
+++ b/demux/demux_mkv.c
@@ -2200,16 +2200,16 @@ static int demux_mkv_open_sub(demuxer_t *demuxer, mkv_track_t *track)
// [0x30..0x37] are component tags utilized for
// non-mobile captioning service ("profile A").
if (component_tag >= 0x30 && component_tag <= 0x37)
- lav->profile = FF_PROFILE_ARIB_PROFILE_A;
+ lav->profile = AV_PROFILE_ARIB_PROFILE_A;
break;
case 0x0012:
// component tag 0x87 signifies a mobile/partial reception
// (1seg) captioning service ("profile C").
if (component_tag == 0x87)
- lav->profile = FF_PROFILE_ARIB_PROFILE_C;
+ lav->profile = AV_PROFILE_ARIB_PROFILE_C;
break;
}
- if (lav->profile == FF_PROFILE_UNKNOWN)
+ if (lav->profile == AV_PROFILE_UNKNOWN)
MP_WARN(demuxer, "ARIB caption profile %02x / %04x not supported.\n",
component_tag, data_component_id);
}