Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1600)

Unified Diff: ui/file_manager/video_player/js/video_player.js

Issue 1987173002: Video Player: Support Media Router to cast Drive videos. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/file_manager/video_player/js/video_player.js
diff --git a/ui/file_manager/video_player/js/video_player.js b/ui/file_manager/video_player/js/video_player.js
index fadab6e61e7d3361ed4601529c794fbc2c8fb327..455cae61a30f01ce08e13f2a7938ce6942c6d0c4 100644
--- a/ui/file_manager/video_player/js/video_player.js
+++ b/ui/file_manager/video_player/js/video_player.js
@@ -277,6 +277,10 @@ VideoPlayer.prototype.prepare = function(videos) {
else
videoPlayerElement.removeAttribute('multiple');
+ var castButton = queryRequiredElement('.cast-button');
+ castButton.addEventListener('click',
+ this.onCastButtonClicked_.wrap(this));
+
document.addEventListener('keydown', reloadVideo);
document.addEventListener('click', reloadVideo);
};
@@ -359,8 +363,6 @@ VideoPlayer.prototype.loadVideo_ = function(video, opt_callback) {
if (this.currentCast_) {
metrics.recordPlayType(metrics.PLAY_TYPE.CAST);
- videoPlayerElement.setAttribute('casting', true);
-
getRequiredElement('cast-name').textContent =
this.currentCast_.friendlyName;
@@ -372,9 +374,14 @@ VideoPlayer.prototype.loadVideo_ = function(video, opt_callback) {
return Promise.reject('No casts are available.');
return new Promise(function(fulfill, reject) {
- chrome.cast.requestSession(
- fulfill, reject, undefined, this.currentCast_.label);
+ if (this.currentSession_) {
+ fulfill(this.currentSession_);
+ } else {
+ chrome.cast.requestSession(
+ fulfill, reject, undefined, this.currentCast_.label);
+ }
}.bind(this)).then(function(session) {
+ videoPlayerElement.setAttribute('casting', true);
session.addUpdateListener(this.onCastSessionUpdateBound_);
this.currentSession_ = session;
@@ -503,7 +510,10 @@ VideoPlayer.prototype.unloadVideo = function(opt_keepSession) {
this.videoElement_ = null;
if (!opt_keepSession && this.currentSession_) {
- this.currentSession_.stop(callback, callback);
+ if (this.currentSession_.status === chrome.cast.SessionStatus.CONNECTED)
fukino 2016/05/18 05:02:21 bug fix: We should not request stop() if the curre
yoshiki 2016/05/19 07:23:37 nit: Please add a comment for that.
fukino 2016/05/19 08:11:06 Done.
+ this.currentSession_.stop(callback, callback);
+ else
+ setTimeout(callback);
this.currentSession_.removeUpdateListener(this.onCastSessionUpdateBound_);
this.currentSession_ = null;
} else {
@@ -653,6 +663,49 @@ VideoPlayer.prototype.setCastList = function(casts) {
};
/**
+ * Tells the availability of cast receivers to VideoPlayeru topdate the
+ * visibility of the cast button..
yoshiki 2016/05/19 07:23:37 nit: JSdoc for the argument.
fukino 2016/05/19 08:11:06 Done.
+ */
+VideoPlayer.prototype.setCastAvailability = function(available) {
+ var videoPlayerElement = getRequiredElement('video-player');
+ if (available) {
+ videoPlayerElement.setAttribute('mr-cast-available', true);
+ } else {
+ videoPlayerElement.removeAttribute('mr-cast-available');
+ if (this.currentCast_)
+ this.onCurrentCastDisappear_();
+ }
+};
+
+/**
+ * Handles click event on cast button to request a session.
+ * @private
+ */
+VideoPlayer.prototype.onCastButtonClicked_ = function() {
+ // This method is called only when Media Router is enabled.
+ // In this case, requestSession() will open a built-in dialog (not a dropdown
+ // menu) to choose the receiver, and callback is called with the session
+ // object after user's operation..
+ chrome.cast.requestSession(
+ function(session) {
+ this.unloadVideo(true);
+ this.loadQueue_.run(function(callback) {
+ this.currentCast_ = {
+ label: session.receiver.label,
+ friendlyName: session.receiver.friendlyName
+ };
+ this.currentSession_ = session;
+ this.reloadCurrentVideo();
+ callback();
+ }.bind(this));
+ }.bind(this),
+ function(error) {
+ if (error.code !== chrome.cast.ErrorCode.CANCEL)
+ console.error('requestSession from cast button failed', error);
+ });
+};
+
+/**
* Updates the check status of the cast menu items.
* @private
*/
@@ -696,8 +749,20 @@ VideoPlayer.prototype.onCurrentCastDisappear_ = function() {
* @private
*/
VideoPlayer.prototype.onCastSessionUpdate_ = function(alive) {
- if (!alive)
+ if (!alive) {
+ var videoPlayerElement = getRequiredElement('video-player');
+ videoPlayerElement.removeAttribute('casting');
+
+ // Loads the current video in local player.
fukino 2016/05/18 05:02:21 bug fix: we need to switch to local player even wh
this.unloadVideo();
+ this.loadQueue_.run(function(callback) {
+ this.currentCast_ = null;
+ if (!chrome.cast.usingPresentationApi)
+ this.updateCheckOnCastMenu_();
+ this.reloadCurrentVideo();
+ callback();
+ }.wrap(this));
+ }
};
/**

Powered by Google App Engine
This is Rietveld 408576698