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:
@@ -28,6 +28,9 @@ Singleton {
|
|||||||
property var normalNotificationSound: null
|
property var normalNotificationSound: null
|
||||||
property var criticalNotificationSound: null
|
property var criticalNotificationSound: null
|
||||||
|
|
||||||
|
property var mediaDevices: null
|
||||||
|
property var mediaDevicesConnections: null
|
||||||
|
|
||||||
signal micMuteChanged
|
signal micMuteChanged
|
||||||
|
|
||||||
Timer {
|
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() {
|
function destroySoundPlayers() {
|
||||||
if (volumeChangeSound) {
|
if (volumeChangeSound) {
|
||||||
volumeChangeSound.destroy()
|
volumeChangeSound.destroy()
|
||||||
@@ -269,14 +303,20 @@ Singleton {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setupMediaDevices()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const deviceProperty = mediaDevices ? `device: root.mediaDevices.defaultAudioOutput\n ` : ""
|
||||||
|
|
||||||
const volumeChangePath = getSoundPath("audio-volume-change")
|
const volumeChangePath = getSoundPath("audio-volume-change")
|
||||||
volumeChangeSound = Qt.createQmlObject(`
|
volumeChangeSound = Qt.createQmlObject(`
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import QtMultimedia
|
import QtMultimedia
|
||||||
MediaPlayer {
|
MediaPlayer {
|
||||||
source: "${volumeChangePath}"
|
source: "${volumeChangePath}"
|
||||||
audioOutput: AudioOutput { volume: 1.0 }
|
audioOutput: AudioOutput {
|
||||||
|
${deviceProperty}volume: 1.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
`, root, "AudioService.VolumeChangeSound")
|
`, root, "AudioService.VolumeChangeSound")
|
||||||
|
|
||||||
@@ -286,7 +326,9 @@ Singleton {
|
|||||||
import QtMultimedia
|
import QtMultimedia
|
||||||
MediaPlayer {
|
MediaPlayer {
|
||||||
source: "${powerPlugPath}"
|
source: "${powerPlugPath}"
|
||||||
audioOutput: AudioOutput { volume: 1.0 }
|
audioOutput: AudioOutput {
|
||||||
|
${deviceProperty}volume: 1.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
`, root, "AudioService.PowerPlugSound")
|
`, root, "AudioService.PowerPlugSound")
|
||||||
|
|
||||||
@@ -296,7 +338,9 @@ Singleton {
|
|||||||
import QtMultimedia
|
import QtMultimedia
|
||||||
MediaPlayer {
|
MediaPlayer {
|
||||||
source: "${powerUnplugPath}"
|
source: "${powerUnplugPath}"
|
||||||
audioOutput: AudioOutput { volume: 1.0 }
|
audioOutput: AudioOutput {
|
||||||
|
${deviceProperty}volume: 1.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
`, root, "AudioService.PowerUnplugSound")
|
`, root, "AudioService.PowerUnplugSound")
|
||||||
|
|
||||||
@@ -306,7 +350,9 @@ Singleton {
|
|||||||
import QtMultimedia
|
import QtMultimedia
|
||||||
MediaPlayer {
|
MediaPlayer {
|
||||||
source: "${messagePath}"
|
source: "${messagePath}"
|
||||||
audioOutput: AudioOutput { volume: 1.0 }
|
audioOutput: AudioOutput {
|
||||||
|
${deviceProperty}volume: 1.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
`, root, "AudioService.NormalNotificationSound")
|
`, root, "AudioService.NormalNotificationSound")
|
||||||
|
|
||||||
@@ -316,7 +362,9 @@ Singleton {
|
|||||||
import QtMultimedia
|
import QtMultimedia
|
||||||
MediaPlayer {
|
MediaPlayer {
|
||||||
source: "${messageNewInstantPath}"
|
source: "${messageNewInstantPath}"
|
||||||
audioOutput: AudioOutput { volume: 1.0 }
|
audioOutput: AudioOutput {
|
||||||
|
${deviceProperty}volume: 1.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
`, root, "AudioService.CriticalNotificationSound")
|
`, root, "AudioService.CriticalNotificationSound")
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user