-
Notifications
You must be signed in to change notification settings - Fork 16
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
implement mediaSession controls for better android integration #1
base: master
Are you sure you want to change the base?
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@googlebot I signed it! |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool idea! Do you know what will happen on desktop browsers like chrome on macOS that have navigator.mediaSession
? I am not familiar with this spec at all.
script.js
Outdated
if (navigator.mediaSession) { | ||
|
||
function playAudio() { | ||
var audio = document.createElement('audio'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh good catch. I have added to the pr for all the good style catches. incoming shortly
script.js
Outdated
|
||
function playAudio() { | ||
var audio = document.createElement('audio'); | ||
audio.src = './silence.mp3'; // silence must be at least 5 seconds https://freesound.org/people/silentspeaker/sounds/426895/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand what this is and why it's needed. Do you have a link to a reference or the spec?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://developers.google.com/web/updates/2017/02/media-session#implementation_notes
see point 5. specifically
As the Web Audio API doesn't request Android Audio Focus for historical reasons, the only way to make it work with the Media Session API is to hook up an element as the input source to the Web Audio API. Hopefully, the proposed Web AudioFocus API will improve the situation in the near future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, then can you leave that sentence and the link as a comment, please?
script.js
Outdated
audio.src = './silence.mp3'; // silence must be at least 5 seconds https://freesound.org/people/silentspeaker/sounds/426895/ | ||
|
||
// to keep the controls open, must loop the silence | ||
audio.addEventListener('ended', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
() =>
script.js
Outdated
audio.play().then(_ => { | ||
let playing = true; | ||
navigator.mediaSession.setActionHandler('play', function() { | ||
audio.play() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
semicolons everywhere, () =>
ok, here is a cleaned up commit. Style issues addressed, and comments added. Let me know if this works. Thanks! mediaSession is experimental, so really mainly for Android. see https://caniuse.com/#search=mediaSession Chrome on macos pretty much does nothing. |
It would be amazing if I could pause and do next track with my bluetooth controls with listen-to-transformer. I have tested the mediaSession api, and it easily supports this.
https://googlechrome.github.io/samples/media-session/audio.html
This pull request adds mediaSession controls.
One issue is that the mediaSession api only works on audio tags currently. Understanding the following