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 /** | 5 /** |
6 * @param {Element} playerContainer Main container. | 6 * @param {Element} playerContainer Main container. |
7 * @param {Element} videoContainer Container for the video element. | 7 * @param {Element} videoContainer Container for the video element. |
8 * @param {Element} controlsContainer Container for video controls. | 8 * @param {Element} controlsContainer Container for video controls. |
9 * @constructor | 9 * @constructor |
10 */ | 10 */ |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 document.querySelector('#thumbnail').style.backgroundImage = ''; | 311 document.querySelector('#thumbnail').style.backgroundImage = ''; |
312 } | 312 } |
313 }) | 313 }) |
314 .catch(function() { | 314 .catch(function() { |
315 // Shows no image on error. | 315 // Shows no image on error. |
316 document.querySelector('#thumbnail').style.backgroundImage = ''; | 316 document.querySelector('#thumbnail').style.backgroundImage = ''; |
317 }); | 317 }); |
318 | 318 |
319 var videoElementInitializePromise; | 319 var videoElementInitializePromise; |
320 if (this.currentCast_) { | 320 if (this.currentCast_) { |
| 321 metrics.recordPlayType(metrics.PLAY_TYPE.CAST); |
| 322 |
321 videoPlayerElement.setAttribute('casting', true); | 323 videoPlayerElement.setAttribute('casting', true); |
322 | 324 |
323 document.querySelector('#cast-name').textContent = | 325 document.querySelector('#cast-name').textContent = |
324 this.currentCast_.friendlyName; | 326 this.currentCast_.friendlyName; |
325 | 327 |
326 videoPlayerElement.setAttribute('castable', true); | 328 videoPlayerElement.setAttribute('castable', true); |
327 | 329 |
328 videoElementInitializePromise = media.isAvailableForCast() | 330 videoElementInitializePromise = media.isAvailableForCast() |
329 .then(function(result) { | 331 .then(function(result) { |
330 if (!result) | 332 if (!result) |
331 return Promise.reject('No casts are available.'); | 333 return Promise.reject('No casts are available.'); |
332 | 334 |
333 return new Promise(function(fulfill, reject) { | 335 return new Promise(function(fulfill, reject) { |
334 chrome.cast.requestSession( | 336 chrome.cast.requestSession( |
335 fulfill, reject, undefined, this.currentCast_.label); | 337 fulfill, reject, undefined, this.currentCast_.label); |
336 }.bind(this)).then(function(session) { | 338 }.bind(this)).then(function(session) { |
337 session.addUpdateListener(this.onCastSessionUpdateBound_); | 339 session.addUpdateListener(this.onCastSessionUpdateBound_); |
338 | 340 |
339 this.currentSession_ = session; | 341 this.currentSession_ = session; |
340 this.videoElement_ = new CastVideoElement(media, session); | 342 this.videoElement_ = new CastVideoElement(media, session); |
341 this.controls.attachMedia(this.videoElement_); | 343 this.controls.attachMedia(this.videoElement_); |
342 }.bind(this)); | 344 }.bind(this)); |
343 }.bind(this)); | 345 }.bind(this)); |
344 } else { | 346 } else { |
| 347 metrics.recordPlayType(metrics.PLAY_TYPE.LOCAL); |
345 videoPlayerElement.removeAttribute('casting'); | 348 videoPlayerElement.removeAttribute('casting'); |
346 | 349 |
347 this.videoElement_ = document.createElement('video'); | 350 this.videoElement_ = document.createElement('video'); |
348 document.querySelector('#video-container').appendChild( | 351 document.querySelector('#video-container').appendChild( |
349 this.videoElement_); | 352 this.videoElement_); |
350 | 353 |
351 this.controls.attachMedia(this.videoElement_); | 354 this.controls.attachMedia(this.videoElement_); |
352 this.videoElement_.src = video.url; | 355 this.videoElement_.src = video.url; |
353 | 356 |
354 media.isAvailableForCast().then(function(result) { | 357 media.isAvailableForCast().then(function(result) { |
(...skipping 28 matching lines...) Expand all Loading... |
383 }.wrap()); | 386 }.wrap()); |
384 this.videoElement_.addEventListener('pause', function() { | 387 this.videoElement_.addEventListener('pause', function() { |
385 chrome.power.releaseKeepAwake(); | 388 chrome.power.releaseKeepAwake(); |
386 }.wrap()); | 389 }.wrap()); |
387 | 390 |
388 this.videoElement_.load(); | 391 this.videoElement_.load(); |
389 callback(); | 392 callback(); |
390 }.bind(this)) | 393 }.bind(this)) |
391 // In case of error. | 394 // In case of error. |
392 .catch(function(error) { | 395 .catch(function(error) { |
| 396 if (this.currentCast_) |
| 397 metrics.recordCastVideoErrorAction(); |
| 398 |
393 videoPlayerElement.removeAttribute('loading'); | 399 videoPlayerElement.removeAttribute('loading'); |
394 console.error('Failed to initialize the video element.', | 400 console.error('Failed to initialize the video element.', |
395 error.stack || error); | 401 error.stack || error); |
396 this.controls_.showErrorMessage( | 402 this.controls_.showErrorMessage( |
397 'VIDEO_PLAYER_VIDEO_FILE_UNSUPPORTED'); | 403 'VIDEO_PLAYER_VIDEO_FILE_UNSUPPORTED'); |
398 callback(); | 404 callback(); |
399 }.bind(this)); | 405 }.bind(this)); |
400 }.wrap(this)); | 406 }.wrap(this)); |
401 }; | 407 }; |
402 | 408 |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 }.wrap(null)); | 667 }.wrap(null)); |
662 } | 668 } |
663 | 669 |
664 var initPromise = Promise.all( | 670 var initPromise = Promise.all( |
665 [new Promise(initVideos.wrap(null)), | 671 [new Promise(initVideos.wrap(null)), |
666 new Promise(initStrings.wrap(null)), | 672 new Promise(initStrings.wrap(null)), |
667 new Promise(util.addPageLoadHandler.wrap(null))]); | 673 new Promise(util.addPageLoadHandler.wrap(null))]); |
668 | 674 |
669 initPromise.then(function(results) { | 675 initPromise.then(function(results) { |
670 var videos = results[0]; | 676 var videos = results[0]; |
| 677 |
| 678 metrics.recordOpenVideoPlayerAction(); |
| 679 metrics.recordNumberOfOpenedFiles(videos.length); |
| 680 |
671 player.prepare(videos); | 681 player.prepare(videos); |
672 return new Promise(player.playFirstVideo.wrap(player)); | 682 return new Promise(player.playFirstVideo.wrap(player)); |
673 }.wrap(null)); | 683 }.wrap(null)); |
OLD | NEW |