Sleep timer
This commit is contained in:
parent
e146239305
commit
e271291f92
3 changed files with 61 additions and 0 deletions
|
@ -116,6 +116,9 @@ MediaPlayer {
|
||||||
} else {
|
} else {
|
||||||
sendPositionToCore(lastPosition);
|
sendPositionToCore(lastPosition);
|
||||||
savePlaybackAfterStopTimer.restart();
|
savePlaybackAfterStopTimer.restart();
|
||||||
|
if (sleepTimerRunning) {
|
||||||
|
stopSleepTimer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,6 +126,37 @@ MediaPlayer {
|
||||||
py.call('main.save_playback_state', []);
|
py.call('main.save_playback_state', []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
property var durationChoices: ([5, 15, 30, 45, 60])
|
||||||
|
|
||||||
|
function startSleepTimer(seconds) {
|
||||||
|
sleepTimer.running = false;
|
||||||
|
sleepTimer.secondsRemaining = seconds;
|
||||||
|
sleepTimer.running = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopSleepTimer() {
|
||||||
|
sleepTimer.running = false;
|
||||||
|
sleepTimer.secondsRemaining = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
property bool sleepTimerRunning: sleepTimer.running
|
||||||
|
property int sleepTimerRemaining: sleepTimer.secondsRemaining
|
||||||
|
|
||||||
|
property var sleepTimer: Timer {
|
||||||
|
property int secondsRemaining: 0
|
||||||
|
|
||||||
|
interval: 1000
|
||||||
|
repeat: true
|
||||||
|
onTriggered: {
|
||||||
|
secondsRemaining -= 1;
|
||||||
|
|
||||||
|
if (secondsRemaining <= 0) {
|
||||||
|
player.pause();
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
property var savePlaybackPositionTimer: Timer {
|
property var savePlaybackPositionTimer: Timer {
|
||||||
// Save position every minute during playback
|
// Save position every minute during playback
|
||||||
interval: 60 * 1000
|
interval: 60 * 1000
|
||||||
|
|
|
@ -141,6 +141,32 @@ SlidePage {
|
||||||
onClicked: player.seekAndSync(player.position + 60 * 1000);
|
onClicked: player.seekAndSync(player.position + 60 * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IconMenuItem {
|
||||||
|
text: player.sleepTimerRunning ? Util.formatDuration(player.sleepTimerRemaining) : 'Sleep'
|
||||||
|
alwaysShowText: player.sleepTimerRunning
|
||||||
|
color: Constants.colors.playback
|
||||||
|
icon: Icons.sleep
|
||||||
|
onClicked: {
|
||||||
|
if (player.sleepTimerRunning) {
|
||||||
|
player.stopSleepTimer();
|
||||||
|
} else {
|
||||||
|
var options = [];
|
||||||
|
var durations_minutes = player.durationChoices;
|
||||||
|
for (var i=0; i<durations_minutes.length; i++) {
|
||||||
|
(function (minutes) {
|
||||||
|
options.push({
|
||||||
|
label: '' + minutes + ' minutes',
|
||||||
|
callback: function () {
|
||||||
|
player.startSleepTimer(60 * minutes);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})(durations_minutes[i]);
|
||||||
|
}
|
||||||
|
pgst.showSelection(options, 'Sleep timer', undefined, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
IconMenuItem {
|
IconMenuItem {
|
||||||
text: 'Chapters'
|
text: 'Chapters'
|
||||||
color: Constants.colors.playback
|
color: Constants.colors.playback
|
||||||
|
|
|
@ -23,3 +23,4 @@ var vellipsis = '\u22ee';
|
||||||
var paperclip = '\ue08a';
|
var paperclip = '\ue08a';
|
||||||
var tag_fill = '\ue02b';
|
var tag_fill = '\ue02b';
|
||||||
var headphones = '\ue061';
|
var headphones = '\ue061';
|
||||||
|
var sleep = '\u263e';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue