1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-07 22:15:38 -05:00

audio: re-create players on default device change

This commit is contained in:
bbedward
2025-11-01 10:14:30 -04:00
parent ca786a3567
commit 5f22347d7a

View File

@@ -28,6 +28,9 @@ Singleton {
property var normalNotificationSound: null
property var criticalNotificationSound: null
property var mediaDevices: null
property var mediaDevicesConnections: null
signal micMuteChanged
Timer {
@@ -241,6 +244,37 @@ Singleton {
}
}
function setupMediaDevices() {
if (!soundsAvailable || mediaDevices) {
return
}
try {
mediaDevices = Qt.createQmlObject(`
import QtQuick
import QtMultimedia
MediaDevices {}
`, root, "AudioService.MediaDevices")
if (mediaDevices) {
mediaDevicesConnections = Qt.createQmlObject(`
import QtQuick
Connections {
function onDefaultAudioOutputChanged() {
console.log("AudioService: Default audio output changed, recreating sound players")
root.destroySoundPlayers()
root.createSoundPlayers()
}
}
`, root, "AudioService.MediaDevicesConnections")
mediaDevicesConnections.target = mediaDevices
}
} catch (e) {
console.log("AudioService: MediaDevices not available, using default audio output")
mediaDevices = null
}
}
function destroySoundPlayers() {
if (volumeChangeSound) {
volumeChangeSound.destroy()
@@ -269,14 +303,20 @@ Singleton {
return
}
setupMediaDevices()
try {
const deviceProperty = mediaDevices ? `device: root.mediaDevices.defaultAudioOutput\n ` : ""
const volumeChangePath = getSoundPath("audio-volume-change")
volumeChangeSound = Qt.createQmlObject(`
import QtQuick
import QtMultimedia
MediaPlayer {
source: "${volumeChangePath}"
audioOutput: AudioOutput { volume: 1.0 }
audioOutput: AudioOutput {
${deviceProperty}volume: 1.0
}
}
`, root, "AudioService.VolumeChangeSound")
@@ -286,7 +326,9 @@ Singleton {
import QtMultimedia
MediaPlayer {
source: "${powerPlugPath}"
audioOutput: AudioOutput { volume: 1.0 }
audioOutput: AudioOutput {
${deviceProperty}volume: 1.0
}
}
`, root, "AudioService.PowerPlugSound")
@@ -296,7 +338,9 @@ Singleton {
import QtMultimedia
MediaPlayer {
source: "${powerUnplugPath}"
audioOutput: AudioOutput { volume: 1.0 }
audioOutput: AudioOutput {
${deviceProperty}volume: 1.0
}
}
`, root, "AudioService.PowerUnplugSound")
@@ -306,7 +350,9 @@ Singleton {
import QtMultimedia
MediaPlayer {
source: "${messagePath}"
audioOutput: AudioOutput { volume: 1.0 }
audioOutput: AudioOutput {
${deviceProperty}volume: 1.0
}
}
`, root, "AudioService.NormalNotificationSound")
@@ -316,7 +362,9 @@ Singleton {
import QtMultimedia
MediaPlayer {
source: "${messageNewInstantPath}"
audioOutput: AudioOutput { volume: 1.0 }
audioOutput: AudioOutput {
${deviceProperty}volume: 1.0
}
}
`, root, "AudioService.CriticalNotificationSound")
} catch (e) {