mirror of
https://github.com/yattee/yattee.git
synced 2025-11-15 22:48:43 +00:00
This commit enables proper Now Playing Info Center integration on iOS, allowing video playback information to appear in Control Center and Lock Screen with working remote controls. Key changes: - Activate audio session on app launch with setCategory(.playback, mode: .moviePlayback) and setActive(true) - Set up remote commands on first play() call instead of during app initialization to avoid claiming Now Playing slot prematurely - Remove removeTarget(nil) calls that were claiming Now Playing without content - Enable remote commands (play, pause, toggle, seek) explicitly and add proper target handlers - Use backend.isPlaying instead of PlayerModel.isPlaying to avoid race conditions - Include playback rate (1.0 for playing, 0.0 for paused) in Now Playing info - Update Now Playing info on main queue for thread safety - Update Now Playing when switching between backends - Remove audio session deactivation from pause() and stop() methods Note: This fix works for AVPlayer backend. MPV backend has fundamental incompatibility with iOS Now Playing system.
46 lines
1.6 KiB
Swift
46 lines
1.6 KiB
Swift
import AVFoundation
|
|
import Defaults
|
|
import Foundation
|
|
import Logging
|
|
import UIKit
|
|
|
|
final class AppDelegate: UIResponder, UIApplicationDelegate {
|
|
var orientationLock = UIInterfaceOrientationMask.all
|
|
|
|
private var logger = Logger(label: "stream.yattee.app.delegate")
|
|
private(set) static var instance: AppDelegate!
|
|
|
|
func application(_: UIApplication, supportedInterfaceOrientationsFor _: UIWindow?) -> UIInterfaceOrientationMask {
|
|
return orientationLock
|
|
}
|
|
|
|
func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { // swiftlint:disable:this discouraged_optional_collection
|
|
Self.instance = self
|
|
|
|
#if !os(macOS)
|
|
UIViewController.swizzleHomeIndicatorProperty()
|
|
OrientationTracker.shared.startDeviceOrientationTracking()
|
|
OrientationModel.shared.startOrientationUpdates()
|
|
|
|
do {
|
|
try AVAudioSession.sharedInstance().setCategory(.playback, mode: .moviePlayback)
|
|
try AVAudioSession.sharedInstance().setActive(true)
|
|
} catch {
|
|
logger.error("Failed to set audio session category: \(error)")
|
|
}
|
|
|
|
UIApplication.shared.beginReceivingRemoteControlEvents()
|
|
#endif
|
|
|
|
return true
|
|
}
|
|
|
|
func application(_: UIApplication, open url: URL, options _: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
|
|
if url.scheme == "yattee" {
|
|
OpenURLHandler(navigationStyle: Constants.defaultNavigationStyle).handle(url)
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
}
|