Repeat track if going back when less than 5 seconds of the item has been playing

This commit is contained in:
ferferga 2020-06-17 21:02:50 +02:00
parent e2f61c67b9
commit 4159268949
2 changed files with 26 additions and 11 deletions

View File

@ -117,8 +117,13 @@ define(['require', 'datetime', 'itemHelper', 'events', 'browser', 'imageLoader',
nowPlayingImageElement = elem.querySelector('.nowPlayingImage');
nowPlayingTextElement = elem.querySelector('.nowPlayingBarText');
nowPlayingUserData = elem.querySelector('.nowPlayingBarUserDataButtons');
positionSlider = elem.querySelector('.nowPlayingBarPositionSlider');
muteButton = elem.querySelector('.muteButton');
playPauseButtons = elem.querySelectorAll('.playPauseButton');
toggleRepeatButton = elem.querySelector('.toggleRepeatButton');
volumeSlider = elem.querySelector('.nowPlayingBarVolumeSlider');
volumeSliderContainer = elem.querySelector('.nowPlayingBarVolumeSliderContainer');
muteButton.addEventListener('click', function () {
if (currentPlayer) {
@ -134,7 +139,6 @@ define(['require', 'datetime', 'itemHelper', 'events', 'browser', 'imageLoader',
}
});
playPauseButtons = elem.querySelectorAll('.playPauseButton');
playPauseButtons.forEach((button) => {
button.addEventListener('click', onPlayPauseClick);
});
@ -147,9 +151,15 @@ define(['require', 'datetime', 'itemHelper', 'events', 'browser', 'imageLoader',
});
elem.querySelector('.previousTrackButton').addEventListener('click', function () {
if (currentPlayer) {
playbackManager.previousTrack(currentPlayer);
if (currentPlayer.id === 'htmlaudioplayer' && (currentPlayer._currentTime <= 5 || !playbackManager.previousTrack(currentPlayer))) {
playbackManager.seekPercent(0, currentPlayer);
// This is done automatically by playbackManager, however, setting this here
// gives instant visual feedback
positionSlider.value = 0;
} else {
playbackManager.previousTrack(currentPlayer);
}
}
});
@ -174,9 +184,6 @@ define(['require', 'datetime', 'itemHelper', 'events', 'browser', 'imageLoader',
toggleRepeatButtonIcon = toggleRepeatButton.querySelector('.material-icons');
volumeSlider = elem.querySelector('.nowPlayingBarVolumeSlider');
volumeSliderContainer = elem.querySelector('.nowPlayingBarVolumeSliderContainer');
if (appHost.supports('physicalvolumecontrol')) {
volumeSliderContainer.classList.add('hide');
} else {
@ -193,7 +200,6 @@ define(['require', 'datetime', 'itemHelper', 'events', 'browser', 'imageLoader',
volumeSlider.addEventListener('mousemove', setVolume);
volumeSlider.addEventListener('touchmove', setVolume);
positionSlider = elem.querySelector('.nowPlayingBarPositionSlider');
positionSlider.addEventListener('change', function () {
if (currentPlayer) {

View File

@ -606,6 +606,7 @@ define(['browser', 'datetime', 'backdrop', 'libraryBrowser', 'listView', 'imageL
function bindEvents(context) {
var btnCommand = context.querySelectorAll('.btnCommand');
var positionSlider = context.querySelector('.nowPlayingPositionSlider');
for (var i = 0, length = btnCommand.length; i < length; i++) {
btnCommand[i].addEventListener('click', onBtnCommandClick);
@ -654,11 +655,19 @@ define(['browser', 'datetime', 'backdrop', 'libraryBrowser', 'listView', 'imageL
}
});
context.querySelector('.btnPreviousTrack').addEventListener('click', function () {
console.log(currentPlayer);
if (currentPlayer) {
playbackManager.previousTrack(currentPlayer);
if (currentPlayer.id === 'htmlaudioplayer' && (currentPlayer._currentTime <= 5 || !playbackManager.previousTrack(currentPlayer))) {
playbackManager.seekPercent(0, currentPlayer);
// This is done automatically by playbackManager. However, setting this here
// gives instant visual feedback
positionSlider.value = 0;
} else {
playbackManager.previousTrack(currentPlayer);
}
}
});
context.querySelector('.nowPlayingPositionSlider').addEventListener('change', function () {
positionSlider.addEventListener('change', function () {
var value = this.value;
if (currentPlayer) {
@ -667,7 +676,7 @@ define(['browser', 'datetime', 'backdrop', 'libraryBrowser', 'listView', 'imageL
}
});
context.querySelector('.nowPlayingPositionSlider').getBubbleText = function (value) {
positionSlider.getBubbleText = function (value) {
var state = lastPlayerState;
if (!state || !state.NowPlayingItem || !currentRuntimeTicks) {