mirror of
https://github.com/jellyfin/jellyfin-web.git
synced 2024-11-16 18:38:25 -07:00
Transfer whole playlist when transfer playback to another device
This commit is contained in:
parent
59dd84b2ee
commit
67da5e49ab
@ -1,47 +1,45 @@
|
||||
define(['events', 'playbackManager'], function (events, playbackManager) {
|
||||
'use strict';
|
||||
import events from 'events';
|
||||
import playbackManager from 'playbackManager';
|
||||
|
||||
function transferPlayback(oldPlayer, newPlayer) {
|
||||
function transferPlayback(oldPlayer, newPlayer) {
|
||||
const state = playbackManager.getPlayerState(oldPlayer);
|
||||
const item = state.NowPlayingItem;
|
||||
|
||||
var state = playbackManager.getPlayerState(oldPlayer);
|
||||
|
||||
var item = state.NowPlayingItem;
|
||||
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
var playState = state.PlayState || {};
|
||||
var resumePositionTicks = playState.PositionTicks || 0;
|
||||
|
||||
playbackManager.stop(oldPlayer).then(function () {
|
||||
|
||||
playbackManager.play({
|
||||
ids: [item.Id],
|
||||
serverId: item.ServerId,
|
||||
startPositionTicks: resumePositionTicks
|
||||
|
||||
}, newPlayer);
|
||||
});
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
events.on(playbackManager, 'playerchange', function (e, newPlayer, newTarget, oldPlayer) {
|
||||
const playlist = playbackManager.getPlaylist(oldPlayer).then(playlist => {
|
||||
const playlistIds = playlist.map(x => x.Id);
|
||||
const playState = state.PlayState || {};
|
||||
const resumePositionTicks = playState.PositionTicks || 0;
|
||||
const playlistIndex = playlistIds.indexOf(item.Id) || 0;
|
||||
|
||||
if (!oldPlayer || !newPlayer) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!oldPlayer.isLocalPlayer) {
|
||||
console.debug('Skipping remote control autoplay because oldPlayer is not a local player');
|
||||
return;
|
||||
}
|
||||
|
||||
if (newPlayer.isLocalPlayer) {
|
||||
console.debug('Skipping remote control autoplay because newPlayer is a local player');
|
||||
return;
|
||||
}
|
||||
|
||||
transferPlayback(oldPlayer, newPlayer);
|
||||
playbackManager.stop(oldPlayer).then(() => {
|
||||
playbackManager.play({
|
||||
ids: playlistIds,
|
||||
serverId: item.ServerId,
|
||||
startPositionTicks: resumePositionTicks,
|
||||
startIndex: playlistIndex
|
||||
}, newPlayer);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
events.on(playbackManager, 'playerchange', (e, newPlayer, newTarget, oldPlayer) => {
|
||||
if (!oldPlayer || !newPlayer) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!oldPlayer.isLocalPlayer) {
|
||||
console.debug('Skipping remote control autoplay because oldPlayer is not a local player');
|
||||
return;
|
||||
}
|
||||
|
||||
if (newPlayer.isLocalPlayer) {
|
||||
console.debug('Skipping remote control autoplay because newPlayer is a local player');
|
||||
return;
|
||||
}
|
||||
|
||||
transferPlayback(oldPlayer, newPlayer);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user