| 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 */ | 181 */ |
| 182 VideoPlayer.prototype.prepare = function(videos) { | 182 VideoPlayer.prototype.prepare = function(videos) { |
| 183 this.videos_ = videos; | 183 this.videos_ = videos; |
| 184 | 184 |
| 185 var preventDefault = function(event) { event.preventDefault(); }.wrap(null); | 185 var preventDefault = function(event) { event.preventDefault(); }.wrap(null); |
| 186 | 186 |
| 187 document.ondragstart = preventDefault; | 187 document.ondragstart = preventDefault; |
| 188 | 188 |
| 189 var maximizeButton = document.querySelector('.maximize-button'); | 189 var maximizeButton = document.querySelector('.maximize-button'); |
| 190 maximizeButton.addEventListener( | 190 maximizeButton.addEventListener( |
| 191 'click', | 191 'click', |
| 192 function(event) { | 192 function(event) { |
| 193 var appWindow = chrome.app.window.current(); | 193 var appWindow = chrome.app.window.current(); |
| 194 if (appWindow.isMaximized()) | 194 if (appWindow.isMaximized()) |
| 195 appWindow.restore(); | 195 appWindow.restore(); |
| 196 else | 196 else |
| 197 appWindow.maximize(); | 197 appWindow.maximize(); |
| 198 event.stopPropagation(); | 198 event.stopPropagation(); |
| 199 }.wrap(null)); | 199 }.wrap(null)); |
| 200 maximizeButton.addEventListener('mousedown', preventDefault); | 200 maximizeButton.addEventListener('mousedown', preventDefault); |
| 201 | 201 |
| 202 var minimizeButton = document.querySelector('.minimize-button'); | 202 var minimizeButton = document.querySelector('.minimize-button'); |
| 203 minimizeButton.addEventListener( | 203 minimizeButton.addEventListener( |
| 204 'click', | 204 'click', |
| 205 function(event) { | 205 function(event) { |
| 206 chrome.app.window.current().minimize() | 206 chrome.app.window.current().minimize(); |
| 207 event.stopPropagation(); | 207 event.stopPropagation(); |
| 208 }.wrap(null)); | 208 }.wrap(null)); |
| 209 minimizeButton.addEventListener('mousedown', preventDefault); | 209 minimizeButton.addEventListener('mousedown', preventDefault); |
| 210 | 210 |
| 211 var closeButton = document.querySelector('.close-button'); | 211 var closeButton = document.querySelector('.close-button'); |
| 212 closeButton.addEventListener( | 212 closeButton.addEventListener( |
| 213 'click', | 213 'click', |
| 214 function(event) { | 214 function(event) { |
| 215 close(); | 215 close(); |
| 216 event.stopPropagation(); | 216 event.stopPropagation(); |
| 217 }.wrap(null)); | 217 }.wrap(null)); |
| 218 closeButton.addEventListener('mousedown', preventDefault); | 218 closeButton.addEventListener('mousedown', preventDefault); |
| 219 | 219 |
| 220 var castButton = document.querySelector('.cast-button'); | 220 var castButton = document.querySelector('.cast-button'); |
| 221 cr.ui.decorate(castButton, cr.ui.MenuButton); | 221 cr.ui.decorate(castButton, cr.ui.MenuButton); |
| 222 castButton.addEventListener( | 222 castButton.addEventListener( |
| 223 'click', | 223 'click', |
| 224 function(event) { | 224 function(event) { |
| 225 event.stopPropagation(); | 225 event.stopPropagation(); |
| 226 }.wrap(null)); | 226 }.wrap(null)); |
| 227 castButton.addEventListener('mousedown', preventDefault); | 227 castButton.addEventListener('mousedown', preventDefault); |
| 228 | 228 |
| 229 var menu = document.querySelector('#cast-menu'); | 229 var menu = document.querySelector('#cast-menu'); |
| 230 cr.ui.decorate(menu, cr.ui.Menu); | 230 cr.ui.decorate(menu, cr.ui.Menu); |
| 231 | 231 |
| 232 this.controls_ = new FullWindowVideoControls( | 232 this.controls_ = new FullWindowVideoControls( |
| 233 document.querySelector('#video-player'), | 233 document.querySelector('#video-player'), |
| 234 document.querySelector('#video-container'), | 234 document.querySelector('#video-container'), |
| 235 document.querySelector('#controls')); | 235 document.querySelector('#controls')); |
| 236 | 236 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 document.querySelector('#error').removeAttribute('visible'); | 304 document.querySelector('#error').removeAttribute('visible'); |
| 305 this.controls.detachMedia(); | 305 this.controls.detachMedia(); |
| 306 this.controls.inactivityWatcher.disabled = true; | 306 this.controls.inactivityWatcher.disabled = true; |
| 307 this.controls.decodeErrorOccured = false; | 307 this.controls.decodeErrorOccured = false; |
| 308 this.controls.casting = !!this.currentCast_; | 308 this.controls.casting = !!this.currentCast_; |
| 309 | 309 |
| 310 videoPlayerElement.setAttribute('loading', true); | 310 videoPlayerElement.setAttribute('loading', true); |
| 311 | 311 |
| 312 var media = new MediaManager(video.entry); | 312 var media = new MediaManager(video.entry); |
| 313 | 313 |
| 314 Promise.all([media.getThumbnail(), media.getToken()]).then( | 314 Promise.all([media.getThumbnail(), media.getToken()]) |
| 315 function(results) { | 315 .then(function(results) { |
| 316 var url = results[0]; | 316 var url = results[0]; |
| 317 var token = results[1]; | 317 var token = results[1]; |
| 318 document.querySelector('#thumbnail').style.backgroundImage = | 318 document.querySelector('#thumbnail').style.backgroundImage = |
| 319 'url(' + url + '&access_token=' + token + ')'; | 319 'url(' + url + '&access_token=' + token + ')'; |
| 320 }).catch(function() { | 320 }) |
| 321 .catch(function() { |
| 321 // Shows no image on error. | 322 // Shows no image on error. |
| 322 document.querySelector('#thumbnail').style.backgroundImage = ''; | 323 document.querySelector('#thumbnail').style.backgroundImage = ''; |
| 323 }); | 324 }); |
| 324 | 325 |
| 325 var videoElementInitializePromise; | 326 var videoElementInitializePromise; |
| 326 if (this.currentCast_) { | 327 if (this.currentCast_) { |
| 327 videoPlayerElement.setAttribute('casting', true); | 328 videoPlayerElement.setAttribute('casting', true); |
| 328 | 329 |
| 329 document.querySelector('#cast-name').textContent = | 330 document.querySelector('#cast-name').textContent = |
| 330 this.currentCast_.friendlyName; | 331 this.currentCast_.friendlyName; |
| 331 | 332 |
| 332 videoPlayerElement.setAttribute('castable', true); | 333 videoPlayerElement.setAttribute('castable', true); |
| 333 | 334 |
| 334 videoElementInitializePromise = | 335 videoElementInitializePromise = media.isAvailableForCast() |
| 335 media.isAvailableForCast().then(function(result) { | 336 .then(function(result) { |
| 336 if (!result) | 337 if (!result) |
| 337 return Promise.reject('No casts are available.'); | 338 return Promise.reject('No casts are available.'); |
| 338 | 339 |
| 339 return new Promise(function(fulfill, reject) { | 340 return new Promise(function(fulfill, reject) { |
| 340 chrome.cast.requestSession( | 341 chrome.cast.requestSession( |
| 341 fulfill, reject, undefined, this.currentCast_.label); | 342 fulfill, reject, undefined, this.currentCast_.label); |
| 342 }.bind(this)).then(function(session) { | 343 }.bind(this)).then(function(session) { |
| 343 session.addUpdateListener(this.onCastSessionUpdateBound_); | 344 session.addUpdateListener(this.onCastSessionUpdateBound_); |
| 344 | 345 |
| 345 this.currentSession_ = session; | 346 this.currentSession_ = session; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 362 videoPlayerElement.setAttribute('castable', true); | 363 videoPlayerElement.setAttribute('castable', true); |
| 363 else | 364 else |
| 364 videoPlayerElement.removeAttribute('castable'); | 365 videoPlayerElement.removeAttribute('castable'); |
| 365 }).catch(function() { | 366 }).catch(function() { |
| 366 videoPlayerElement.setAttribute('castable', true); | 367 videoPlayerElement.setAttribute('castable', true); |
| 367 }); | 368 }); |
| 368 | 369 |
| 369 videoElementInitializePromise = Promise.resolve(); | 370 videoElementInitializePromise = Promise.resolve(); |
| 370 } | 371 } |
| 371 | 372 |
| 372 videoElementInitializePromise. | 373 videoElementInitializePromise |
| 373 then(function() { | 374 .then(function() { |
| 374 var handler = function(currentPos) { | 375 var handler = function(currentPos) { |
| 375 if (currentPos === this.currentPos_) { | 376 if (currentPos === this.currentPos_) { |
| 376 if (opt_callback) | 377 if (opt_callback) |
| 377 opt_callback(); | 378 opt_callback(); |
| 378 videoPlayerElement.removeAttribute('loading'); | 379 videoPlayerElement.removeAttribute('loading'); |
| 379 this.controls.inactivityWatcher.disabled = false; | 380 this.controls.inactivityWatcher.disabled = false; |
| 380 } | 381 } |
| 381 | 382 |
| 382 this.videoElement_.removeEventListener('loadedmetadata', handler); | 383 this.videoElement_.removeEventListener('loadedmetadata', handler); |
| 383 }.wrap(this, this.currentPos_); | 384 }.wrap(this, this.currentPos_); |
| 384 | 385 |
| 385 this.videoElement_.addEventListener('loadedmetadata', handler); | 386 this.videoElement_.addEventListener('loadedmetadata', handler); |
| 386 | 387 |
| 387 this.videoElement_.addEventListener('play', function() { | 388 this.videoElement_.addEventListener('play', function() { |
| 388 chrome.power.requestKeepAwake('display'); | 389 chrome.power.requestKeepAwake('display'); |
| 389 }.wrap()); | 390 }.wrap()); |
| 390 this.videoElement_.addEventListener('pause', function() { | 391 this.videoElement_.addEventListener('pause', function() { |
| 391 chrome.power.releaseKeepAwake(); | 392 chrome.power.releaseKeepAwake(); |
| 392 }.wrap()); | 393 }.wrap()); |
| 393 | 394 |
| 394 this.videoElement_.load(); | 395 this.videoElement_.load(); |
| 395 callback(); | 396 callback(); |
| 396 }.bind(this)). | 397 }.bind(this)) |
| 397 // In case of error. | 398 // In case of error. |
| 398 catch(function(error) { | 399 .catch(function(error) { |
| 399 videoPlayerElement.removeAttribute('loading'); | 400 videoPlayerElement.removeAttribute('loading'); |
| 400 console.error('Failed to initialize the video element.', | 401 console.error('Failed to initialize the video element.', |
| 401 error.stack || error); | 402 error.stack || error); |
| 402 this.controls_.showErrorMessage('GALLERY_VIDEO_ERROR'); | 403 this.controls_.showErrorMessage('GALLERY_VIDEO_ERROR'); |
| 403 callback(); | 404 callback(); |
| 404 }.bind(this)); | 405 }.bind(this)); |
| 405 }.wrap(this)); | 406 }.wrap(this)); |
| 406 }; | 407 }; |
| 407 | 408 |
| 408 /** | 409 /** |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 * @param {function()=} opt_callback Completion callback. | 508 * @param {function()=} opt_callback Completion callback. |
| 508 */ | 509 */ |
| 509 VideoPlayer.prototype.reloadCurrentVideo = function(opt_callback) { | 510 VideoPlayer.prototype.reloadCurrentVideo = function(opt_callback) { |
| 510 var currentVideo = this.videos_[this.currentPos_]; | 511 var currentVideo = this.videos_[this.currentPos_]; |
| 511 this.loadVideo_(currentVideo, opt_callback); | 512 this.loadVideo_(currentVideo, opt_callback); |
| 512 }; | 513 }; |
| 513 | 514 |
| 514 /** | 515 /** |
| 515 * Invokes when a menuitem in the cast menu is selected. | 516 * Invokes when a menuitem in the cast menu is selected. |
| 516 * @param {Object} cast Selected element in the list of casts. | 517 * @param {Object} cast Selected element in the list of casts. |
| 518 * @private |
| 517 */ | 519 */ |
| 518 VideoPlayer.prototype.onCastSelected_ = function(cast) { | 520 VideoPlayer.prototype.onCastSelected_ = function(cast) { |
| 519 // If the selected item is same as the current item, do nothing. | 521 // If the selected item is same as the current item, do nothing. |
| 520 if ((this.currentCast_ && this.currentCast_.label) === (cast && cast.label)) | 522 if ((this.currentCast_ && this.currentCast_.label) === (cast && cast.label)) |
| 521 return; | 523 return; |
| 522 | 524 |
| 523 this.unloadVideo(false); | 525 this.unloadVideo(false); |
| 524 | 526 |
| 525 // Waits for unloading video. | 527 // Waits for unloading video. |
| 526 this.loadQueue_.run(function(callback) { | 528 this.loadQueue_.run(function(callback) { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 var initPromise = Promise.all( | 667 var initPromise = Promise.all( |
| 666 [new Promise(initVideos.wrap(null)), | 668 [new Promise(initVideos.wrap(null)), |
| 667 new Promise(initStrings.wrap(null)), | 669 new Promise(initStrings.wrap(null)), |
| 668 new Promise(util.addPageLoadHandler.wrap(null))]); | 670 new Promise(util.addPageLoadHandler.wrap(null))]); |
| 669 | 671 |
| 670 initPromise.then(function(results) { | 672 initPromise.then(function(results) { |
| 671 var videos = results[0]; | 673 var videos = results[0]; |
| 672 player.prepare(videos); | 674 player.prepare(videos); |
| 673 return new Promise(player.playFirstVideo.wrap(player)); | 675 return new Promise(player.playFirstVideo.wrap(player)); |
| 674 }.wrap(null)); | 676 }.wrap(null)); |
| OLD | NEW |