mirror of
https://github.com/yattee/yattee.git
synced 2025-11-22 06:31:26 +00:00
Fix audio session interrupting other apps on launch
Previously, the audio session was initialized immediately when the app launched, causing audio from other apps (like Music) to stop even when no video was playing in Yattee. Changes: - Remove audio session initialization from AppDelegate launch - Remove audio session setup from MPVClient initialization - Update setAudioSessionActive() to configure audio session category before activation The audio session is now lazily initialized only when playback actually starts: - For MPV backend: triggered by FILE_LOADED, PLAYBACK_RESTART, AUDIO_RECONFIG events - For AVPlayer backend: triggered when play() is called This allows music from other apps to continue playing until a video is actually played in Yattee.
This commit is contained in:
@@ -135,12 +135,6 @@ final class MPVClient: ObservableObject {
|
||||
|
||||
checkError(mpv_initialize(mpv))
|
||||
|
||||
#if !os(macOS)
|
||||
// Set up audio session for Now Playing support
|
||||
backend?.model.setupAudioSessionForNowPlaying()
|
||||
backend?.model.updateNowPlayingInfo()
|
||||
#endif
|
||||
|
||||
let api = UnsafeMutableRawPointer(mutating: (MPV_RENDER_API_TYPE_OPENGL as NSString).utf8String)
|
||||
var initParams = mpv_opengl_init_params(
|
||||
get_proc_address: getProcAddress,
|
||||
|
||||
@@ -1394,7 +1394,11 @@ final class PlayerModel: ObservableObject {
|
||||
func setAudioSessionActive(_ setActive: Bool) {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
|
||||
do {
|
||||
try AVAudioSession.sharedInstance().setActive(setActive)
|
||||
let audioSession = AVAudioSession.sharedInstance()
|
||||
if setActive {
|
||||
try audioSession.setCategory(.playback, mode: .moviePlayback)
|
||||
}
|
||||
try audioSession.setActive(setActive)
|
||||
} catch {
|
||||
self.logger.error("Error setting audio session to \(setActive): \(error)")
|
||||
}
|
||||
|
||||
@@ -22,13 +22,6 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user