| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * @param {Element} playerContainer Main container. | 8 * @param {Element} playerContainer Main container. |
| 9 * @param {Element} videoContainer Container for the video element. | 9 * @param {Element} videoContainer Container for the video element. |
| 10 * @param {Element} controlsContainer Container for video controls. | 10 * @param {Element} controlsContainer Container for video controls. |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 function unload() { | 238 function unload() { |
| 239 if (!player.controls || !player.controls.getMedia()) | 239 if (!player.controls || !player.controls.getMedia()) |
| 240 return; | 240 return; |
| 241 | 241 |
| 242 player.controls.savePosition(true /* exiting */); | 242 player.controls.savePosition(true /* exiting */); |
| 243 player.controls.cleanup(); | 243 player.controls.cleanup(); |
| 244 } | 244 } |
| 245 | 245 |
| 246 /** | 246 /** |
| 247 * Loads the video file. | 247 * Loads the video file. |
| 248 * @param {string} url URL of the video file. | 248 * @param {Object} video Data of the video file. |
| 249 * @param {string} title Title of the video file. | |
| 250 * @param {function()=} opt_callback Completion callback. | 249 * @param {function()=} opt_callback Completion callback. |
| 251 * @private | 250 * @private |
| 252 */ | 251 */ |
| 253 VideoPlayer.prototype.loadVideo_ = function(url, title, opt_callback) { | 252 VideoPlayer.prototype.loadVideo_ = function(video, opt_callback) { |
| 254 this.unloadVideo(); | 253 this.unloadVideo(); |
| 255 | 254 |
| 256 document.title = title; | 255 document.title = video.title; |
| 257 | 256 |
| 258 document.querySelector('#title').innerText = title; | 257 document.querySelector('#title').innerText = video.title; |
| 259 | 258 |
| 260 var videoPlayerElement = document.querySelector('#video-player'); | 259 var videoPlayerElement = document.querySelector('#video-player'); |
| 261 if (this.currentPos_ === (this.videos_.length - 1)) | 260 if (this.currentPos_ === (this.videos_.length - 1)) |
| 262 videoPlayerElement.setAttribute('last-video', true); | 261 videoPlayerElement.setAttribute('last-video', true); |
| 263 else | 262 else |
| 264 videoPlayerElement.removeAttribute('last-video'); | 263 videoPlayerElement.removeAttribute('last-video'); |
| 265 | 264 |
| 266 if (this.currentPos_ === 0) | 265 if (this.currentPos_ === 0) |
| 267 videoPlayerElement.setAttribute('first-video', true); | 266 videoPlayerElement.setAttribute('first-video', true); |
| 268 else | 267 else |
| (...skipping 13 matching lines...) Expand all Loading... |
| 282 document.querySelector('#cast-name-label').textContent = | 281 document.querySelector('#cast-name-label').textContent = |
| 283 loadTimeData.getString('VIDEO_PLAYER_PLAYING_ON');; | 282 loadTimeData.getString('VIDEO_PLAYER_PLAYING_ON');; |
| 284 document.querySelector('#cast-name').textContent = this.currentCast_.name; | 283 document.querySelector('#cast-name').textContent = this.currentCast_.name; |
| 285 } else { | 284 } else { |
| 286 videoPlayerElement.removeAttribute('casting'); | 285 videoPlayerElement.removeAttribute('casting'); |
| 287 | 286 |
| 288 this.videoElement_ = document.createElement('video'); | 287 this.videoElement_ = document.createElement('video'); |
| 289 document.querySelector('#video-container').appendChild(this.videoElement_); | 288 document.querySelector('#video-container').appendChild(this.videoElement_); |
| 290 | 289 |
| 291 this.controls.attachMedia(this.videoElement_); | 290 this.controls.attachMedia(this.videoElement_); |
| 292 this.videoElement_.src = url; | 291 this.videoElement_.src = video.url; |
| 293 } | 292 } |
| 294 | 293 |
| 295 this.videoElement_.load(); | 294 this.videoElement_.load(); |
| 296 | 295 |
| 297 if (opt_callback) { | 296 if (opt_callback) { |
| 298 var handler = function(currentPos, event) { | 297 var handler = function(currentPos, event) { |
| 299 console.log('loaded: ', currentPos, this.currentPos_); | 298 console.log('loaded: ', currentPos, this.currentPos_); |
| 300 if (currentPos === this.currentPos_) | 299 if (currentPos === this.currentPos_) |
| 301 opt_callback(); | 300 opt_callback(); |
| 302 this.videoElement_.removeEventListener('loadedmetadata', handler); | 301 this.videoElement_.removeEventListener('loadedmetadata', handler); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 }; | 383 }; |
| 385 | 384 |
| 386 /** | 385 /** |
| 387 * Reloads the current video. | 386 * Reloads the current video. |
| 388 * | 387 * |
| 389 * @param {function()=} opt_callback Completion callback. | 388 * @param {function()=} opt_callback Completion callback. |
| 390 * @private | 389 * @private |
| 391 */ | 390 */ |
| 392 VideoPlayer.prototype.reloadCurrentVideo_ = function(opt_callback) { | 391 VideoPlayer.prototype.reloadCurrentVideo_ = function(opt_callback) { |
| 393 var currentVideo = this.videos_[this.currentPos_]; | 392 var currentVideo = this.videos_[this.currentPos_]; |
| 394 this.loadVideo_(currentVideo.fileUrl, currentVideo.entry.name, opt_callback); | 393 this.loadVideo_(currentVideo, opt_callback); |
| 395 }; | 394 }; |
| 396 | 395 |
| 397 /** | 396 /** |
| 398 * Invokes when a menuitem in the cast menu is selected. | 397 * Invokes when a menuitem in the cast menu is selected. |
| 399 * @param {Object} cast Selected element in the list of casts. | 398 * @param {Object} cast Selected element in the list of casts. |
| 400 */ | 399 */ |
| 401 VideoPlayer.prototype.onCastSelected_ = function(cast) { | 400 VideoPlayer.prototype.onCastSelected_ = function(cast) { |
| 402 // If the selected item is same as the current item, do nothing. | 401 // If the selected item is same as the current item, do nothing. |
| 403 if ((this.currentCast_ && this.currentCast_.name) === (cast && cast.name)) | 402 if ((this.currentCast_ && this.currentCast_.name) === (cast && cast.name)) |
| 404 return; | 403 return; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 var initPromise = Promise.all( | 478 var initPromise = Promise.all( |
| 480 [new Promise(initVideos.wrap(null)), | 479 [new Promise(initVideos.wrap(null)), |
| 481 new Promise(initStrings.wrap(null)), | 480 new Promise(initStrings.wrap(null)), |
| 482 new Promise(util.addPageLoadHandler.wrap(null))]); | 481 new Promise(util.addPageLoadHandler.wrap(null))]); |
| 483 | 482 |
| 484 initPromise.then(function(results) { | 483 initPromise.then(function(results) { |
| 485 var videos = results[0]; | 484 var videos = results[0]; |
| 486 player.prepare(videos); | 485 player.prepare(videos); |
| 487 return new Promise(player.playFirstVideo.wrap(player)); | 486 return new Promise(player.playFirstVideo.wrap(player)); |
| 488 }.wrap(null)); | 487 }.wrap(null)); |
| OLD | NEW |