新增所选音频输出设备被移除时是否暂停播放

pull/277/head
lyswhut 2020-05-08 19:14:44 +08:00
parent ecf9dce758
commit 26bdf25423
12 changed files with 223 additions and 181 deletions

242
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "lx-music-desktop",
"version": "0.18.0",
"version": "0.18.3",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -1477,9 +1477,9 @@
"dev": true
},
"@vue/component-compiler-utils": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/@vue/component-compiler-utils/-/component-compiler-utils-3.1.1.tgz",
"integrity": "sha512-+lN3nsfJJDGMNz7fCpcoYIORrXo0K3OTsdr8jCM7FuqdI4+70TY6gxY6viJ2Xi1clqyPg7LpeOWwjF31vSMmUw==",
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/@vue/component-compiler-utils/-/component-compiler-utils-3.1.2.tgz",
"integrity": "sha512-QLq9z8m79mCinpaEeSURhnNCN6djxpHw0lpP/bodMlt5kALfONpryMthvnrQOlTcIKoF+VoPi+lPHUYeDFPXug==",
"dev": true,
"requires": {
"consolidate": "^0.15.1",
@ -3733,65 +3733,13 @@
}
},
"cfonts": {
"version": "2.8.1",
"resolved": "https://registry.npmjs.org/cfonts/-/cfonts-2.8.1.tgz",
"integrity": "sha512-+vql7UbJQJQYOGM4kOC/r7x6yjY9dXERy+DE2RXFCKepwC0dZTdZrBL23P4G09OwgeIo9u6uFxw0Y7BqsowyOQ==",
"version": "2.8.2",
"resolved": "https://registry.npmjs.org/cfonts/-/cfonts-2.8.2.tgz",
"integrity": "sha512-qF0zbWCLPI4uHhbxP7IPA1nx5SFxfCZdurQjne20faeAOEtiUC4DHpost5sEpP7GNUEfpEI+e3PyLRE9k4KoLw==",
"dev": true,
"requires": {
"chalk": "^3.0.0",
"chalk": "^4.0.0",
"window-size": "^1.1.1"
},
"dependencies": {
"ansi-styles": {
"version": "4.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz",
"integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==",
"dev": true,
"requires": {
"@types/color-name": "^1.1.1",
"color-convert": "^2.0.1"
}
},
"chalk": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz",
"integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==",
"dev": true,
"requires": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
}
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"dev": true,
"requires": {
"color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"dev": true
},
"has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"dev": true
},
"supports-color": {
"version": "7.1.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz",
"integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==",
"dev": true,
"requires": {
"has-flag": "^4.0.0"
}
}
}
},
"chalk": {
@ -5583,9 +5531,9 @@
}
},
"electron-log": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/electron-log/-/electron-log-4.1.1.tgz",
"integrity": "sha512-vkK3rNBOciRiinxrsdgg8hyUia+ct8ZMjBblvKjgNk4uHEDjjSyn313NOwv75xOMVIKlfmYzxaN8kR/oGC33aQ=="
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/electron-log/-/electron-log-4.1.2.tgz",
"integrity": "sha512-MGPjGBEj6p0JdJmbqxbGud7kkHdV+T+D7gq1U+mfsnUM+o0bd4nPsQjVdgqQPsj0epoKdGbNIZ4FPpTQKhRfZA=="
},
"electron-publish": {
"version": "22.6.0",
@ -9311,9 +9259,9 @@
}
},
"jest-worker": {
"version": "25.4.0",
"resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-25.4.0.tgz",
"integrity": "sha512-ghAs/1FtfYpMmYQ0AHqxV62XPvKdUDIBBApMZfly+E9JEmYh2K45G0R5dWxx986RN12pRCxsViwQVtGl+N4whw==",
"version": "26.0.0",
"resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-26.0.0.tgz",
"integrity": "sha512-pPaYa2+JnwmiZjK9x7p9BoZht+47ecFCDFA/CJxspHzeDvQcfVBLWzCiWyo+EGrSiQMWZtCFo9iSvMZnAAo8vw==",
"dev": true,
"requires": {
"merge-stream": "^2.0.0",
@ -9583,9 +9531,9 @@
}
},
"less-loader": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/less-loader/-/less-loader-6.0.0.tgz",
"integrity": "sha512-k9KrSkjkdGCQwbKPHfbJT9AfRCmOCHCCjiQCc0v2fdVCRTlJvr1Si68Zk6Z4d4UyVkp0U/nEEdQeH4wV/jW8/g==",
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/less-loader/-/less-loader-6.1.0.tgz",
"integrity": "sha512-/jLzOwLyqJ7Kt3xg5sHHkXtOyShWwFj410K9Si9WO+/h8rmYxxkSR0A3/hFEntWudE20zZnWMtpMYnLzqTVdUA==",
"dev": true,
"requires": {
"clone": "^2.1.2",
@ -10140,6 +10088,24 @@
"minipass": "^3.0.0"
}
},
"minizlib": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.0.tgz",
"integrity": "sha512-EzTZN/fjSvifSX0SlqUERCN39o6T40AMarPbv0MrarSFtIITCBh7bi+dU8nxGFHuqs9jdIAeoYoKuQAAASsPPA==",
"dev": true,
"requires": {
"minipass": "^3.0.0",
"yallist": "^4.0.0"
},
"dependencies": {
"yallist": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
"dev": true
}
}
},
"mississippi": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/mississippi/-/mississippi-3.0.0.tgz",
@ -10218,6 +10184,23 @@
}
}
},
"move-file": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/move-file/-/move-file-2.0.0.tgz",
"integrity": "sha512-cdkdhNCgbP5dvS4tlGxZbD+nloio9GIimP57EjqFhwLcMjnU+XJKAZzlmg/TN/AK1LuNAdTSvm3CPPP4Xkv0iQ==",
"dev": true,
"requires": {
"path-exists": "^4.0.0"
},
"dependencies": {
"path-exists": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz",
"integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==",
"dev": true
}
}
},
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
@ -11704,7 +11687,8 @@
"version": "1.19.1",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz",
"integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==",
"dev": true
"dev": true,
"optional": true
},
"pretty-error": {
"version": "2.1.1",
@ -13940,6 +13924,40 @@
"integrity": "sha512-4WK/bYZmj8xLr+HUCODHGF1ZFzsYffasLUgEiMBY4fgtltdO6B4WJtlSbPaDTLpYTcGVwM2qLnFTICEcNxs3kA==",
"dev": true
},
"tar": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/tar/-/tar-6.0.2.tgz",
"integrity": "sha512-Glo3jkRtPcvpDlAs/0+hozav78yoXKFr+c4wgw62NNMO3oo4AaJdCo21Uu7lcwr55h39W2XD1LMERc64wtbItg==",
"dev": true,
"requires": {
"chownr": "^2.0.0",
"fs-minipass": "^2.0.0",
"minipass": "^3.0.0",
"minizlib": "^2.1.0",
"mkdirp": "^1.0.3",
"yallist": "^4.0.0"
},
"dependencies": {
"chownr": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz",
"integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==",
"dev": true
},
"mkdirp": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",
"integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==",
"dev": true
},
"yallist": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
"dev": true
}
}
},
"temp-file": {
"version": "3.3.7",
"resolved": "https://registry.npmjs.org/temp-file/-/temp-file-3.3.7.tgz",
@ -13992,48 +14010,53 @@
}
},
"terser-webpack-plugin": {
"version": "2.3.6",
"resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-2.3.6.tgz",
"integrity": "sha512-I8IDsQwZrqjdmOicNeE8L/MhwatAap3mUrtcAKJuilsemUNcX+Hier/eAzwStVqhlCxq0aG3ni9bK/0BESXkTg==",
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-3.0.1.tgz",
"integrity": "sha512-eFDtq8qPUEa9hXcUzTwKXTnugIVtlqc1Z/ZVhG8LmRT3lgRY13+pQTnFLY2N7ATB6TKCHuW/IGjoAnZz9wOIqw==",
"dev": true,
"requires": {
"cacache": "^13.0.1",
"cacache": "^15.0.3",
"find-cache-dir": "^3.3.1",
"jest-worker": "^25.4.0",
"jest-worker": "^26.0.0",
"p-limit": "^2.3.0",
"schema-utils": "^2.6.6",
"serialize-javascript": "^3.0.0",
"source-map": "^0.6.1",
"terser": "^4.6.12",
"terser": "^4.6.13",
"webpack-sources": "^1.4.3"
},
"dependencies": {
"cacache": {
"version": "13.0.1",
"resolved": "https://registry.npmjs.org/cacache/-/cacache-13.0.1.tgz",
"integrity": "sha512-5ZvAxd05HDDU+y9BVvcqYu2LLXmPnQ0hW62h32g4xBTgL/MppR4/04NHfj/ycM2y6lmTnbw6HVi+1eN0Psba6w==",
"version": "15.0.3",
"resolved": "https://registry.npmjs.org/cacache/-/cacache-15.0.3.tgz",
"integrity": "sha512-bc3jKYjqv7k4pWh7I/ixIjfcjPul4V4jme/WbjvwGS5LzoPL/GzXr4C5EgPNLO/QEZl9Oi61iGitYEdwcrwLCQ==",
"dev": true,
"requires": {
"chownr": "^1.1.2",
"figgy-pudding": "^3.5.1",
"chownr": "^2.0.0",
"fs-minipass": "^2.0.0",
"glob": "^7.1.4",
"graceful-fs": "^4.2.2",
"infer-owner": "^1.0.4",
"lru-cache": "^5.1.1",
"minipass": "^3.0.0",
"minipass": "^3.1.1",
"minipass-collect": "^1.0.2",
"minipass-flush": "^1.0.5",
"minipass-pipeline": "^1.2.2",
"mkdirp": "^0.5.1",
"move-concurrently": "^1.0.1",
"p-map": "^3.0.0",
"mkdirp": "^1.0.3",
"move-file": "^2.0.0",
"p-map": "^4.0.0",
"promise-inflight": "^1.0.1",
"rimraf": "^2.7.1",
"ssri": "^7.0.0",
"rimraf": "^3.0.2",
"ssri": "^8.0.0",
"tar": "^6.0.2",
"unique-filename": "^1.1.1"
}
},
"chownr": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz",
"integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==",
"dev": true
},
"commander": {
"version": "2.20.3",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
@ -14070,6 +14093,12 @@
"p-locate": "^4.1.0"
}
},
"mkdirp": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",
"integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==",
"dev": true
},
"p-limit": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz",
@ -14088,6 +14117,15 @@
"p-limit": "^2.2.0"
}
},
"p-map": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/p-map/-/p-map-4.0.0.tgz",
"integrity": "sha512-/bjOqmgETBYB5BoEeGVea8dmvHb2m9GLy1E9W43yeyfP6QQCZGFNa+XRceJEuDB6zqr+gKpIAmlLebMpykw/MQ==",
"dev": true,
"requires": {
"aggregate-error": "^3.0.0"
}
},
"path-exists": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz",
@ -14103,15 +14141,6 @@
"find-up": "^4.0.0"
}
},
"rimraf": {
"version": "2.7.1",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz",
"integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==",
"dev": true,
"requires": {
"glob": "^7.1.3"
}
},
"schema-utils": {
"version": "2.6.6",
"resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-2.6.6.tgz",
@ -14145,19 +14174,18 @@
}
},
"ssri": {
"version": "7.1.0",
"resolved": "https://registry.npmjs.org/ssri/-/ssri-7.1.0.tgz",
"integrity": "sha512-77/WrDZUWocK0mvA5NTRQyveUf+wsrIc6vyrxpS8tVvYBcX215QbafrJR3KtkpskIzoFLqqNuuYQvxaMjXJ/0g==",
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/ssri/-/ssri-8.0.0.tgz",
"integrity": "sha512-aq/pz989nxVYwn16Tsbj1TqFpD5LLrQxHf5zaHuieFV+R0Bbr4y8qUsOA45hXT/N4/9UNXTarBjnjVmjSOVaAA==",
"dev": true,
"requires": {
"figgy-pudding": "^3.5.1",
"minipass": "^3.1.1"
}
},
"terser": {
"version": "4.6.12",
"resolved": "https://registry.npmjs.org/terser/-/terser-4.6.12.tgz",
"integrity": "sha512-fnIwuaKjFPANG6MAixC/k1TDtnl1YlPLUlLVIxxGZUn1gfUx2+l3/zGNB72wya+lgsb50QBi2tUV75RiODwnww==",
"version": "4.6.13",
"resolved": "https://registry.npmjs.org/terser/-/terser-4.6.13.tgz",
"integrity": "sha512-wMvqukYgVpQlymbnNbabVZbtM6PN63AzqexpwJL8tbh/mRT9LE5o+ruVduAGL7D6Fpjl+Q+06U5I9Ul82odAhw==",
"dev": true,
"requires": {
"commander": "^2.20.0",
@ -14931,9 +14959,9 @@
"integrity": "sha512-wpk/drIkPf6gHCtvHc8zAZ1nsWBZ+/OOJYtJxqhYD6CKT0FJAG5oypwgF9kABt30FBWhl8NEb/QY+vaaBARlFg=="
},
"vue-loader": {
"version": "15.9.1",
"resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-15.9.1.tgz",
"integrity": "sha512-IaPU2KOPjs/QjMlxFs/TiTtQUSbftQ7lsAvoxe21rtcQohsMhx+1AltXCNhZIpIn46PtODiAgz+o8RbMpKtmJw==",
"version": "15.9.2",
"resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-15.9.2.tgz",
"integrity": "sha512-oXBubaY//CYEISBlHX+c2YPJbmOH68xXPXjFv4MAgPqQvUsnjrBAjCJi8HXZ/r/yfn0tPL5VZj1Zcp8mJPI8VA==",
"dev": true,
"requires": {
"@vue/component-compiler-utils": "^3.1.0",

View File

@ -163,7 +163,7 @@
"babel-minify-webpack-plugin": "^0.3.1",
"babel-preset-minify": "^0.5.1",
"browserslist": "^4.12.0",
"cfonts": "^2.8.1",
"cfonts": "^2.8.2",
"chalk": "^4.0.0",
"changelog-parser": "^2.8.0",
"copy-webpack-plugin": "^5.1.1",
@ -189,7 +189,7 @@
"friendly-errors-webpack-plugin": "^1.7.0",
"html-webpack-plugin": "^4.3.0",
"less": "^3.11.1",
"less-loader": "^6.0.0",
"less-loader": "^6.1.0",
"markdown-it": "^10.0.0",
"mini-css-extract-plugin": "^0.9.0",
"optimize-css-assets-webpack-plugin": "^5.0.3",
@ -203,9 +203,9 @@
"spinnies": "^0.5.1",
"stylus": "^0.54.7",
"stylus-loader": "^3.0.2",
"terser-webpack-plugin": "^2.3.6",
"terser-webpack-plugin": "^3.0.1",
"url-loader": "^4.1.0",
"vue-loader": "^15.9.1",
"vue-loader": "^15.9.2",
"vue-style-loader": "^4.1.2",
"vue-template-compiler": "^2.6.11",
"webpack": "^4.43.0",
@ -217,7 +217,7 @@
"dependencies": {
"crypto-js": "^4.0.0",
"dnscache": "^1.0.2",
"electron-log": "^4.1.1",
"electron-log": "^4.1.2",
"electron-store": "^5.1.1",
"electron-updater": "^4.3.1",
"image-size": "^0.8.3",

View File

@ -1,6 +1,7 @@
### 新增
- 新增`rpm`、`pacman`包的打包
- 新增所选音频输出设备被移除时是否暂停播放的设置,默认关闭
### 修复

View File

@ -135,11 +135,13 @@ export default {
this.setVolume(volume)
}, 300)
navigator.mediaDevices.addEventListener('devicechange', this.handleMediaListChange)
document.addEventListener('mousemove', this.handleVolumeMsMove)
document.addEventListener('mouseup', this.handleVolumeMsUp)
window.addEventListener('resize', this.handleResize)
},
beforeDestroy() {
navigator.mediaDevices.removeEventListener('devicechange', this.handleMediaListChange)
document.removeEventListener('mousemove', this.handleVolumeMsMove)
document.removeEventListener('mouseup', this.handleVolumeMsUp)
window.removeEventListener('resize', this.handleResize)
@ -479,6 +481,7 @@ export default {
return this.getUrl({ musicInfo: targetSong, type, isRefresh }).then(() => {
this.audio.src = this.musicInfo.url = targetSong.typeUrl[type]
}).catch(err => {
// console.log('err', err.message)
if (err.message == requestMsg.cancelRequest) return
if (!isRetryed) return this.setUrl(targetSong, isRefresh, true)
this.status = this.statusText = err.message
@ -617,16 +620,28 @@ export default {
},
async setMediaDevice() {
let mediaDeviceId = this.setting.player.mediaDeviceId
const devices = await navigator.mediaDevices.enumerateDevices()
let device = devices.find(device => device.deviceId === mediaDeviceId)
const deviceId = device ? device.deviceId : 'default'
if (mediaDeviceId != 'default') {
const devices = await navigator.mediaDevices.enumerateDevices()
let device = devices.find(device => device.deviceId === mediaDeviceId)
mediaDeviceId = device ? device.deviceId : 'default'
}
// console.log(device)
this.audio.setSinkId(deviceId).catch(err => {
this.audio.setSinkId(mediaDeviceId).catch(err => {
console.log(err)
this.setMediaDeviceId('default')
})
},
async handleMediaListChange() {
let mediaDeviceId = this.setting.player.mediaDeviceId
const devices = await navigator.mediaDevices.enumerateDevices()
let device = devices.find(device => device.deviceId === mediaDeviceId)
if (device) return
// console.log(device)
this.setMediaDeviceId('default')
console.log(this.setting.player.isMediaDeviceRemovedStopPlay, this.isPlay)
if (this.setting.player.isMediaDeviceRemovedStopPlay && this.isPlay) this.togglePlay()
},
handlePlayDetailAction({ type, data }) {
switch (type) {
case 'prev':

View File

@ -38,8 +38,8 @@
"play_task_bar": "任务栏播放进度条",
"play_mediaDevice_title": "选择声音输出的媒体设备",
"play_mediaDevice": "音频输出",
"play_mediaDevice_refresh_btn_title": "刷新音频设备列表",
"play_mediaDevice_refresh_btn": "刷新",
"play_mediaDevice_remove_stop_play": "所选音频输出设备被移除时是否暂停播放",
"play_mediaDevice_remove_stop_play_title": "所选的声音输出设备被移除时是否暂停播放歌曲",
"search": "搜索设置",
"search_hot_title": "是否显示热门搜索",

View File

@ -37,8 +37,8 @@
"play_task_bar": "任務欄播放進度條",
"play_mediaDevice_title": "選擇聲音輸出的媒體設備",
"play_mediaDevice": "音頻輸出",
"play_mediaDevice_refresh_btn_title": "刷新音頻設備列表",
"play_mediaDevice_refresh_btn": "刷新",
"play_mediaDevice_remove_stop_play": "所選音頻輸出設備被移除時是否暫停播放",
"play_mediaDevice_remove_stop_play_title": "所選的聲音輸出設備被移除時是否暫停播放歌曲",
"search": "搜索設置",
"search_hot_title": "是否顯示熱門搜索",
"search_hot": "熱門搜索",

View File

@ -38,8 +38,8 @@
"play_task_bar": "Taskbar play progress bar",
"play_mediaDevice_title": "Select a media device for audio output",
"play_mediaDevice": "Audio output",
"play_mediaDevice_refresh_btn_title": "Refresh audio device list",
"play_mediaDevice_refresh_btn": "Refresh",
"play_mediaDevice_remove_stop_play": "Whether to pause playback when the selected audio output device is removed",
"play_mediaDevice_remove_stop_play_title": "Whether to pause the song when the selected sound output device is removed",
"search": "Search",
"search_hot_title": "Select whether to show popular searches",

View File

@ -36,26 +36,32 @@ const actions = {
urlRequest = music[musicInfo.source].getMusicUrl(musicInfo, type)
return urlRequest.promise.then(result => {
commit('setUrl', { musicInfo, url: result.url, type })
}).finally(() => {
urlRequest = null
}).catch(err => {
urlRequest = null
return Promise.reject(err)
})
},
getPic({ commit, state }, musicInfo) {
if (picRequest && picRequest.cancelHttp) picRequest.cancelHttp()
picRequest = music[musicInfo.source].getPic(musicInfo)
return picRequest.promise.then(url => {
commit('getPic', { musicInfo, url })
}).finally(() => {
picRequest = null
commit('getPic', { musicInfo, url })
}).catch(err => {
picRequest = null
return Promise.reject(err)
})
},
getLrc({ commit, state }, musicInfo) {
if (lrcRequest && lrcRequest.cancelHttp) lrcRequest.cancelHttp()
lrcRequest = music[musicInfo.source].getLyric(musicInfo)
return lrcRequest.promise.then(lrc => {
commit('setLrc', { musicInfo, lrc })
}).finally(() => {
lrcRequest = null
commit('setLrc', { musicInfo, lrc })
}).catch(err => {
lrcRequest = null
return Promise.reject(err)
})
},
}

View File

@ -184,7 +184,7 @@ export const objectDeepMerge = (target, source) => {
* @param {*} setting
*/
export const updateSetting = (setting, version) => {
const defaultVersion = '1.0.23'
const defaultVersion = '1.0.24'
if (!version) {
if (setting) {
version = setting.version
@ -198,6 +198,7 @@ export const updateSetting = (setting, version) => {
isShowTaskProgess: true,
volume: 1,
mediaDeviceId: 'default',
isMediaDeviceRemovedStopPlay: false,
},
list: {
isShowAlbumName: true,

View File

@ -1,6 +1,7 @@
export const requestMsg = {
fail: '请求异常😮,可以多试几次,若还是不行就换一首吧。。。',
unachievable: '哦No😱...接口无法访问了!',
timeout: '请求超时',
// unachievable: '哦No😱...接口无法访问了!已帮你切换到临时接口,重试下看能不能播放吧~',
notConnectNetwork: '无法连接到服务器',
cancelRequest: '取消http请求',

View File

@ -46,44 +46,34 @@ const defaultHeaders = {
* @param {*} options
*/
const buildHttpPromose = (url, options) => {
let requestObj
let cancelFn
let isCancelled = false
let p = new Promise((resolve, reject) => {
cancelFn = reject
let obj = {
isCancelled: false,
}
obj.promise = new Promise((resolve, reject) => {
obj.cancelFn = reject
debugRequest && console.log(`\n---send request------${url}------------`)
fetchData(url, options.method, options, (err, resp, body) => {
// options.isShowProgress && window.api.hideProgress()
debugRequest && console.log(`\n---response------${url}------------`)
debugRequest && console.log(body)
requestObj = null
cancelFn = null
if (err) {
// console.log('出错', err.code)
if (err.code === 'ETIMEDOUT' || err.code == 'ESOCKETTIMEDOUT') {
const { promise, cancelHttp } = httpFetch(url, options)
obj.cancelHttp = cancelHttp
promise.then(resp => resolve(resp)).catch(err => reject(err))
return
}
return reject(err)
}
obj.requestObj = null
obj.cancelFn = null
if (err) return reject(err)
resolve(resp)
}).then(ro => {
requestObj = ro
if (isCancelled) obj.cancelHttp()
obj.requestObj = ro
if (obj.isCancelled) obj.cancelHttp()
console.log(obj.requestObj, obj.isCancelled)
})
})
const obj = {
promise: p,
cancelHttp() {
if (!requestObj) return isCancelled = true
cancelFn(new Error(requestMsg.cancelRequest))
cancelHttp(requestObj)
requestObj = null
cancelFn = null
p = null
},
obj.cancelHttp = () => {
console.log('cancel: ', obj)
if (!obj.requestObj) return obj.isCancelled = true
obj.cancelFn(new Error(requestMsg.cancelRequest))
cancelHttp(obj.requestObj)
obj.requestObj = null
obj.cancelFn = null
obj.promise = obj.cancelHttp = null
}
return obj
}
@ -96,19 +86,22 @@ const buildHttpPromose = (url, options) => {
export const httpFetch = (url, options = { method: 'get' }) => {
const requestObj = buildHttpPromose(url, options)
requestObj.promise = requestObj.promise.catch(err => {
if (err.code === 'ETIMEDOUT' || err.code == 'ESOCKETTIMEDOUT') {
const { promise, cancelHttp } = httpFetch(url, options)
requestObj.cancelHttp()
requestObj.cancelHttp = cancelHttp
return promise
}
console.log('出错', err)
if (err.message === 'socket hang up') {
// window.globalObj.apiSource = 'temp'
return Promise.reject(new Error(requestMsg.unachievable))
}
if (err.code === 'ENOTFOUND') return Promise.reject(new Error(requestMsg.notConnectNetwork))
return Promise.reject(err)
switch (err.code) {
case 'ETIMEDOUT':
case 'ESOCKETTIMEDOUT':
return Promise.reject(new Error(requestMsg.timeout))
case 'ENOTFOUND':
return Promise.reject(new Error(requestMsg.notConnectNetwork))
default:
return Promise.reject(err)
}
})
console.log(requestObj)
return requestObj
}
@ -117,6 +110,7 @@ export const httpFetch = (url, options = { method: 'get' }) => {
* @param {*} index
*/
export const cancelHttp = requestObj => {
console.log(requestObj)
if (!requestObj) return
console.log('cancel:', requestObj.href)
requestObj.abort()

View File

@ -60,14 +60,14 @@ div.scroll(:class="$style.setting")
h3 {{$t('view.setting.play_task_bar')}}
div
material-checkbox(id="setting_player_showTaskProgess" v-model="current_setting.player.isShowTaskProgess" :label="$t('view.setting.is_enable')")
dd(:title="$t('view.setting.play_mediaDevice_remove_stop_play_title')")
h3 {{$t('view.setting.play_mediaDevice_remove_stop_play')}}
div
material-checkbox(id="setting_player_isMediaDeviceRemovedStopPlay" v-model="current_setting.player.isMediaDeviceRemovedStopPlay" :label="$t('view.setting.is_enable')")
dd(:title="$t('view.setting.play_mediaDevice_title')")
h3 {{$t('view.setting.play_mediaDevice')}}
div
material-selection(:list="mediaDevices" :class="$style.gapLeft" v-model="current_setting.player.mediaDeviceId" item-key="deviceId" item-name="label")
material-btn(min :title="$t('view.setting.play_mediaDevice_refresh_btn_title')" :class="[$style.btnMediaDeviceRefresh, $style.gapLeft]" @click="getMediaDevice")
svg(version='1.1' xmlns='http://www.w3.org/2000/svg' xlink='http://www.w3.org/1999/xlink' height='100%' viewBox='0 0 512 512' space='preserve')
use(xlink:href='#icon-refresh')
span {{$t('view.setting.play_mediaDevice_refresh_btn')}}
dt {{$t('view.setting.search')}}
dd(:title="$t('view.setting.search_hot_title')")
@ -318,6 +318,7 @@ export default {
isShowTaskProgess: true,
volume: 1,
mediaDeviceId: 'default',
isMediaDeviceRemovedStopPlay: false,
},
list: {
isShowAlbumName: true,
@ -381,6 +382,9 @@ export default {
'setting.isAgreePact'(n) {
this.current_setting.isAgreePact = n
},
'setting.player.mediaDeviceId'(n) {
this.current_setting.player.mediaDeviceId = n
},
'current_setting.player.isShowTaskProgess'(n) {
if (n) return
this.$nextTick(() => {
@ -392,8 +396,12 @@ export default {
},
},
mounted() {
navigator.mediaDevices.addEventListener('devicechange', this.getMediaDevice)
this.init()
},
beforeDestroy() {
navigator.mediaDevices.removeEventListener('devicechange', this.getMediaDevice)
},
methods: {
...mapMutations(['setSetting', 'setSettingVersion', 'setVersionModalVisible']),
...mapMutations('list', ['setList']),
@ -615,8 +623,6 @@ export default {
async getMediaDevice() {
const devices = await navigator.mediaDevices.enumerateDevices()
let audioDevices = devices.filter(device => device.kind === 'audiooutput')
let currentId = this.current_setting.player.mediaDeviceId
if (!audioDevices.some(device => device.deviceId === currentId)) this.current_setting.player.mediaDeviceId = 'default'
this.mediaDevices = audioDevices
// console.log(this.mediaDevices)
},
@ -760,16 +766,6 @@ export default {
})
}
}
.btn-media-device-refresh {
height: 28px;
line-height: 28px;
padding: 0px 15px;
svg {
width: 1em;
vertical-align: middle;
margin-right: 5px;
}
}
.save-path {
font-size: 12px;