{"action":"created","comment":{"url":"https://api.github.com/repos/ampproject/amphtml/pulls/comments/130425878","pull_request_review_id":53298020,"id":130425878,"diff_hunk":"@@ -0,0 +1,124 @@\n+/**\n+ * Copyright 2017 The AMP HTML Authors. All Rights Reserved.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *      http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS-IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+import {tryParseJson} from './json';\n+\n+/**\n+ * Updates the Media Session API's metadata\n+ * @param {!./ampdoc-impl.AmpDoc} ampdoc\n+ * @param {!./video-interface.VideoMetaDef} metaData\n+ * @param {function} playHandler\n+ * @param {function} pauseHandler\n+ */\n+export function setMediaSession(ampdoc,\n+                                metaData,\n+                                playHandler = null,\n+                                pauseHandler = null) {\n+  const win = ampdoc.win;\n+  const navigator = win.navigator;\n+  if ('mediaSession' in navigator && win.MediaMetadata) {\n+    // Clear mediaSession (required to fix a bug when switching between two\n+    // videos)\n+    navigator.mediaSession.metadata = new win.MediaMetadata({\n+      title: '',\n+      artist: '',\n+      album: '',\n+      artwork: [\n+        { src: ''},\n+      ]\n+    });\n+    // Add metaData\n+    navigator.mediaSession.metadata = new win.MediaMetadata(metaData);\n+\n+    navigator.mediaSession.setActionHandler('play', playHandler);\n+    navigator.mediaSession.setActionHandler('pause', pauseHandler);\n+\n+    // TODO(@wassgha) Implement seek & next/previous\n+  }\n+}\n+\n+\n+/**\n+ * Parses the schema.org json-ld formatted meta-data, looks for the page's\n+ * featured image and returns it\n+ * @param {!./ampdoc-impl.AmpDoc} ampdoc\n+ * @return {string|undefined}\n+ */\n+export function parseSchemaImage(ampdoc) {\n+  const doc = ampdoc.win.document;\n+  const schema = doc.querySelector('script[type=\"application/ld+json\"]');\n+  if (!schema) {\n+    // No schema element found\n+    return undefined;","path":"src/mediasession-helper.js","position":65,"original_position":65,"commit_id":"81741d0618d39788eaf86c94b004eb0e274d8988","original_commit_id":"81741d0618d39788eaf86c94b004eb0e274d8988","user":{"login":"aghassemi","id":2099009,"avatar_url":"https://avatars3.githubusercontent.com/u/2099009?v=4","gravatar_id":"","url":"https://api.github.com/users/aghassemi","html_url":"https://github.com/aghassemi","followers_url":"https://api.github.com/users/aghassemi/followers","following_url":"https://api.github.com/users/aghassemi/following{/other_user}","gists_url":"https://api.github.com/users/aghassemi/gists{/gist_id}","starred_url":"https://api.github.com/users/aghassemi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aghassemi/subscriptions","organizations_url":"https://api.github.com/users/aghassemi/orgs","repos_url":"https://api.github.com/users/aghassemi/repos","events_url":"https://api.github.com/users/aghassemi/events{/privacy}","received_events_url":"https://api.github.com/users/aghassemi/received_events","type":"User","site_admin":false},"body":"nit: just `return;`","created_at":"2017-07-31T18:35:01Z","updated_at":"2017-07-31T18:51:32Z","html_url":"https://github.com/ampproject/amphtml/pull/10476#discussion_r130425878","pull_request_url":"https://api.github.com/repos/ampproject/amphtml/pulls/10476","_links":{"self":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/comments/130425878"},"html":{"href":"https://github.com/ampproject/amphtml/pull/10476#discussion_r130425878"},"pull_request":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/10476"}}},"pull_request":{"url":"https://api.github.com/repos/ampproject/amphtml/pulls/10476","id":130921803,"html_url":"https://github.com/ampproject/amphtml/pull/10476","diff_url":"https://github.com/ampproject/amphtml/pull/10476.diff","patch_url":"https://github.com/ampproject/amphtml/pull/10476.patch","issue_url":"https://api.github.com/repos/ampproject/amphtml/issues/10476","number":10476,"state":"open","locked":false,"title":"Implemented Media Session API for video components","user":{"login":"wassgha","id":591655,"avatar_url":"https://avatars3.githubusercontent.com/u/591655?v=4","gravatar_id":"","url":"https://api.github.com/users/wassgha","html_url":"https://github.com/wassgha","followers_url":"https://api.github.com/users/wassgha/followers","following_url":"https://api.github.com/users/wassgha/following{/other_user}","gists_url":"https://api.github.com/users/wassgha/gists{/gist_id}","starred_url":"https://api.github.com/users/wassgha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wassgha/subscriptions","organizations_url":"https://api.github.com/users/wassgha/orgs","repos_url":"https://api.github.com/users/wassgha/repos","events_url":"https://api.github.com/users/wassgha/events{/privacy}","received_events_url":"https://api.github.com/users/wassgha/received_events","type":"User","site_admin":false},"body":"<div align=\"center\"><img src=\"http://www.androidpolice.com/wp-content/uploads/2017/02/nexus2cee_Screenshot_20170204-132854.png\" height=\"300px\" /></div><br>\r\n\r\nThis implements the Media Session API inside the video manager as described in #7272\r\n\r\n### Changes\r\n- Added a new variable that players implementing the `video-interface` should expose : `metaData` which contains `posterUrl` (512x512 png image), `title`, `album`, `artist`.\r\n- Implemented guessing logic to fill in missing information from `metaData` (see to-do)\r\n- Update Media Session using gathered and guessed `metaData` when the video loads as well as when the video starts playing (so that we override the media session when switching between videos on the same page)\r\n- Added opt-out method `preimplementsMediaSession` for players already implementing the Media Session API (`amp-youtube` for example) so that we don't override their implementation\r\n- Implemented the `preimplementsMediaSession` on `amp-youtube` to opt-out\r\n- Added multiple parsers for album artwork in this order:\r\n\r\n> 1. `poster` attribute\r\n> 3. `schema` for NewsArticle usually contains a thumbnail\r\n> 4. `meta` images (`og:image` in particular if available)\r\n> 5. `favicon`\r\n\r\nDeciding whether these other sources might be useful:\r\n\r\n> 6. First image in the body of the document\r\n> 7. first frame of the video\r\n\r\n\r\n### Excluded players list\r\nList of video players that have a good implementation of the Media Session API already built-in.\r\n- `amp-vimeo`\r\n- `amp-youtube`\r\n\r\n### To-do\r\n- Determine which players may benefit from an opt-out like `amp-youtube`\r\n- Implement seek/next/previous track\r\n\r\nCloses #7272 , Checks off an item on #4154","created_at":"2017-07-17T18:34:33Z","updated_at":"2017-07-31T18:51:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b0e946ddc7d8b8a59c7833d44263e63df12d5b10","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/ampproject/amphtml/pulls/10476/commits","review_comments_url":"https://api.github.com/repos/ampproject/amphtml/pulls/10476/comments","review_comment_url":"https://api.github.com/repos/ampproject/amphtml/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ampproject/amphtml/issues/10476/comments","statuses_url":"https://api.github.com/repos/ampproject/amphtml/statuses/81741d0618d39788eaf86c94b004eb0e274d8988","head":{"label":"wassgha:media-session","ref":"media-session","sha":"81741d0618d39788eaf86c94b004eb0e274d8988","user":{"login":"wassgha","id":591655,"avatar_url":"https://avatars3.githubusercontent.com/u/591655?v=4","gravatar_id":"","url":"https://api.github.com/users/wassgha","html_url":"https://github.com/wassgha","followers_url":"https://api.github.com/users/wassgha/followers","following_url":"https://api.github.com/users/wassgha/following{/other_user}","gists_url":"https://api.github.com/users/wassgha/gists{/gist_id}","starred_url":"https://api.github.com/users/wassgha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wassgha/subscriptions","organizations_url":"https://api.github.com/users/wassgha/orgs","repos_url":"https://api.github.com/users/wassgha/repos","events_url":"https://api.github.com/users/wassgha/events{/privacy}","received_events_url":"https://api.github.com/users/wassgha/received_events","type":"User","site_admin":false},"repo":{"id":92342164,"name":"amphtml","full_name":"wassgha/amphtml","owner":{"login":"wassgha","id":591655,"avatar_url":"https://avatars3.githubusercontent.com/u/591655?v=4","gravatar_id":"","url":"https://api.github.com/users/wassgha","html_url":"https://github.com/wassgha","followers_url":"https://api.github.com/users/wassgha/followers","following_url":"https://api.github.com/users/wassgha/following{/other_user}","gists_url":"https://api.github.com/users/wassgha/gists{/gist_id}","starred_url":"https://api.github.com/users/wassgha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wassgha/subscriptions","organizations_url":"https://api.github.com/users/wassgha/orgs","repos_url":"https://api.github.com/users/wassgha/repos","events_url":"https://api.github.com/users/wassgha/events{/privacy}","received_events_url":"https://api.github.com/users/wassgha/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/wassgha/amphtml","description":"AMP HTML source code, samples, and documentation.  See below for more info.","fork":true,"url":"https://api.github.com/repos/wassgha/amphtml","forks_url":"https://api.github.com/repos/wassgha/amphtml/forks","keys_url":"https://api.github.com/repos/wassgha/amphtml/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wassgha/amphtml/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wassgha/amphtml/teams","hooks_url":"https://api.github.com/repos/wassgha/amphtml/hooks","issue_events_url":"https://api.github.com/repos/wassgha/amphtml/issues/events{/number}","events_url":"https://api.github.com/repos/wassgha/amphtml/events","assignees_url":"https://api.github.com/repos/wassgha/amphtml/assignees{/user}","branches_url":"https://api.github.com/repos/wassgha/amphtml/branches{/branch}","tags_url":"https://api.github.com/repos/wassgha/amphtml/tags","blobs_url":"https://api.github.com/repos/wassgha/amphtml/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wassgha/amphtml/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wassgha/amphtml/git/refs{/sha}","trees_url":"https://api.github.com/repos/wassgha/amphtml/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wassgha/amphtml/statuses/{sha}","languages_url":"https://api.github.com/repos/wassgha/amphtml/languages","stargazers_url":"https://api.github.com/repos/wassgha/amphtml/stargazers","contributors_url":"https://api.github.com/repos/wassgha/amphtml/contributors","subscribers_url":"https://api.github.com/repos/wassgha/amphtml/subscribers","subscription_url":"https://api.github.com/repos/wassgha/amphtml/subscription","commits_url":"https://api.github.com/repos/wassgha/amphtml/commits{/sha}","git_commits_url":"https://api.github.com/repos/wassgha/amphtml/git/commits{/sha}","comments_url":"https://api.github.com/repos/wassgha/amphtml/comments{/number}","issue_comment_url":"https://api.github.com/repos/wassgha/amphtml/issues/comments{/number}","contents_url":"https://api.github.com/repos/wassgha/amphtml/contents/{+path}","compare_url":"https://api.github.com/repos/wassgha/amphtml/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wassgha/amphtml/merges","archive_url":"https://api.github.com/repos/wassgha/amphtml/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wassgha/amphtml/downloads","issues_url":"https://api.github.com/repos/wassgha/amphtml/issues{/number}","pulls_url":"https://api.github.com/repos/wassgha/amphtml/pulls{/number}","milestones_url":"https://api.github.com/repos/wassgha/amphtml/milestones{/number}","notifications_url":"https://api.github.com/repos/wassgha/amphtml/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wassgha/amphtml/labels{/name}","releases_url":"https://api.github.com/repos/wassgha/amphtml/releases{/id}","deployments_url":"https://api.github.com/repos/wassgha/amphtml/deployments","created_at":"2017-05-24T22:32:53Z","updated_at":"2017-05-24T22:33:02Z","pushed_at":"2017-07-31T18:20:09Z","git_url":"git://github.com/wassgha/amphtml.git","ssh_url":"git@github.com:wassgha/amphtml.git","clone_url":"https://github.com/wassgha/amphtml.git","svn_url":"https://github.com/wassgha/amphtml","homepage":"https://www.ampproject.org","size":262733,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"ampproject:master","ref":"master","sha":"1cc2b8b10cb566eac652d43c2db7125bb1c725cb","user":{"login":"ampproject","id":14114390,"avatar_url":"https://avatars3.githubusercontent.com/u/14114390?v=4","gravatar_id":"","url":"https://api.github.com/users/ampproject","html_url":"https://github.com/ampproject","followers_url":"https://api.github.com/users/ampproject/followers","following_url":"https://api.github.com/users/ampproject/following{/other_user}","gists_url":"https://api.github.com/users/ampproject/gists{/gist_id}","starred_url":"https://api.github.com/users/ampproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ampproject/subscriptions","organizations_url":"https://api.github.com/users/ampproject/orgs","repos_url":"https://api.github.com/users/ampproject/repos","events_url":"https://api.github.com/users/ampproject/events{/privacy}","received_events_url":"https://api.github.com/users/ampproject/received_events","type":"Organization","site_admin":false},"repo":{"id":41766002,"name":"amphtml","full_name":"ampproject/amphtml","owner":{"login":"ampproject","id":14114390,"avatar_url":"https://avatars3.githubusercontent.com/u/14114390?v=4","gravatar_id":"","url":"https://api.github.com/users/ampproject","html_url":"https://github.com/ampproject","followers_url":"https://api.github.com/users/ampproject/followers","following_url":"https://api.github.com/users/ampproject/following{/other_user}","gists_url":"https://api.github.com/users/ampproject/gists{/gist_id}","starred_url":"https://api.github.com/users/ampproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ampproject/subscriptions","organizations_url":"https://api.github.com/users/ampproject/orgs","repos_url":"https://api.github.com/users/ampproject/repos","events_url":"https://api.github.com/users/ampproject/events{/privacy}","received_events_url":"https://api.github.com/users/ampproject/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ampproject/amphtml","description":"AMP HTML source code, samples, and documentation.  See below for more info.","fork":false,"url":"https://api.github.com/repos/ampproject/amphtml","forks_url":"https://api.github.com/repos/ampproject/amphtml/forks","keys_url":"https://api.github.com/repos/ampproject/amphtml/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ampproject/amphtml/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ampproject/amphtml/teams","hooks_url":"https://api.github.com/repos/ampproject/amphtml/hooks","issue_events_url":"https://api.github.com/repos/ampproject/amphtml/issues/events{/number}","events_url":"https://api.github.com/repos/ampproject/amphtml/events","assignees_url":"https://api.github.com/repos/ampproject/amphtml/assignees{/user}","branches_url":"https://api.github.com/repos/ampproject/amphtml/branches{/branch}","tags_url":"https://api.github.com/repos/ampproject/amphtml/tags","blobs_url":"https://api.github.com/repos/ampproject/amphtml/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ampproject/amphtml/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ampproject/amphtml/git/refs{/sha}","trees_url":"https://api.github.com/repos/ampproject/amphtml/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ampproject/amphtml/statuses/{sha}","languages_url":"https://api.github.com/repos/ampproject/amphtml/languages","stargazers_url":"https://api.github.com/repos/ampproject/amphtml/stargazers","contributors_url":"https://api.github.com/repos/ampproject/amphtml/contributors","subscribers_url":"https://api.github.com/repos/ampproject/amphtml/subscribers","subscription_url":"https://api.github.com/repos/ampproject/amphtml/subscription","commits_url":"https://api.github.com/repos/ampproject/amphtml/commits{/sha}","git_commits_url":"https://api.github.com/repos/ampproject/amphtml/git/commits{/sha}","comments_url":"https://api.github.com/repos/ampproject/amphtml/comments{/number}","issue_comment_url":"https://api.github.com/repos/ampproject/amphtml/issues/comments{/number}","contents_url":"https://api.github.com/repos/ampproject/amphtml/contents/{+path}","compare_url":"https://api.github.com/repos/ampproject/amphtml/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ampproject/amphtml/merges","archive_url":"https://api.github.com/repos/ampproject/amphtml/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ampproject/amphtml/downloads","issues_url":"https://api.github.com/repos/ampproject/amphtml/issues{/number}","pulls_url":"https://api.github.com/repos/ampproject/amphtml/pulls{/number}","milestones_url":"https://api.github.com/repos/ampproject/amphtml/milestones{/number}","notifications_url":"https://api.github.com/repos/ampproject/amphtml/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ampproject/amphtml/labels{/name}","releases_url":"https://api.github.com/repos/ampproject/amphtml/releases{/id}","deployments_url":"https://api.github.com/repos/ampproject/amphtml/deployments","created_at":"2015-09-01T22:10:53Z","updated_at":"2017-07-31T18:24:16Z","pushed_at":"2017-07-31T18:43:09Z","git_url":"git://github.com/ampproject/amphtml.git","ssh_url":"git@github.com:ampproject/amphtml.git","clone_url":"https://github.com/ampproject/amphtml.git","svn_url":"https://github.com/ampproject/amphtml","homepage":"https://www.ampproject.org","size":257834,"stargazers_count":10332,"watchers_count":10332,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":1854,"mirror_url":null,"open_issues_count":895,"forks":1854,"open_issues":895,"watchers":10332,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/10476"},"html":{"href":"https://github.com/ampproject/amphtml/pull/10476"},"issue":{"href":"https://api.github.com/repos/ampproject/amphtml/issues/10476"},"comments":{"href":"https://api.github.com/repos/ampproject/amphtml/issues/10476/comments"},"review_comments":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/10476/comments"},"review_comment":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/10476/commits"},"statuses":{"href":"https://api.github.com/repos/ampproject/amphtml/statuses/81741d0618d39788eaf86c94b004eb0e274d8988"}}}}
{"actor":{"display_login":"aghassemi"}}