diff --git a/src/actions.js b/src/actions.js index 4513e714..b9afd3cf 100644 --- a/src/actions.js +++ b/src/actions.js @@ -22,5 +22,13 @@ var actions = { prev_track: { run: (window) => window.child.player.playlistWidget.prevTrack(), accels: ['Left'], + }, + next_chapter: { + run: (window) => window.child.player.next_chapter(), + accels: ['Right'], + }, + prev_chapter: { + run: (window) => window.child.player.prev_chapter(), + accels: ['Left'], } }; diff --git a/src/player.js b/src/player.js index a23a272e..90e565ca 100644 --- a/src/player.js +++ b/src/player.js @@ -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) {