@@ -14,6 +14,7 @@ const getDevices = async() => {
1414
1515export 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