chorus2 icon indicating copy to clipboard operation
chorus2 copied to clipboard

Feature Request: Global Media Key Control

Open jwmay2012 opened this issue 3 years ago • 0 comments

Feature suggestion

Capture and forward global media key presses from keyboard to Kodi.

Using chorus UI, select an album/playlist for kodi to play. Play/Pause, Prev/Next, (and maybe volume?) button presses control media playback in Kodi, as if you were controlling a playback app on your computer/browser.

Similar to playback control from Jellyfin/Plex/any_other_browser_media_player.

Use Case / Why? / Context

When I'm at my desk, I can just use the media source directly (Jellyfin) to play music locally and have my media keys control the player.

However, sometimes I want to work with my laptop in the living room where my TV w/Kodi is, so I'm looking for a way to queue up an album/playlist on Kodi and have media keys (play/pause, next/prev, volume) be directed to Kodi.

Possible Implementation

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

Just spent some time tinkering in the console. I have no idea what I'm doing within the scope of your project, but here's a POC.

// Begin playing silent audio. MediaSession API doesn't function unless its playing something
this.audioTag = document.createElement('audio');
document.body.appendChild(this.audioTag);
this.audioTag.src = "https://raw.githubusercontent.com/anars/blank-audio/master/10-seconds-of-silence.mp3";
this.audioTag.loop = true;
this.audioTag.play();

// grab player to send commands and make it global
player = this.Kodi.kodiPlayer;

// set media session api action handlers for play/pause next/prev
navigator.mediaSession.setActionHandler('play', function() { player.triggerMethod("control:play") });
navigator.mediaSession.setActionHandler('pause', function() { player.triggerMethod("control:play") });
navigator.mediaSession.setActionHandler('nexttrack', function() { player.triggerMethod("control:next") });
navigator.mediaSession.setActionHandler('previoustrack', function() { player.triggerMethod("control:prev") });

The Play/Pause next/prev media key now control Kodi.

Thanks for your time.

jwmay2012 avatar May 10 '22 17:05 jwmay2012