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

Support Media Session title in demo #689

Merged
merged 5 commits into from
Feb 14, 2017

Conversation

beaufortfrancois
Copy link
Contributor

@beaufortfrancois beaufortfrancois commented Feb 9, 2017

With the brand new Media Session API, we can now customize media notifications by providing metadata for the media the web app is playing. It also allows us to handle media related events such as seeking or track changing which may come from notifications or media keys.

So here's a first stab to support the Media Session in the shaka demo.
WDYT?

screenshot_20170209-113048

if (playPromise !== undefined) {
// If video plays successfully, set media session title.
playPromise.then(function() {
navigator.mediaSession.metadata.title = asset.name;

Choose a reason for hiding this comment

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

Would it make sense to have something like:

var playPromise = shakaDemo.video_.play();
if (playPromise !== undefined && 'mediaSession' in navigator) {
  playPromise.then(function() {
    navigator.mediaSession.metadata = new MediaMetadata({ title: asset.name });
  });
}

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 was thinking about future use of the play promise so that people don't have to refactor the Media Session part and could simply add their code when play promise is resolved. Does that make sense?

Choose a reason for hiding this comment

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

Should the play promise check be first then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're absolutely right. I've updated patch.

// Reset the media session.
navigator.mediaSession.metadata = new MediaMetadata();
if (playPromise !== undefined) {
if (playPromise !== undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR! Small nit: we generally avoid using '===' operator in the project unless there's a good reason to have it instead of just '=='.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@beaufortfrancois
Copy link
Contributor Author

@ismena I've addressed your feedback.

@ismena
Copy link
Contributor

ismena commented Feb 10, 2017

@beaufortfrancois Cool, let me run it through our test bot.

@shaka-bot
Copy link
Collaborator

Testing in progress...

@shaka-bot
Copy link
Collaborator

Failure:

+ echo START-BUILD
START-BUILD
+ ./build/all.py
175 files checked, no errors found.

   Config loaded: /var/lib/jenkins/jobs/Manual PR Test (local-tests)/workspace/.htmlhintrc

   Config loaded: /var/lib/jenkins/jobs/Manual PR Test (local-tests)/workspace/.htmlhintrc

   Config loaded: /var/lib/jenkins/jobs/Manual PR Test (local-tests)/workspace/.htmlhintrc

Scanned 3 files, no errors found (23 ms).
/var/lib/jenkins/jobs/Manual PR Test (local-tests)/workspace/demo/asset_section.js:203: ERROR - variable MediaMetadata is undeclared
      navigator.mediaSession.metadata = new MediaMetadata();
                                            ^

1 error(s), 0 warning(s)
Build failed
Generating Closure dependencies...
Running Closure linter...
Running htmlhint...
Checking that the build files are complete...
Checking the tests for type errors...
Build step 'Execute shell' marked build as failure

@TheModMaker
Copy link
Contributor

This is a new API and our compiler doesn't know about the types involved. You will need to add an additional file to the externs folder. Simply copy one of them and modify it to describe the new APIs (you don't need to include everything, just what you use).

You can also run build/all.py to check that it works locally.

@beaufortfrancois
Copy link
Contributor Author

I've added missing externs.js files in aa693a9 but it looks like tests are still failing for the play promise:

Checking the tests for type errors...


./externs/mediaelements.js:29: ERROR - variable HTMLMediaElement.prototype.play redefined, original definition at externs.zip//html5.js:1700
HTMLMediaElement.prototype.play = function() {};
^

1 error(s), 0 warning(s)
Build failed

I'd appreciate some help there.

/**
* @override
*/
HTMLMediaElement.prototype.play = function() {};
Copy link
Contributor

Choose a reason for hiding this comment

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

This file is not needed. This is already known by the compiler (the error is about duplicate definitions).

// If video plays successfully, set media session title.
playPromise.then(function() {
navigator.mediaSession.metadata.title = asset.name;
});
Copy link
Contributor

Choose a reason for hiding this comment

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

How about doing this after player.load() resolves instead?



/**
* @constructor
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace with:

/** @type {MediaMetadata} */
Navigator.prototype.mediaSession;

*/
var MediaMetadata = function() {};


Copy link
Contributor

Choose a reason for hiding this comment

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

You'll need a line like:

/** @type {string} */
MediaMetadata.prototype.title;


/**
* @fileoverview Externs for MediaSession based on
* {@link https://goo.gl/8QS094i Editor's Draft, 12 January 2017}
Copy link
Contributor

Choose a reason for hiding this comment

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

Double check this URL, it doesn't work for me.

@beaufortfrancois
Copy link
Contributor Author

@TheModMaker Done! Thanks ;)

@shaka-bot
Copy link
Collaborator

Testing in progress...

@shaka-bot
Copy link
Collaborator

All tests passed!

@TheModMaker TheModMaker merged commit bab557d into shaka-project:master Feb 14, 2017
@TheModMaker
Copy link
Contributor

Thanks for the PR and thanks for introducing this to us. This will be helpful if we decide to add more UI elements to our demo app.

@beaufortfrancois beaufortfrancois deleted the addMediaSession branch February 15, 2017 09:15
@beaufortfrancois
Copy link
Contributor Author

Yeah! Please let me know when it's live @TheModMaker!

@TheModMaker
Copy link
Contributor

It is already live on the nightly site: https://nightly-dot-shaka-player-demo.appspot.com/demo/. It will appear in the normal demo once we release v2.1.

TheModMaker pushed a commit that referenced this pull request Feb 24, 2017
@github-actions github-actions bot added the status: archived Archived and locked; will not be updated label Jul 25, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: archived Archived and locked; will not be updated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants