Global Hotkeys via Media Session

Open
#285 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
30/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Domain
frontend, web-dev

Research direction

Start with the linked MDN MediaSession documentation and verify browser support, including whether active audio is required. Then locate the application's existing global-hotkey entry point and determine how media actions should connect to it. Done means supported media-key actions reliably invoke the intended handlers.

Written by the indexing model from the issue text.

Description

enhancement needs further discussion / research suitable for contributions

Looks like it is indeed possible to have yet another form of global hotkeys. We can start a media session and pretend we are playing music, at which point the browser will forward any key presses of the media keys on your keyboard (or any other way of pausing, playing, skipping, ... the current song, such as pressing buttons on your headphones) to custom JavaScript code you can execute:

https://developer.mozilla.org/en-US/docs/Web/API/MediaSession

if ('mediaSession' in navigator){
  navigator.mediaSession.metadata = new MediaMetadata({
    title: "Podcast Episode Title",
    artist: "Podcast Host",
    album: "Podcast Name",
    artwork: [{src: "podcast.jpg"}]
  });
  navigator.mediaSession.setActionHandler('play', function() {});
  navigator.mediaSession.setActionHandler('pause', function() {});
  navigator.mediaSession.setActionHandler('seekbackward', function() {});
  navigator.mediaSession.setActionHandler('seekforward', function() {});
  navigator.mediaSession.setActionHandler('previoustrack', function() {});
  navigator.mediaSession.setActionHandler('nexttrack', function() {});
}

Seems like you may need to play some actual audio or so for this to work.

Dominant language
TypeScript
Stars
301
Forks
55
Avg merge
8m
Merged PRs (30d)
1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from LiveSplit/LiveSplitOne

All issues in LiveSplit/LiveSplitOne

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.