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

@@ -369,6 +369,16 @@ class ClapperPlayer extends GstClapper.Clapper
this[action]();
}
next_chapter()
{
return this._switchChapter(false);
}
prev_chapter()
{
return this._switchChapter(true);
}
emitWs(action, value)
{
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)
{
for(let source of playlist) {