feat: Added output devices selection | 增加输出设备选择

Added output devices selection | 增加输出设备选择
master
qier222 4 years ago committed by GitHub
commit aaa68c5808
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -118,6 +118,7 @@ export default {
high: "High", high: "High",
lossless: "Lossless", lossless: "Lossless",
}, },
deviceSelector: "Audio Output Device",
appearance: { appearance: {
text: "Appearance", text: "Appearance",
auto: "Auto", auto: "Auto",

@ -119,6 +119,7 @@ export default {
high: "极高", high: "极高",
lossless: "无损", lossless: "无损",
}, },
deviceSelector: "音频输出设备",
appearance: { appearance: {
text: "外观", text: "外观",
auto: "自动", auto: "自动",

@ -7,6 +7,7 @@ let localStorage = {
lang: null, lang: null,
appearance: "auto", appearance: "auto",
musicQuality: 320000, musicQuality: 320000,
outputDevice: "default",
showGithubIcon: true, showGithubIcon: true,
showPlaylistsByAppleMusic: true, showPlaylistsByAppleMusic: true,
showUnavailableSongInGreyStyle: true, showUnavailableSongInGreyStyle: true,

@ -9,6 +9,9 @@ export default {
changeMusicQuality(state, value) { changeMusicQuality(state, value) {
state.settings.musicQuality = value; state.settings.musicQuality = value;
}, },
changeOutputDevice(state, deviceId) {
state.settings.outputDevice = deviceId;
},
updateSettings(state, { key, value }) { updateSettings(state, { key, value }) {
state.settings[key] = value; state.settings[key] = value;
}, },

@ -102,6 +102,8 @@ export default class {
_init() { _init() {
Howler.autoUnlock = false; Howler.autoUnlock = false;
Howler.usingWebAudio = true;
Howler.masterGain = true;
this._loadSelfFromLocalStorage(); this._loadSelfFromLocalStorage();
this._replaceCurrentTrack(this._currentTrack.id, false).then(() => { this._replaceCurrentTrack(this._currentTrack.id, false).then(() => {
this._howler.seek(localStorage.getItem("playerCurrentTrackTime") ?? 0); this._howler.seek(localStorage.getItem("playerCurrentTrackTime") ?? 0);
@ -161,6 +163,7 @@ export default class {
this.play(); this.play();
document.title = `${this._currentTrack.name} · ${this._currentTrack.ar[0].name} - YesPlayMusic`; document.title = `${this._currentTrack.name} · ${this._currentTrack.ar[0].name} - YesPlayMusic`;
} }
this.setOutputDevice();
this._howler.once("end", () => { this._howler.once("end", () => {
this._nextTrackCallback(); this._nextTrackCallback();
}); });
@ -254,6 +257,9 @@ export default class {
navigator.mediaSession.setActionHandler("stop", () => { navigator.mediaSession.setActionHandler("stop", () => {
this.pause(); this.pause();
}); });
navigator.mediaSession.setActionHandler("seekto", (event) => {
this.seek(event.seekTime);
});
} }
} }
_updateMediaSessionMetaData(track) { _updateMediaSessionMetaData(track) {
@ -340,6 +346,10 @@ export default class {
this.volume = 0; this.volume = 0;
} }
} }
setOutputDevice() {
if (this._howler._sounds.length <= 0) return;
this._howler._sounds[0]._node.setSinkId(store.state.settings.outputDevice);
}
replacePlaylist( replacePlaylist(
trackIDs, trackIDs,

@ -345,10 +345,19 @@ export default {
); );
}, },
filteredTracks() { filteredTracks() {
return this.tracks.filter(song => return this.tracks.filter(
song.name.toLowerCase().includes(this.playlistKeyword.toLowerCase()) || (song) =>
song.al.name.toLowerCase().includes(this.playlistKeyword.toLowerCase()) || song.name
song.ar.find(artist => artist.name.toLowerCase().includes(this.playlistKeyword.toLowerCase())) .toLowerCase()
.includes(this.playlistKeyword.toLowerCase()) ||
song.al.name
.toLowerCase()
.includes(this.playlistKeyword.toLowerCase()) ||
song.ar.find((artist) =>
artist.name
.toLowerCase()
.includes(this.playlistKeyword.toLowerCase())
)
); );
}, },
}, },
@ -397,7 +406,11 @@ export default {
this.lastLoadedTrackIndex = data.playlist.tracks.length - 1; this.lastLoadedTrackIndex = data.playlist.tracks.length - 1;
if (this.playlist.trackCount > this.tracks.length) { if (this.playlist.trackCount > this.tracks.length) {
window.addEventListener("scroll", this.handleScroll, true); window.addEventListener("scroll", this.handleScroll, true);
window.addEventListener("input", this.handleSearch, this.playlistKeyword); window.addEventListener(
"input",
this.handleSearch,
this.playlistKeyword
);
} }
return data; return data;
}) })
@ -549,17 +562,14 @@ export default {
.playlist-info { .playlist-info {
width: calc(100vw - 2 * var(--main-content-padding-x)); width: calc(100vw - 2 * var(--main-content-padding-x));
display: block; display: block;
.cover { .cover {
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
} }
.info { .info {
margin-top: 24px; margin-top: 24px;
margin-left: 0; margin-left: 0;
.title { .title {
font-size: 48px; font-size: 48px;
} }

@ -74,6 +74,23 @@
</select> </select>
</div> </div>
</div> </div>
<div class="item">
<div class="left">
<div class="title"> {{ $t("settings.deviceSelector") }} </div>
</div>
<div class="right">
<select v-model="outputDevice">
<option
v-for="device in allOutputDevices"
:key="device.deviceId"
:value="device.deviceId"
:selected="device.deviceId == outputDevice"
>
{{ device.label }}
</option>
</select>
</div>
</div>
<div class="item"> <div class="item">
<div class="left"> <div class="left">
<div class="title"> <div class="title">
@ -227,10 +244,11 @@ export default {
size: "0KB", size: "0KB",
length: 0, length: 0,
}, },
allOutputDevices: [],
}; };
}, },
computed: { computed: {
...mapState(["settings", "data"]), ...mapState(["player", "settings", "data"]),
isElectron() { isElectron() {
return process.env.IS_ELECTRON; return process.env.IS_ELECTRON;
}, },
@ -270,6 +288,26 @@ export default {
this.clearCache("tracks"); this.clearCache("tracks");
}, },
}, },
outputDevice: {
get() {
if (this.allOutputDevices.length == 0) this.getAllOutputDevices(); // Ensure devices loaded before get
const isValidDevice = this.allOutputDevices.find(
(device) => device.deviceId === this.settings.outputDevice
);
if (
this.settings.outputDevice === undefined ||
isValidDevice === undefined
)
return "default"; // Default deviceId
return this.settings.outputDevice;
},
set(deviceId) {
if (deviceId === this.settings.outputDevice || deviceId === undefined)
return;
this.$store.commit("changeOutputDevice", deviceId);
this.player.setOutputDevice();
},
},
showGithubIcon: { showGithubIcon: {
get() { get() {
if (this.settings.showGithubIcon === undefined) return true; if (this.settings.showGithubIcon === undefined) return true;
@ -356,6 +394,16 @@ export default {
}, },
}, },
methods: { methods: {
getAllOutputDevices() {
return navigator.mediaDevices
.enumerateDevices()
.then(
(devices) =>
(this.allOutputDevices = devices.filter(
(device) => device.kind == "audiooutput"
))
);
},
logout() { logout() {
doLogout(); doLogout();
this.$router.push({ name: "home" }); this.$router.push({ name: "home" });

Loading…
Cancel
Save