fix playback

This commit is contained in:
cvium 2019-01-13 14:34:23 +01:00
parent f58c896435
commit 5113f1aef2
4 changed files with 62 additions and 80 deletions

4
app.js
View File

@ -27,10 +27,6 @@ window.VolumeInfo = {
Level: 100
};
function clearMediaElement() {
document.getElementById('video-player').src = "";
}
function broadcastToMessageBus(msg) {
window.castReceiverContext.sendCustomMessage('urn:x-cast:com.jellyfin.cast', window.senderId, msg);

View File

@ -130,7 +130,7 @@
}
var url = getUrl($scope.serverAddress, "Sessions/Playing/Progress");
debugger;
restartPingInterval($scope, options);
lastTranscoderPing = new Date().getTime();
@ -412,7 +412,8 @@
factory.reportPlaybackStart($scope, getReportingParams($scope)).then(function () {
console.log('calling mediaElement.play');
window.mediaElement.play();
debugger;
window.mediaManager.play();
setAppStatus('playing-with-controls');
if ($scope.mediaType == "Audio") {
setAppStatus('audio');
@ -433,17 +434,7 @@
setTimeout(function () {
var startTime = new Date();
window.mediaElement.play();
window.mediaElement.pause();
while (typeof (window.mediaElement.buffered) === 'undefined' || window.mediaElement.buffered.length === 0) {
if ((new Date()) - startTime > 25000) {
setAppStatus('waiting');
factory.setApplicationClose();
return;
}
}
window.mediaManager.defaultOnPlay(event);
window.mediaManager.play();
setAppStatus('playing-with-controls');
if ($scope.mediaType == "Audio") {

View File

@ -2,6 +2,18 @@
window.castReceiverContext = cast.framework.CastReceiverContext.getInstance();
window.mediaManager = window.castReceiverContext.getPlayerManager();
window.mediaManager.addEventListener(cast.framework.events.category.CORE,
event => {
console.log("Core event: " + event.type);
console.log(event);
});
const playbackConfig = new cast.framework.PlaybackConfig();
// Set the player to start playback as soon as there are five seconds of
// media content buffered. Default is 10.
playbackConfig.autoResumeDuration = 5;
setInterval(updateTimeOfDay, 40000);
// According to cast docs this should be disabled when not needed
@ -10,7 +22,6 @@
var init = function () {
resetPlaybackScope($scope);
clearMediaElement();
};
init();
@ -22,7 +33,6 @@
var broadcastToServer = new Date();
function onMediaElementTimeUpdate(e) {
if ($scope.isChangingStream) {
return;
}
@ -32,12 +42,12 @@
var elapsed = now - broadcastToServer;
if (elapsed > 5000) {
// TODO use status as input
embyActions.reportPlaybackProgress($scope, getReportingParams($scope));
broadcastToServer = now;
}
else if (elapsed > 1500) {
// TODO use status as input
embyActions.reportPlaybackProgress($scope, getReportingParams($scope), false);
}
}
@ -71,20 +81,20 @@
function enableTimeUpdateListener(enabled) {
if (enabled) {
window.mediaElement.addEventListener('timeupdate', onMediaElementTimeUpdate);
window.mediaElement.addEventListener('volumechange', onMediaElementVolumeChange);
window.mediaElement.addEventListener('pause', onMediaElementPause);
window.mediaElement.addEventListener('playing', onMediaElementPlaying);
window.mediaManager.addEventListener(cast.framework.events.EventType.TIME_UPDATE, onMediaElementTimeUpdate);
window.mediaManager.addEventListener(cast.framework.events.EventType.REQUEST_VOLUME_CHANGE, onMediaElementVolumeChange);
window.mediaManager.addEventListener(cast.framework.events.EventType.PAUSE, onMediaElementPause);
window.mediaManager.addEventListener(cast.framework.events.EventType.PLAYING, onMediaElementPlaying);
} else {
window.mediaElement.removeEventListener('timeupdate', onMediaElementTimeUpdate);
window.mediaElement.removeEventListener('volumechange', onMediaElementVolumeChange);
window.mediaElement.removeEventListener('pause', onMediaElementPause);
window.mediaElement.removeEventListener('playing', onMediaElementPlaying);
window.mediaManager.removeEventListener(cast.framework.events.EventType.TIME_UPDATE, onMediaElementTimeUpdate);
window.mediaManager.removeEventListener(cast.framework.events.EventType.REQUEST_VOLUME_CHANGE, onMediaElementVolumeChange);
window.mediaManager.removeEventListener(cast.framework.events.EventType.PAUSE, onMediaElementPause);
window.mediaManager.removeEventListener(cast.framework.events.EventType.PLAYING, onMediaElementPlaying);
}
}
function isPlaying() {
return window.playlist.length > 0;
return window.mediaManager.getPlayerState() === cast.framework.messages.PlayerState.PLAYING;
}
window.addEventListener('beforeunload', function () {
@ -94,26 +104,25 @@
embyActions.reportPlaybackStopped($scope, getReportingParams($scope));
});
mgr.defaultOnPlay = mgr.onPlay;
mgr.onPlay = function (event) {
mgr.defaultOnPlay = function (event) {
embyActions.play($scope, event);
embyActions.reportPlaybackProgress($scope, getReportingParams($scope));
};
mgr.addEventListener('PLAY', mgr.defaultOnPlay);
mgr.defaultOnPause = mgr.onPause;
mgr.onPause = function (event) {
mgr.defaultOnPause(event);
mgr.defaultOnPause = function (event) {
embyActions.pause($scope);
embyActions.reportPlaybackProgress($scope, getReportingParams($scope));
};
mgr.addEventListener('PAUSE', mgr.defaultOnPause);
mgr.defaultOnStop = mgr.onStop;
mgr.onStop = function (event) {
mgr.defaultOnStop = function (event) {
stop();
};
mgr.addEventListener('ABORT', mgr.defaultOnStop);
mgr.onEnded = function () {
mgr.addEventListener('ENDED', function () {
// Ignore
if ($scope.isChangingStream) {
@ -130,7 +139,7 @@
window.currentPlaylistIndex = -1;
embyActions.displayUserInfo($scope, $scope.serverAddress, $scope.accessToken, $scope.userId);
}
};
});
function stop(nextMode) {
@ -148,15 +157,14 @@
promise = embyActions.reportPlaybackStopped($scope, reportingParams);
}
clearMediaElement();
promise = promise || Promise.resolve();
return promise;
}
window.castReceiverContext.onSystemVolumeChanged = function (event) {
console.log("### Cast Receiver Manager - System Volume Changed : " + JSON.stringify(event));
window.castReceiverContext.addEventListener(cast.framework.system.EventType.SYSTEM_VOLUME_CHANGED, function (event) {
debugger;
console.log("### Cast Receiver Manager - System Volume Changed : " + JSON.stringify(event.data));
// See cast.receiver.media.Volume
console.log("### Volume: " + event.data['level'] + " is muted? " + event.data['muted']);
@ -167,7 +175,7 @@
if ($scope.userId != null) {
reportEvent('volumechange', true);
}
};
});
console.log('Application is ready, starting system');
@ -291,10 +299,10 @@
}
else if (data.command == 'PlayPause') {
if (window.mediaElement.paused) {
window.mediaElement.play();
if (window.mediaManager.getPlayerState() === cast.framework.messages.PlayerState.PAUSED) {
window.mediaManager.play();
} else {
window.mediaElement.pause();
window.mediaManager.pause();
}
}
else if (data.command == 'Pause') {
@ -390,6 +398,7 @@
}
function changeStream(ticks, params) {
debugger;
if (ticks) {
ticks = parseInt(ticks);
@ -462,28 +471,6 @@
}
}
function setSrcIntoRenderer(streamInfo) {
var url = streamInfo.url;
console.log('new media url: ' + url);
window.mediaElement.src = url;
window.mediaElement.autoplay = true;
setStartPositionTicks(streamInfo.startPositionTicks || 0);
window.mediaElement.play();
$scope.mediaSource = streamInfo.mediaSource;
setTextTrack($scope, streamInfo.subtitleStreamUrl);
setTimeout(function () {
$scope.isChangingStream = false;
}, 1000);
}
// Create a message handler for the custome namespace channel
// TODO save namespace somewhere global?
window.castReceiverContext.addCustomMessageListener('urn:x-cast:com.jellyfin.cast', function(evt) {
@ -893,10 +880,11 @@
var loadRequestData = new cast.framework.messages.LoadRequestData();
loadRequestData.media = mediaInfo;
loadRequestData.autoplay = true;
loadRequestData.autoplay = false;
embyActions.load($scope, mediaInfo.customData, item);
window.mediaManager.load(loadRequestData);
$scope.PlaybackMediaSource = mediaSource;
var autoplay = true;
@ -912,7 +900,7 @@
if (autoplay) {
//window.mediaElement.pause();
console.log('calling embyActions.delayStart');
//embyActions.delayStart($scope);
embyActions.delayStart($scope);
}
enableTimeUpdateListener(false);
enableTimeUpdateListener(true);

View File

@ -17,7 +17,7 @@ function getUrl(serverAddress, name) {
function getCurrentPositionTicks($scope) {
var positionTicks = window.mediaElement.currentTime * 10000000;
var positionTicks = window.mediaManager.getCurrentTimeSec() * 10000000;
if (!$scope.canClientSeek) {
@ -28,14 +28,14 @@ function getCurrentPositionTicks($scope) {
}
function getReportingParams($scope) {
var volumeInfo = window.castReceiverContext.getSystemVolume();
return {
PositionTicks: getCurrentPositionTicks($scope),
IsPaused: window.mediaElement.paused,
IsMuted: window.VolumeInfo.IsMuted,
IsPaused: window.mediaManager.getPlayerState() === cast.framework.messages.PlayerState.PAUSED,
IsMuted: volumeInfo.muted,
AudioStreamIndex: $scope.audioStreamIndex,
SubtitleStreamIndex: $scope.subtitleStreamIndex,
VolumeLevel: window.VolumeInfo.Level,
VolumeLevel: volumeInfo.Level,
ItemId: $scope.itemId,
MediaSourceId: $scope.mediaSourceId,
QueueableMediaTypes: ['Audio', 'Video'],
@ -90,7 +90,7 @@ function getNextPlaybackItemInfo() {
}
function getSenderReportingData($scope, reportingData) {
debugger;
var state = {
ItemId: reportingData.ItemId,
PlayState: extend({}, reportingData),
@ -451,19 +451,26 @@ function createStreamInfo(item, mediaSource, startPosition) {
if (info.subtitleStreamIndex != null) {
debugger;
var subtitleStream = mediaSource.MediaStreams.find(function (stream) { return stream.Type === "Subtitle"; });
var subtitleStreams = mediaSource.MediaStreams.filter(function (stream) { return stream.Type === "Subtitle"; });
var subtitleTracks = []
//getStreamByIndex(mediaSource.MediaStreams, 'Subtitle', info.subtitleStreamIndex);
if (subtitleStream) { // && subtitleStream.DeliveryMethod == 'External') {
subtitleStreams.forEach(function(subtitleStream) {
// && subtitleStream.DeliveryMethod == 'External') {
//var textStreamUrl = subtitleStream.IsExternalUrl ? subtitleStream.DeliveryUrl : (getUrl(item.serverAddress, subtitleStream.DeliveryUrl));
//info.subtitleStreamUrl = textStreamUrl;
var track = new cast.framework.messages.Track(info.subtitleStreamIndex, 'TEXT')
track.trackId = subtitleStream.Index;
track.language = subtitleStream.Language;
track.name = subtitleStream.DisplayTitle;
track.subtype = "SUBTITLES";
info.tracks = [track]
subtitleTracks.push(track)
console.log('Subtitle url: ' + info.subtitleStreamUrl);
});
if (subtitleTracks) {
info.tracks = subtitleTracks;
}
}