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: Add mediasession support #8309

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

mister-ben
Copy link
Contributor

@mister-ben mister-ben commented Jun 4, 2023

Description

Adds built-in, opt-in support for populating mediasession metadata and setting action handlers

Specific Changes proposed

  • Enabled with a truthy mediaSession player setup option. Since implementors may be using the API, not on by default. Possibly this could be made default in a major version.
  • mediaSession.skipTime (seconds) will override the default skip interval (if the browser/os doesn't request a time)
  • Supports getting metadata from getMedia() (if loadMedia() has been used) or from playlist metadata.
  • Adds a player event updatemetadata with the resolved metadata object as its second argument. The metadata can be modified synchronously if needed, i.e. there is another source of truth for metadata.
  • Guards against actions during ads, assuming a contrib-ads-based implementation.

Requirements Checklist

  • Feature implemented / Bug fixed
  • If necessary, more likely in a feature request than a bug fix
    • Change has been verified in an actual browser (Chrome, Firefox, IE)
    • Unit Tests updated or fixed
    • Docs/guides updated
    • Example created (starter template on JSBin)
  • Reviewed by Two Core Contributors

@codecov
Copy link

codecov bot commented Jun 4, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (a6a0f57) 82.72% compared to head (43536f0) 82.69%.
Report is 6 commits behind head on main.

❗ Current head 43536f0 differs from pull request most recent head b249c67. Consider uploading reports for the commit b249c67 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8309      +/-   ##
==========================================
- Coverage   82.72%   82.69%   -0.04%     
==========================================
  Files         113      113              
  Lines        7594     7563      -31     
  Branches     1827     1826       -1     
==========================================
- Hits         6282     6254      -28     
+ Misses       1312     1309       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/js/mediasession.js Outdated Show resolved Hide resolved
position: 5
}), 'setPositionState called');

this.player.trigger('paused');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Referring to my comment above:

Shouldn't it be pause instead of paused ?

};

const updatePositionState = () => {
const dur = parseFloat(this.duration());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question, is there a case that requires a parseFloat?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That can probably go

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a specification perspective (w3c, whatwg), it seems safe to remove the parseFloat, especially as the condition immediately following it prevents any NaN or Infinity. However, if you prefer to keep it, that's fine too.

return;
}
const ms = window.navigator.mediaSession;
const defaultSkipTime = 15;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question, do you think it would be a good idea to use skipButtons values if they are available? This would allow a unified experience between the player and the mediaSession.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that makes sense, yes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about keeping this property as it is for now and adding this modification via another PR? Because it would be nice to have the titleBar values as well.

@amtins
Copy link
Contributor

amtins commented Dec 10, 2023

@mister-ben everything works well, except for the minor issue related to the pause event.

I found a small issue in videojs-playlist that prevents the artwork to be set, this means that when the next media is played, the poster is not displayed.

@mister-ben
Copy link
Contributor Author

@mister-ben everything works well, except for the minor issue related to the pause event.

I found a small issue in videojs-playlist that prevents the artwork to be set, this means that when the next media is played, the poster is not displayed.

Thanks for reviewing! I think there may be a PR that would fix that issue, need to check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants