Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: media button support #2373

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: replace unformatted quotation marks
  • Loading branch information
scarletborder committed Feb 18, 2025
commit 4bc8432db42c003ddda7ff7662821a943efec146
20 changes: 10 additions & 10 deletions src/components/Player.vue
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ export default {
},
mounted() {
this.setupMediaControls();
window.addEventListener("keydown", this.handleKeydown);
window.addEventListener('keydown', this.handleKeydown);
},
beforeDestroy() {
window.removeEventListener("keydown", this.handleKeydown);
window.removeEventListener('keydown', this.handleKeydown);
},
methods: {
...mapMutations(['toggleLyrics']),
Expand Down Expand Up @@ -279,31 +279,31 @@ export default {
},

setupMediaControls() {
if ("mediaSession" in navigator) {
navigator.mediaSession.setActionHandler("play", () => {
if ('mediaSession' in navigator) {
navigator.mediaSession.setActionHandler('play', () => {
this.playOrPause();
});
navigator.mediaSession.setActionHandler("pause", () => {
navigator.mediaSession.setActionHandler('pause', () => {
this.playOrPause();
});
navigator.mediaSession.setActionHandler("previoustrack", () => {
navigator.mediaSession.setActionHandler('previoustrack', () => {
this.playPrevTrack();
});
navigator.mediaSession.setActionHandler("nexttrack", () => {
navigator.mediaSession.setActionHandler('nexttrack', () => {
this.playNextTrack();
});
}
},

handleKeydown(event) {
switch (event.code) {
case "MediaPlayPause":
case 'MediaPlayPause':
this.playOrPause();
break;
case "MediaTrackPrevious":
case 'MediaTrackPrevious':
this.playPrevTrack();
break;
case "MediaTrackNext":
case 'MediaTrackNext':
this.playNextTrack();
break;
default:
Expand Down