jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/playback/remotecontrolautoplay.js

48 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-01-02 23:51:36 -07:00
define(['events', 'playbackManager'], function (events, playbackManager) {
2016-10-22 22:11:46 -07:00
'use strict';
2015-12-25 21:08:25 -07:00
2017-01-02 23:51:36 -07:00
function transferPlayback(oldPlayer, newPlayer) {
2015-12-25 21:08:25 -07:00
2017-01-04 22:22:32 -07:00
playbackManager.getPlayerState(oldPlayer).then(function (state) {
2015-12-25 21:08:25 -07:00
var item = state.NowPlayingItem;
if (!item) {
return;
}
var playState = state.PlayState || {};
2017-01-04 22:22:32 -07:00
playbackManager.stop(oldPlayer);
2015-12-25 21:08:25 -07:00
var itemId = item.Id;
var resumePositionTicks = playState.PositionTicks || 0;
2017-01-02 23:51:36 -07:00
playbackManager.play({
2015-12-25 21:08:25 -07:00
ids: [itemId],
startPositionTicks: resumePositionTicks
2017-01-04 22:22:32 -07:00
}, newPlayer);
2015-12-25 21:08:25 -07:00
});
}
2017-01-02 23:51:36 -07:00
events.on(playbackManager, 'playerchange', function (e, newPlayer, newTarget, oldPlayer) {
2015-12-25 21:08:25 -07:00
2017-01-02 23:51:36 -07:00
if (!oldPlayer || !newPlayer) {
2015-12-25 21:08:25 -07:00
return;
}
if (!oldPlayer.isLocalPlayer) {
console.log('Skipping remote control autoplay because oldPlayer is not a local player');
return;
}
if (newPlayer.isLocalPlayer) {
console.log('Skipping remote control autoplay because newPlayer is a local player');
return;
}
2017-01-04 22:22:32 -07:00
transferPlayback(oldPlayer, newPlayer);
2015-12-25 21:08:25 -07:00
});
2016-05-05 19:55:15 -07:00
});