From 51155004434555e5cc537e8e9e742c76a0271f03 Mon Sep 17 00:00:00 2001 From: Patrick Farwick <9168045+MinecraftPlaye@users.noreply.github.com> Date: Sun, 3 Oct 2021 19:18:30 +0000 Subject: [PATCH 1/4] Save progress when reading a comic book archive --- CONTRIBUTORS.md | 1 + src/plugins/comicsPlayer/plugin.js | 62 ++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 47013eab1..f0eb21e6d 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -49,6 +49,7 @@ - [Ömer Erdinç Yağmurlu](https://github.com/omeryagmurlu) - [Keegan Dahm](https://github.com/keegandahm) - [GodTamIt](https://github.com/GodTamIt) + - [MinecraftPlaye](https://github.com/MinecraftPlaye) # Emby Contributors diff --git a/src/plugins/comicsPlayer/plugin.js b/src/plugins/comicsPlayer/plugin.js index 48e624b56..ce7fd4618 100644 --- a/src/plugins/comicsPlayer/plugin.js +++ b/src/plugins/comicsPlayer/plugin.js @@ -30,9 +30,17 @@ export class ComicsPlayer { return this.setCurrentSrc(elem, options); } + destroy() { + // Nothing to do here + } + stop() { this.unbindEvents(); + const stopInfo = { + src: this.item + }; + Events.trigger(this, 'stopped', [stopInfo]); this.archiveSource?.release(); const elem = this.mediaElement; @@ -44,6 +52,36 @@ export class ComicsPlayer { loading.hide(); } + currentTime() { + // * 1000 is an arbitrary value copied over from the bookPlayer + return this.progress * 1000; + } + + duration() { + // 1000 is an arbitrary value copied over from the bookPlayer + return 1000; + } + + currentItem() { + return this.item; + } + + volume() { + return 100; + } + + isMuted() { + return false; + } + + paused() { + return false; + } + + seekable() { + return true; + } + onDialogClosed() { this.stop(); } @@ -60,8 +98,8 @@ export class ComicsPlayer { bindMediaElementEvents() { const elem = this.mediaElement; - elem?.addEventListener('close', this.onDialogClosed, {once: true}); - elem?.querySelector('.btnExit').addEventListener('click', this.onDialogClosed, {once: true}); + elem?.addEventListener('close', this.onDialogClosed, { once: true }); + elem?.querySelector('.btnExit').addEventListener('click', this.onDialogClosed, { once: true }); } bindEvents() { @@ -118,7 +156,15 @@ export class ComicsPlayer { setCurrentSrc(elem, options) { const item = options.items[0]; - this.currentItem = item; + this.item = item; + this.streamInfo = { + started: true, + ended: false, + item: this.item, + mediaSource: { + Id: item.Id + } + }; loading.show(); @@ -134,6 +180,8 @@ export class ComicsPlayer { return this.archiveSource.load().then(() => { loading.hide(); + + this.progress = options.startPositionTicks / 10000000 || 0; this.swiperInstance = new Swiper(elem.querySelector('.slideshowSwiperContainer'), { direction: 'horizontal', // loop is disabled due to the lack of Swiper support in virtual slides @@ -150,7 +198,7 @@ export class ComicsPlayer { preloadImages: true, slidesPerView: 1, slidesPerColumn: 1, - initialSlide: 0, + initialSlide: this.progress * this.archiveSource.urls.length, // reduces memory consumption for large libraries while allowing preloading of images virtual: { slides: this.archiveSource.urls, @@ -160,6 +208,12 @@ export class ComicsPlayer { addSlidesAfter: 1 } }); + + // save current page ( a page is an image file inside the archive ) + this.swiperInstance.on('slideChange', () => { + this.progress = this.swiperInstance.activeIndex / this.archiveSource.urls.length; + Events.trigger(this, 'pause'); + }); }); } From 1806baec3721765ea35b4125185455e1e8549bbd Mon Sep 17 00:00:00 2001 From: Patrick Farwick <9168045+MinecraftPlaye@users.noreply.github.com> Date: Tue, 5 Oct 2021 20:10:25 +0000 Subject: [PATCH 2/4] Move "destroy" after "stop" and separate commands --- src/plugins/comicsPlayer/plugin.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/plugins/comicsPlayer/plugin.js b/src/plugins/comicsPlayer/plugin.js index ce7fd4618..700f812f3 100644 --- a/src/plugins/comicsPlayer/plugin.js +++ b/src/plugins/comicsPlayer/plugin.js @@ -30,17 +30,15 @@ export class ComicsPlayer { return this.setCurrentSrc(elem, options); } - destroy() { - // Nothing to do here - } - stop() { this.unbindEvents(); + const stopInfo = { src: this.item }; Events.trigger(this, 'stopped', [stopInfo]); + this.archiveSource?.release(); const elem = this.mediaElement; @@ -52,6 +50,10 @@ export class ComicsPlayer { loading.hide(); } + destroy() { + // Nothing to do here + } + currentTime() { // * 1000 is an arbitrary value copied over from the bookPlayer return this.progress * 1000; From b3056ee321d763873f4e5f35749550dbb2ff3816 Mon Sep 17 00:00:00 2001 From: Patrick Farwick <9168045+MinecraftPlaye@users.noreply.github.com> Date: Tue, 5 Oct 2021 20:20:33 +0000 Subject: [PATCH 3/4] Store each page as a tick --- src/plugins/comicsPlayer/plugin.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/plugins/comicsPlayer/plugin.js b/src/plugins/comicsPlayer/plugin.js index 700f812f3..2ad815754 100644 --- a/src/plugins/comicsPlayer/plugin.js +++ b/src/plugins/comicsPlayer/plugin.js @@ -24,7 +24,8 @@ export class ComicsPlayer { } play(options) { - this.progress = 0; + this.currentPage = 0; + this.pageCount = 0; const elem = this.createMediaElement(); return this.setCurrentSrc(elem, options); @@ -55,13 +56,12 @@ export class ComicsPlayer { } currentTime() { - // * 1000 is an arbitrary value copied over from the bookPlayer - return this.progress * 1000; + return this.currentPage; } duration() { // 1000 is an arbitrary value copied over from the bookPlayer - return 1000; + return this.pageCount; } currentItem() { @@ -183,7 +183,8 @@ export class ComicsPlayer { return this.archiveSource.load().then(() => { loading.hide(); - this.progress = options.startPositionTicks / 10000000 || 0; + this.pageCount = this.archiveSource.urls.length; + this.currentPage = options.startPositionTicks / 10000 || 0; this.swiperInstance = new Swiper(elem.querySelector('.slideshowSwiperContainer'), { direction: 'horizontal', // loop is disabled due to the lack of Swiper support in virtual slides @@ -200,7 +201,7 @@ export class ComicsPlayer { preloadImages: true, slidesPerView: 1, slidesPerColumn: 1, - initialSlide: this.progress * this.archiveSource.urls.length, + initialSlide: this.currentPage, // reduces memory consumption for large libraries while allowing preloading of images virtual: { slides: this.archiveSource.urls, @@ -213,7 +214,7 @@ export class ComicsPlayer { // save current page ( a page is an image file inside the archive ) this.swiperInstance.on('slideChange', () => { - this.progress = this.swiperInstance.activeIndex / this.archiveSource.urls.length; + this.currentPage = this.swiperInstance.activeIndex; Events.trigger(this, 'pause'); }); }); From c6c263de994ac043350400d9b3226c41f1d035fc Mon Sep 17 00:00:00 2001 From: Patrick Farwick <9168045+MinecraftPlaye@users.noreply.github.com> Date: Tue, 5 Oct 2021 20:41:47 +0000 Subject: [PATCH 4/4] Remove outdated comment --- src/plugins/comicsPlayer/plugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/comicsPlayer/plugin.js b/src/plugins/comicsPlayer/plugin.js index 2ad815754..3f6f844e3 100644 --- a/src/plugins/comicsPlayer/plugin.js +++ b/src/plugins/comicsPlayer/plugin.js @@ -60,7 +60,6 @@ export class ComicsPlayer { } duration() { - // 1000 is an arbitrary value copied over from the bookPlayer return this.pageCount; } @@ -185,6 +184,7 @@ export class ComicsPlayer { this.pageCount = this.archiveSource.urls.length; this.currentPage = options.startPositionTicks / 10000 || 0; + this.swiperInstance = new Swiper(elem.querySelector('.slideshowSwiperContainer'), { direction: 'horizontal', // loop is disabled due to the lack of Swiper support in virtual slides