mirror of
https://github.com/jellyfin/jellyfin-web.git
synced 2024-11-17 19:08:18 -07:00
re-enable chromecast, not functional yet
This commit is contained in:
parent
5412ab129e
commit
dd1f6487b0
@ -251,41 +251,41 @@
|
||||
* Loads media into a running receiver application
|
||||
* @param {Number} mediaIndex An index number to indicate current media content
|
||||
*/
|
||||
CastPlayer.prototype.loadMedia = function (user, item, startTimeTicks, mediaSourceId, audioStreamIndex, subtitleStreamIndex) {
|
||||
CastPlayer.prototype.loadMedia = function (userId, options, command) {
|
||||
|
||||
if (!this.session) {
|
||||
console.log("no session");
|
||||
return;
|
||||
}
|
||||
|
||||
this.currentMediaOffset = startTimeTicks || 0;
|
||||
//this.currentMediaOffset = startTimeTicks || 0;
|
||||
|
||||
var maxBitrate = 12000000;
|
||||
var mediaInfo = getMediaSourceInfo(user, item, maxBitrate, mediaSourceId, audioStreamIndex, subtitleStreamIndex);
|
||||
//var maxBitrate = 12000000;
|
||||
//var mediaInfo = getMediaSourceInfo(user, item, maxBitrate, mediaSourceId, audioStreamIndex, subtitleStreamIndex);
|
||||
|
||||
var streamUrl = getStreamUrl(item, mediaInfo, startTimeTicks, maxBitrate);
|
||||
//var streamUrl = getStreamUrl(item, mediaInfo, startTimeTicks, maxBitrate);
|
||||
|
||||
var castMediaInfo = new chrome.cast.media.MediaInfo(streamUrl);
|
||||
//var castMediaInfo = new chrome.cast.media.MediaInfo(streamUrl);
|
||||
|
||||
castMediaInfo.customData = getCustomData(item, mediaInfo.mediaSource.Id, startTimeTicks);
|
||||
castMediaInfo.metadata = getMetadata(item);
|
||||
//castMediaInfo.customData = getCustomData(item, mediaInfo.mediaSource.Id, startTimeTicks);
|
||||
//castMediaInfo.metadata = getMetadata(item);
|
||||
|
||||
if (mediaInfo.streamContainer == 'm3u8') {
|
||||
castMediaInfo.contentType = 'application/x-mpegURL';
|
||||
} else {
|
||||
castMediaInfo.contentType = item.MediaType.toLowerCase() + '/' + mediaInfo.streamContainer.toLowerCase();
|
||||
}
|
||||
//if (mediaInfo.streamContainer == 'm3u8') {
|
||||
// castMediaInfo.contentType = 'application/x-mpegURL';
|
||||
//} else {
|
||||
// castMediaInfo.contentType = item.MediaType.toLowerCase() + '/' + mediaInfo.streamContainer.toLowerCase();
|
||||
//}
|
||||
|
||||
castMediaInfo.streamType = mediaInfo.isStatic ? chrome.cast.media.StreamType.BUFFERED : chrome.cast.media.StreamType.LIVE;
|
||||
//castMediaInfo.streamType = mediaInfo.isStatic ? chrome.cast.media.StreamType.BUFFERED : chrome.cast.media.StreamType.LIVE;
|
||||
|
||||
var request = new chrome.cast.media.LoadRequest(castMediaInfo);
|
||||
request.autoplay = true;
|
||||
request.currentTime = startTimeTicks ? startTimeTicks / 10000000 : 0;
|
||||
//var request = new chrome.cast.media.LoadRequest(castMediaInfo);
|
||||
//request.autoplay = true;
|
||||
//request.currentTime = startTimeTicks ? startTimeTicks / 10000000 : 0;
|
||||
|
||||
this.castPlayerState = PLAYER_STATE.LOADING;
|
||||
this.session.loadMedia(request,
|
||||
this.onMediaDiscovered.bind(this, 'loadMedia'),
|
||||
this.onLoadMediaError.bind(this));
|
||||
//this.castPlayerState = PLAYER_STATE.LOADING;
|
||||
//this.session.loadMedia(request,
|
||||
// this.onMediaDiscovered.bind(this, 'loadMedia'),
|
||||
// this.onLoadMediaError.bind(this));
|
||||
};
|
||||
|
||||
/**
|
||||
@ -379,7 +379,7 @@
|
||||
case PLAYER_STATE.IDLE:
|
||||
case PLAYER_STATE.LOADING:
|
||||
case PLAYER_STATE.STOPPED:
|
||||
this.loadMedia(this.currentMediaIndex);
|
||||
this.loadMedia();
|
||||
this.currentMediaSession.addUpdateListener(this.mediaStatusUpdateHandler);
|
||||
this.castPlayerState = PLAYER_STATE.PLAYING;
|
||||
break;
|
||||
@ -588,7 +588,7 @@
|
||||
this.timer = setInterval(this.incrementMediaTimeHandler, this.timerStep);
|
||||
};
|
||||
|
||||
//var castPlayer = new CastPlayer();
|
||||
var castPlayer = new CastPlayer();
|
||||
|
||||
function getCodecLimits() {
|
||||
|
||||
@ -973,8 +973,6 @@
|
||||
|
||||
var self = this;
|
||||
|
||||
var currentPlaylistIndex;
|
||||
|
||||
var getItemFields = "MediaSources,Chapters";
|
||||
|
||||
self.name = PlayerName;
|
||||
@ -983,20 +981,16 @@
|
||||
|
||||
self.isMuted = false;
|
||||
|
||||
self.playlist = [];
|
||||
|
||||
self.playlistIndex = 0;
|
||||
|
||||
self.positionTicks = 0;
|
||||
|
||||
self.runtimeTicks = 0;
|
||||
|
||||
$(castPlayer).on("/playback/complete", function (e) {
|
||||
if (self.playlistIndex < (self.playlist.items || []).length) {
|
||||
self.play(self.playlist);
|
||||
} else {
|
||||
$(self).trigger("playbackstop.nowplayingbar");
|
||||
}
|
||||
|
||||
var state = self.getPlayerStateInternal();
|
||||
|
||||
$(self).trigger("playbackstop", [state]);
|
||||
|
||||
});
|
||||
|
||||
$(castPlayer).on("/playback/update", function (e, data) {
|
||||
@ -1006,98 +1000,11 @@
|
||||
|
||||
var state = self.getPlayerStateInternal();
|
||||
|
||||
$(self).trigger("positionchange.nowplayingbar", [ state ]);
|
||||
$(self).trigger("positionchange", [state]);
|
||||
});
|
||||
|
||||
function getItemsForPlayback(query) {
|
||||
var userId = Dashboard.getCurrentUserId();
|
||||
|
||||
query.Limit = query.Limit || 100;
|
||||
query.Fields = getItemFields;
|
||||
query.ExcludeLocationTypes = "Virtual";
|
||||
|
||||
return ApiClient.getItems(userId, query);
|
||||
}
|
||||
|
||||
function queueItems (items) {
|
||||
for (var i = 0, length = items.length; i < length; i++) {
|
||||
self.playlist.push(items[i]);
|
||||
}
|
||||
}
|
||||
|
||||
function queueItemsNext(items) {
|
||||
var insertIndex = 1;
|
||||
for (var i = 0, length = items.length; i < length; i++) {
|
||||
self.playlist.splice(insertIndex, 0, items[i]);
|
||||
insertIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
function translateItemsForPlayback(items) {
|
||||
var deferred = $.Deferred();
|
||||
var firstItem = items[0];
|
||||
var promise;
|
||||
if (firstItem.IsFolder) {
|
||||
promise = self.getItemsForPlayback({
|
||||
ParentId: firstItem.Id,
|
||||
Filters: "IsNotFolder",
|
||||
Recursive: true,
|
||||
SortBy: "SortName",
|
||||
MediaTypes: "Audio,Video"
|
||||
});
|
||||
}
|
||||
else if (firstItem.Type == "MusicArtist") {
|
||||
promise = self.getItemsForPlayback({
|
||||
Artists: firstItem.Name,
|
||||
Filters: "IsNotFolder",
|
||||
Recursive: true,
|
||||
SortBy: "SortName",
|
||||
MediaTypes: "Audio"
|
||||
});
|
||||
}
|
||||
else if (firstItem.Type == "MusicGenre") {
|
||||
promise = self.getItemsForPlayback({
|
||||
Genres: firstItem.Name,
|
||||
Filters: "IsNotFolder",
|
||||
Recursive: true,
|
||||
SortBy: "SortName",
|
||||
MediaTypes: "Audio"
|
||||
});
|
||||
}
|
||||
|
||||
if (promise) {
|
||||
promise.done(function (result) {
|
||||
deferred.resolveWith(null, [result.Items]);
|
||||
});
|
||||
} else {
|
||||
deferred.resolveWith(null, [items]);
|
||||
}
|
||||
|
||||
return deferred.promise();
|
||||
}
|
||||
|
||||
self.play = function (options) {
|
||||
if (self.isPaused) {
|
||||
self.isPaused = !self.isPaused;
|
||||
castPlayer.playMedia();
|
||||
} else if (options.items) {
|
||||
Dashboard.getCurrentUser().done(function (user) {
|
||||
castPlayer.loadMedia(user, options.items[self.playlistIndex++], options.startPositionTicks);
|
||||
});
|
||||
} else {
|
||||
var userId = Dashboard.getCurrentUserId();
|
||||
|
||||
var query = {};
|
||||
query.Limit = query.Limit || 100;
|
||||
query.Fields = getItemFields;
|
||||
query.ExcludeLocationTypes = "Virtual";
|
||||
query.Ids = options.ids.join(',');
|
||||
|
||||
ApiClient.getItems(userId, query).done(function (result) {
|
||||
options.items = result.Items;
|
||||
self.play(options);
|
||||
});
|
||||
}
|
||||
castPlayer.loadMedia(Dashboard.getCurrentUserId(), options, 'PlayNow');
|
||||
};
|
||||
|
||||
self.unpause = function () {
|
||||
@ -1137,8 +1044,7 @@
|
||||
}
|
||||
|
||||
self.getItemsForPlayback(query).done(function (result) {
|
||||
self.playlist = { items: result.Items };
|
||||
self.play(self.playlist);
|
||||
self.play({ items: result.Items });
|
||||
});
|
||||
});
|
||||
};
|
||||
@ -1182,8 +1088,7 @@
|
||||
}
|
||||
|
||||
promise.done(function (result) {
|
||||
self.playlist = { items: result.Items };
|
||||
self.play(self.playlist);
|
||||
self.play({ items: result.Items });
|
||||
});
|
||||
});
|
||||
};
|
||||
@ -1193,41 +1098,14 @@
|
||||
};
|
||||
|
||||
self.queue = function (options) {
|
||||
Dashboard.getCurrentUser().done(function (user) {
|
||||
if (options.items) {
|
||||
translateItemsForPlayback(options.items).done(function (items) {
|
||||
queueItems(items);
|
||||
});
|
||||
} else {
|
||||
getItemsForPlayback({
|
||||
Ids: options.ids.join(',')
|
||||
}).done(function (result) {
|
||||
translateItemsForPlayback(result.Items).done(function (items) {
|
||||
queueItems(items);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
castPlayer.loadMedia(Dashboard.getCurrentUserId(), options, 'PlayLast');
|
||||
};
|
||||
|
||||
self.queueNext = function (options) {
|
||||
Dashboard.getCurrentUser().done(function (user) {
|
||||
if (options.items) {
|
||||
queueItemsNext(options.items);
|
||||
} else {
|
||||
self.getItemsForPlayback({
|
||||
Ids: options.ids.join(',')
|
||||
}).done(function (result) {
|
||||
options.items = result.Items;
|
||||
queueItemsNext(options.items);
|
||||
});
|
||||
}
|
||||
});
|
||||
castPlayer.loadMedia(Dashboard.getCurrentUserId(), options, 'PlayNext');
|
||||
};
|
||||
|
||||
self.stop = function () {
|
||||
self.playlist = [];
|
||||
self.playlistIndex = 0;
|
||||
castPlayer.stopMedia();
|
||||
};
|
||||
|
||||
@ -1285,72 +1163,14 @@
|
||||
};
|
||||
};
|
||||
|
||||
self.setCurrentTime = function (ticks, item, updateSlider) {
|
||||
// Convert to ticks
|
||||
ticks = Math.floor(ticks);
|
||||
var timeText = Dashboard.getDisplayTime(ticks);
|
||||
if (self.currentDurationTicks) {
|
||||
timeText += " / " + Dashboard.getDisplayTime(self.currentDurationTicks);
|
||||
if (updateSlider) {
|
||||
var percent = ticks / self.currentDurationTicks;
|
||||
percent *= 100;
|
||||
self.positionSlider.val(percent).slider('enable').slider('refresh');
|
||||
}
|
||||
} else {
|
||||
self.positionSlider.slider('disable').slider('refresh');
|
||||
}
|
||||
|
||||
self.currentTimeElement.html(timeText);
|
||||
};
|
||||
|
||||
self.changeStream = function (position) {
|
||||
castPlayer.seekMedia(position);
|
||||
};
|
||||
|
||||
self.seek = function (position) {
|
||||
castPlayer.seekMedia(position);
|
||||
};
|
||||
|
||||
self.removeFromPlaylist = function (i) {
|
||||
self.playlist.remove(i);
|
||||
};
|
||||
|
||||
self.currentPlaylistIndex = function (i) {
|
||||
if (i == null) {
|
||||
return currentPlaylistIndex;
|
||||
}
|
||||
|
||||
var newItem = self.playlist[i];
|
||||
|
||||
Dashboard.getCurrentUser().done(function (user) {
|
||||
self.playInternal(newItem, 0, user);
|
||||
currentPlaylistIndex = i;
|
||||
});
|
||||
};
|
||||
|
||||
self.nextTrack = function () {
|
||||
var newIndex = currentPlaylistIndex + 1;
|
||||
var newItem = self.playlist[newIndex];
|
||||
|
||||
if (newItem) {
|
||||
Dashboard.getCurrentUser().done(function (user) {
|
||||
self.playInternal(newItem, 0, user);
|
||||
currentPlaylistIndex = newIndex;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
self.previousTrack = function () {
|
||||
var newIndex = currentPlaylistIndex - 1;
|
||||
if (newIndex >= 0) {
|
||||
var newItem = self.playlist[newIndex];
|
||||
if (newItem) {
|
||||
Dashboard.getCurrentUser().done(function (user) {
|
||||
self.playInternal(newItem, 0, user);
|
||||
currentPlaylistIndex = newIndex;
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
self.beginPlayerUpdates = function () {
|
||||
@ -1391,7 +1211,7 @@
|
||||
var state = {
|
||||
PlayState: {
|
||||
|
||||
CanSeek: self.positionTicks < self.runtimeTicks,
|
||||
CanSeek: self.runtimeTicks && self.positionTicks > 0,
|
||||
PositionTicks: self.positionTicks,
|
||||
VolumeLevel: castPlayer.currentVolume * 100,
|
||||
IsPaused: self.isPaused,
|
||||
@ -1440,16 +1260,16 @@
|
||||
};
|
||||
}
|
||||
|
||||
//MediaController.registerPlayer(new chromecastPlayer());
|
||||
MediaController.registerPlayer(new chromecastPlayer());
|
||||
|
||||
//$(MediaController).on('playerchange', function () {
|
||||
$(MediaController).on('playerchange', function () {
|
||||
|
||||
// if (MediaController.getPlayerInfo().name == PlayerName) {
|
||||
if (MediaController.getPlayerInfo().name == PlayerName) {
|
||||
|
||||
// if (castPlayer.deviceState != DEVICE_STATE.ACTIVE && castPlayer.isInitialized) {
|
||||
// castPlayer.launchApp();
|
||||
// }
|
||||
// }
|
||||
//});
|
||||
if (CastPlayer.deviceState != DEVICE_STATE.ACTIVE && CastPlayer.isInitialized) {
|
||||
CastPlayer.launchApp();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
})(window, window.chrome, console);
|
@ -365,7 +365,7 @@
|
||||
|
||||
var time = self.currentDurationTicks * (Number(pct) * .01);
|
||||
|
||||
var tooltext = Dashboard.getDisplayTime(time)
|
||||
var tooltext = Dashboard.getDisplayTime(time);
|
||||
|
||||
tooltip.text(tooltext);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user