mirror of
https://gitlab.com/futo-org/fcast.git
synced 2025-08-21 14:52:50 +00:00
Receivers: Send playback update on playlist index change
This commit is contained in:
parent
1622a9b752
commit
fdbefc63e0
2 changed files with 29 additions and 6 deletions
|
@ -106,7 +106,14 @@ function formatDuration(duration: number) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendPlaybackUpdate(updateState: PlaybackState) {
|
function sendPlaybackUpdate(updateState: PlaybackState) {
|
||||||
const updateMessage = new PlaybackUpdateMessage(Date.now(), updateState, player?.getCurrentTime(), player?.getDuration(), player?.getPlaybackRate());
|
const updateMessage = new PlaybackUpdateMessage(
|
||||||
|
Date.now(),
|
||||||
|
updateState,
|
||||||
|
player?.getCurrentTime(),
|
||||||
|
player?.getDuration(),
|
||||||
|
player?.getPlaybackRate(),
|
||||||
|
isMediaItem ? playlistIndex : null
|
||||||
|
);
|
||||||
playbackState = updateState;
|
playbackState = updateState;
|
||||||
|
|
||||||
if (updateMessage.generationTime > lastPlayerUpdateGenerationTime) {
|
if (updateMessage.generationTime > lastPlayerUpdateGenerationTime) {
|
||||||
|
@ -386,6 +393,7 @@ function setPlaylistItem(index: number) {
|
||||||
playlistIndex = index;
|
playlistIndex = index;
|
||||||
cachedPlayMediaItem = cachedPlaylist.items[playlistIndex];
|
cachedPlayMediaItem = cachedPlaylist.items[playlistIndex];
|
||||||
playItemCached = true;
|
playItemCached = true;
|
||||||
|
sendPlaybackUpdate(playbackState);
|
||||||
window.targetAPI.sendPlayRequest(playMessageFromMediaItem(cachedPlaylist.items[playlistIndex]), playlistIndex);
|
window.targetAPI.sendPlayRequest(playMessageFromMediaItem(cachedPlaylist.items[playlistIndex]), playlistIndex);
|
||||||
showDurationTimer.stop();
|
showDurationTimer.stop();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { EventMessage, EventType, GenericMediaMetadata, KeyEvent, MediaItem, MediaItemEvent, MetadataType, PlaybackState, PlaylistContent, PlayMessage, SeekMessage, SetPlaylistItemMessage, SetSpeedMessage, SetVolumeMessage } from 'common/Packets';
|
import { EventMessage, EventType, GenericMediaMetadata, KeyEvent, MediaItem, MediaItemEvent, MetadataType, PlaybackState, PlaylistContent, PlayMessage, SeekMessage, SetPlaylistItemMessage, SetSpeedMessage, SetVolumeMessage, PlaybackUpdateMessage } from 'common/Packets';
|
||||||
import { mediaItemFromPlayMessage, playMessageFromMediaItem, Timer } from 'common/UtilityFrontend';
|
import { mediaItemFromPlayMessage, playMessageFromMediaItem, Timer } from 'common/UtilityFrontend';
|
||||||
import { supportedImageTypes } from 'common/MimeTypes';
|
import { supportedImageTypes } from 'common/MimeTypes';
|
||||||
import * as connectionMonitor from 'common/ConnectionMonitor';
|
import * as connectionMonitor from 'common/ConnectionMonitor';
|
||||||
|
@ -54,10 +54,24 @@ let showDurationTimer = new Timer(() => {
|
||||||
idleIcon.style.display = 'block';
|
idleIcon.style.display = 'block';
|
||||||
|
|
||||||
playerCtrlAction.setAttribute("class", "play iconSize");
|
playerCtrlAction.setAttribute("class", "play iconSize");
|
||||||
imageViewerPlaybackState = PlaybackState.Idle;
|
sendPlaybackUpdate(PlaybackState.Idle);
|
||||||
}
|
}
|
||||||
}, 0, false);
|
}, 0, false);
|
||||||
|
|
||||||
|
function sendPlaybackUpdate(updateState: PlaybackState) {
|
||||||
|
const updateMessage = new PlaybackUpdateMessage(
|
||||||
|
Date.now(),
|
||||||
|
updateState,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
isMediaItem ? playlistIndex : null
|
||||||
|
);
|
||||||
|
imageViewerPlaybackState = updateState;
|
||||||
|
|
||||||
|
window.targetAPI.sendPlaybackUpdate(updateMessage);
|
||||||
|
};
|
||||||
|
|
||||||
function onPlay(_event, value: PlayMessage) {
|
function onPlay(_event, value: PlayMessage) {
|
||||||
if (isPlaylistPlayRequestCounter === 0) {
|
if (isPlaylistPlayRequestCounter === 0) {
|
||||||
cachedPlayMediaItem = mediaItemFromPlayMessage(value);
|
cachedPlayMediaItem = mediaItemFromPlayMessage(value);
|
||||||
|
@ -161,6 +175,7 @@ function setPlaylistItem(index: number) {
|
||||||
playlistIndex = index;
|
playlistIndex = index;
|
||||||
cachedPlayMediaItem = cachedPlaylist.items[playlistIndex];
|
cachedPlayMediaItem = cachedPlaylist.items[playlistIndex];
|
||||||
isPlaylistPlayRequestCounter++;
|
isPlaylistPlayRequestCounter++;
|
||||||
|
sendPlaybackUpdate(imageViewerPlaybackState);
|
||||||
window.targetAPI.sendPlayRequest(playMessageFromMediaItem(cachedPlaylist.items[playlistIndex]), playlistIndex);
|
window.targetAPI.sendPlayRequest(playMessageFromMediaItem(cachedPlaylist.items[playlistIndex]), playlistIndex);
|
||||||
showDurationTimer.stop();
|
showDurationTimer.stop();
|
||||||
}
|
}
|
||||||
|
@ -222,7 +237,7 @@ function playerCtrlStateUpdate(event: PlayerControlEvent) {
|
||||||
if (imageViewerPlaybackState === PlaybackState.Idle || imageViewerPlaybackState === PlaybackState.Playing) {
|
if (imageViewerPlaybackState === PlaybackState.Idle || imageViewerPlaybackState === PlaybackState.Playing) {
|
||||||
showDurationTimer.start(cachedPlayMediaItem.showDuration * 1000);
|
showDurationTimer.start(cachedPlayMediaItem.showDuration * 1000);
|
||||||
playerCtrlAction.setAttribute("class", "pause iconSize");
|
playerCtrlAction.setAttribute("class", "pause iconSize");
|
||||||
imageViewerPlaybackState = PlaybackState.Playing;
|
sendPlaybackUpdate(PlaybackState.Playing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -251,7 +266,7 @@ function playerCtrlStateUpdate(event: PlayerControlEvent) {
|
||||||
|
|
||||||
case PlayerControlEvent.Pause:
|
case PlayerControlEvent.Pause:
|
||||||
playerCtrlAction.setAttribute("class", "play iconSize");
|
playerCtrlAction.setAttribute("class", "play iconSize");
|
||||||
imageViewerPlaybackState = PlaybackState.Paused;
|
sendPlaybackUpdate(PlaybackState.Paused);
|
||||||
showDurationTimer.pause();
|
showDurationTimer.pause();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -269,7 +284,7 @@ function playerCtrlStateUpdate(event: PlayerControlEvent) {
|
||||||
showDurationTimer.start(cachedPlayMediaItem.showDuration * 1000);
|
showDurationTimer.start(cachedPlayMediaItem.showDuration * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
imageViewerPlaybackState = PlaybackState.Playing;
|
sendPlaybackUpdate(PlaybackState.Playing);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue