Use Shift+Left/Right to switch video chapters

This commit is contained in:
Rafał Dzięgiel
2021-04-22 14:40:21 +02:00
parent edfa85b5cc
commit bd13a3c15a
2 changed files with 42 additions and 0 deletions

View File

@@ -22,5 +22,13 @@ var actions = {
prev_track: { prev_track: {
run: (window) => window.child.player.playlistWidget.prevTrack(), run: (window) => window.child.player.playlistWidget.prevTrack(),
accels: ['<Ctrl>Left'], accels: ['<Ctrl>Left'],
},
next_chapter: {
run: (window) => window.child.player.next_chapter(),
accels: ['<Shift>Right'],
},
prev_chapter: {
run: (window) => window.child.player.prev_chapter(),
accels: ['<Shift>Left'],
} }
}; };

View File

@@ -369,6 +369,16 @@ class ClapperPlayer extends GstClapper.Clapper
this[action](); this[action]();
} }
next_chapter()
{
return this._switchChapter(false);
}
prev_chapter()
{
return this._switchChapter(true);
}
emitWs(action, value) emitWs(action, value)
{ {
if(!this.webserver) if(!this.webserver)
@@ -409,6 +419,30 @@ class ClapperPlayer extends GstClapper.Clapper
} }
} }
_switchChapter(isPrevious)
{
if(this.state === GstClapper.ClapperState.STOPPED)
return false;
const { chapters } = this.widget.root.child.controls;
if(!chapters)
return false;
const now = this.position / Gst.SECOND;
let chapterTimes = Object.keys(chapters);
if(isPrevious)
chapterTimes.reverse();
const chapter = chapterTimes.find(time => (isPrevious)
? now - 2.5 > time
: now < time
);
if(!chapter)
return false;
this.seek_chapter(chapter);
}
_addPlaylistItems(playlist) _addPlaylistItems(playlist)
{ {
for(let source of playlist) { for(let source of playlist) {