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

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: Address review comments. 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
« no previous file with comments | « ui/file_manager/video_player/js/media_controls.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..b7defccbbbcb18112b90a4f5da3d86c0aa3e9a4b 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,12 @@ VideoPlayer.prototype.unloadVideo = function(opt_keepSession) {
this.videoElement_ = null;
if (!opt_keepSession && this.currentSession_) {
- this.currentSession_.stop(callback, callback);
+ // We should not request stop() if the current session is not connected to
+ // the receiver.
+ if (this.currentSession_.status === chrome.cast.SessionStatus.CONNECTED)
+ this.currentSession_.stop(callback, callback);
+ else
+ setTimeout(callback);
this.currentSession_.removeUpdateListener(this.onCastSessionUpdateBound_);
this.currentSession_ = null;
} else {
@@ -653,6 +665,50 @@ VideoPlayer.prototype.setCastList = function(casts) {
};
/**
+ * Tells the availability of cast receivers to VideoPlayeru topdate the
+ * visibility of the cast button..
+ * @param {boolean} available Whether at least one cast receiver is available.
+ */
+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 +752,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.
this.unloadVideo();
+ this.loadQueue_.run(function(callback) {
+ this.currentCast_ = null;
+ if (!chrome.cast.usingPresentationApi)
+ this.updateCheckOnCastMenu_();
+ this.reloadCurrentVideo();
+ callback();
+ }.wrap(this));
+ }
};
/**
« no previous file with comments | « ui/file_manager/video_player/js/media_controls.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698