Skip to content

Commit 3df152f

Browse files
feat: manual audio device selector (#237)
* Add manual audio selector * fixed the bugs in config.qml * fix and simplify audio device configuration * simplify AudioOutput device selection * AudioOutputDevice should be empty by default --------- Co-authored-by: Luis Bocanegra <luisbocanegra@users.noreply.github.com>
1 parent eb9e98b commit 3df152f

5 files changed

Lines changed: 65 additions & 2 deletions

File tree

package/contents/config/main.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@
1111
<default>[]</default>
1212
</entry>
1313
<entry name="BackgroundColor" type="String">
14-
<label>Last folder used</label>
14+
<label>Background color</label>
1515
<default>#000000</default>
1616
</entry>
17+
<entry name="AudioOutputDevice" type="String">
18+
<label>Audio output device</label>
19+
<default></default>
20+
</entry>
1721
<entry name="FillMode" type="Int">
1822
<label>Video fill mode</label>
1923
<default>2</default>

package/contents/ui/FadePlayer.qml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Item {
2626
property bool fillBlur: true
2727
property real alternativePlaybackRateGlobal: 0.5
2828
property bool useAlternativePlaybackRate: false
29+
property string audioOutputDevice
2930

3031
// Crossfade must not be longer than the shortest video or the fade becomes glitchy
3132
// we don't know the length until a video gets played, so the crossfade duration
@@ -111,6 +112,7 @@ Item {
111112
source: playerSource.filename ?? ""
112113
volume: root.volume
113114
muted: root.muted
115+
audioOutputDevice: root.audioOutputDevice
114116
z: 2
115117
opacity: 1
116118
fillMode: root.fillMode
@@ -206,6 +208,7 @@ Item {
206208
source: playerSource.filename ?? ""
207209
volume: root.volume
208210
muted: root.muted
211+
audioOutputDevice: root.audioOutputDevice
209212
z: 1
210213
fillMode: root.fillMode
211214
fillBlur: root.fillBlur

package/contents/ui/VideoPlayer.qml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Item {
2121
readonly property alias videoHeight: videoOutput.contentRect.height
2222
readonly property alias videoWidth: videoOutput.contentRect.width
2323
readonly property bool showFillBlur: root.fillBlur && root.fitScale !== 1
24+
property string audioOutputDevice
25+
readonly property string currentAudioDevice: audioOutput.device ? audioOutput.device.description : i18n("Unknown")
2426
property real fitScale: {
2527
if (height > videoHeight) {
2628
return height / videoHeight;
@@ -48,9 +50,22 @@ Item {
4850
anchors.fill: parent
4951
}
5052

53+
MediaDevices {
54+
id: mediaDevices
55+
}
56+
5157
AudioOutput {
5258
id: audioOutput
5359
volume: root.opacity * root.volume
60+
device: {
61+
let output;
62+
if (root.audioOutputDevice !== "") {
63+
output = mediaDevices.audioOutputs.find(o => {
64+
return o.id.toString() === root.audioOutputDevice;
65+
});
66+
}
67+
return output || mediaDevices.defaultAudioOutput;
68+
}
5469
}
5570

5671
MediaPlayer {

package/contents/ui/config.qml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ ColumnLayout {
4545
property alias cfg_BatteryDisablesBlur: batteryDisablesBlurCheckBox.checked
4646
property alias cfg_BlurRadius: blurRadiusSpinBox.value
4747
property string cfg_VideoUrls
48+
property alias cfg_AudioOutputDevice: audioDeviceCombo.currentValue
4849
property bool isLoading: false
4950
property alias cfg_ScreenOffPausesVideo: screenOffPausesVideoCheckbox.checked
5051
property alias cfg_ScreenStateCmd: screenStateCmdTextField.text
@@ -157,6 +158,34 @@ ColumnLayout {
157158
return model;
158159
}
159160

161+
MediaDevices {
162+
id: mediaDevices
163+
onAudioOutputsChanged: root.getAudioDevicesModel()
164+
}
165+
166+
ListModel {
167+
id: audioDevicesModel
168+
}
169+
170+
function getAudioDevicesModel() {
171+
audioDevicesModel.clear();
172+
173+
audioDevicesModel.append({
174+
"id": "",
175+
"description": i18nd("plasma_wallpaper_luisbocanegra.smart.video.wallpaper.reborn", "Default")
176+
});
177+
178+
mediaDevices.audioOutputs.forEach(o => {
179+
const id = o.id.toString();
180+
const description = o.description.toString();
181+
console.log("Output", id, description);
182+
audioDevicesModel.append({
183+
id,
184+
description
185+
});
186+
});
187+
}
188+
160189
function updateConfig() {
161190
let videos = new Array();
162191
for (let i = 0; i < videosModel.model.count; i++) {
@@ -193,6 +222,7 @@ ColumnLayout {
193222

194223
Component.onCompleted: {
195224
videosModel.initModel(cfg_VideoUrls);
225+
getAudioDevicesModel();
196226
}
197227

198228
Kirigami.FormLayout {
@@ -604,6 +634,15 @@ ColumnLayout {
604634
visible: root.currentTab === 1
605635
}
606636

637+
ComboBox {
638+
id: audioDeviceCombo
639+
visible: root.currentTab === 1 && root.cfg_MuteMode !== 5
640+
Kirigami.FormData.label: i18nd("plasma_wallpaper_luisbocanegra.smart.video.wallpaper.reborn", "Audio device:")
641+
model: audioDevicesModel
642+
textRole: "description"
643+
valueRole: "id"
644+
}
645+
607646
RowLayout {
608647
visible: root.currentTab === 1 && root.cfg_MuteMode !== 5
609648
Label {

package/contents/ui/main.qml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ WallpaperItem {
302302
useAlternativePlaybackRate: main.useAlternativePlaybackRate
303303
alternativePlaybackRateGlobal: main.configuration.AlternativePlaybackRate
304304
resumeLastVideo: main.configuration.ResumeLastVideo
305+
audioOutputDevice: main.configuration.AudioOutputDevice
305306
}
306307
}
307308
FastBlur {
@@ -368,7 +369,8 @@ WallpaperItem {
368369
text += `inLockScreen: ${main.lockScreenMode}\n`;
369370
text += `screenLocked: ${main.screenLocked}\n`;
370371
text += `showBlur: ${main.showBlur}\n`;
371-
text += `id: ${Plasmoid.id}`;
372+
text += `id: ${Plasmoid.id}\n`;
373+
text += `Audio Device: ${player.player1.currentAudioDevice}`;
372374
return text;
373375
}
374376
}

0 commit comments

Comments
 (0)