Skip to content

Commit cccb5b1

Browse files
committed
修复修改播放设置-音频输出设置后,所做的更改没有被保存的问题(#1116
1 parent 3c58974 commit cccb5b1

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

publish/changeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- 修复桌面歌词使用斜体出现截断的问题(#1106
77
- 修复某些情况下歌词的滚动问题
88
- 修复禁用切歌时歌曲播放完毕后的歌曲信息显示问题
9+
- 修复修改播放设置-音频输出设置后,所做的更改没有被保存的问题
910

1011
### 优化
1112

src/renderer/core/useApp/usePlayer/useMediaDevice.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const getDevices = async() => {
1414

1515
export default () => {
1616
let prevDeviceLabel: string | null = null
17+
let prevDeviceId = ''
1718

1819
const setMediaDevice = async(mediaDeviceId: string) => {
1920
let label = prevDeviceLabel
@@ -30,9 +31,15 @@ export default () => {
3031

3132
prevDeviceLabel = label
3233
// console.log(device)
33-
setMediaDeviceId(mediaDeviceId).catch((err: any) => {
34+
setMediaDeviceId(mediaDeviceId).then(() => {
35+
prevDeviceId = mediaDeviceId
36+
saveMediaDeviceId(mediaDeviceId)
37+
}).catch((err: any) => {
3438
console.log(err)
35-
saveMediaDeviceId('default')
39+
setMediaDeviceId('default').finally(() => {
40+
prevDeviceId = 'default'
41+
saveMediaDeviceId('default')
42+
})
3643
})
3744
}
3845

@@ -60,13 +67,13 @@ export default () => {
6067
// @ts-expect-error
6168
handleDeviceChangeStopPlay(device, mediaDeviceId)
6269

63-
setMediaDeviceId(device!.deviceId).catch((err: any) => {
64-
console.log(err)
65-
saveMediaDeviceId('default')
66-
})
70+
void setMediaDevice(device!.deviceId)
6771
}
6872

69-
watch(() => appSetting['player.mediaDeviceId'], setMediaDevice)
73+
watch(() => appSetting['player.mediaDeviceId'], (id) => {
74+
if (prevDeviceId == id) return
75+
void setMediaDevice(id)
76+
})
7077

7178

7279
void setMediaDevice(appSetting['player.mediaDeviceId'])

0 commit comments

Comments
 (0)