Skip to content

Commit 633da0a

Browse files
committed
feat: Support auto-starting slideshow
Signed-off-by: Louis Chmn <louis@chmn.me>
1 parent de4b897 commit 633da0a

3 files changed

Lines changed: 82 additions & 2 deletions

File tree

src/components/Videos.vue

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
:src="url"
2121
preload="metadata"
2222
@error.capture.prevent.stop.once="onFail"
23+
@play="onPlay"
24+
@pause="onPause"
2325
@ended="donePlaying"
2426
@canplay="doneLoading"
2527
@loadedmetadata="onLoadedMetadata">
@@ -182,7 +184,17 @@ export default {
182184
this.updateHeightWidth()
183185
},
184186
187+
onPlay() {
188+
this.$emit('update:playing', true)
189+
},
190+
191+
onPause() {
192+
this.$emit('update:playing', false)
193+
},
194+
185195
donePlaying() {
196+
this.$emit('update:playing', false)
197+
186198
// reset and show poster after play
187199
this.$refs.video.autoplay = false
188200
this.$refs.video.load()

src/services/Viewer.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export default class Viewer {
5555
this._state.onNext = () => {}
5656
this._state.onClose = () => {}
5757
this._state.canLoop = true
58+
this._state.startSlideshow = false
5859
this._state.handlers = []
5960
this._state.overrideHandlerId = null
6061

@@ -258,6 +259,16 @@ export default class Viewer {
258259
return this._state.canLoop
259260
}
260261

262+
/**
263+
* Whether the slideshow start playing as soon as the viewer is opens
264+
*
265+
* @memberof Viewer
266+
* @return {boolean}
267+
*/
268+
get startSlideshow() {
269+
return this._state.startSlideshow
270+
}
271+
261272
/**
262273
* If this handler is set, it should be used for viewing the next file.
263274
*
@@ -291,11 +302,23 @@ export default class Viewer {
291302
* @param {boolean} options.enableSidebar whether to enable the sidebar or not
292303
* @param {Function} options.loadMore callback for loading more files
293304
* @param {boolean} options.canLoop can the viewer loop over the array
305+
* @param {boolean} options.startSlideshow start playing the slideshow right away
294306
* @param {Function} options.onPrev callback when navigating back to previous file
295307
* @param {Function} options.onNext callback when navigation forward to next file
296308
* @param {Function} options.onClose callback when closing the viewer
297309
*/
298-
open({ path, fileInfo, list = [], enableSidebar = true, loadMore = () => ([]), canLoop = true, onPrev = () => {}, onNext = () => {}, onClose = () => {} } = {}) {
310+
open({
311+
path,
312+
fileInfo,
313+
list = [],
314+
enableSidebar = true,
315+
loadMore = () => [],
316+
canLoop = true,
317+
startSlideshow = false,
318+
onPrev = () => {},
319+
onNext = () => {},
320+
onClose = () => {},
321+
} = {}) {
299322
if (typeof arguments[0] === 'string') {
300323
throw new Error('Opening the viewer with a single string parameter is deprecated. Please use a destructuring object instead', `OCA.Viewer.open({ path: '${path}' })`)
301324
}
@@ -330,6 +353,7 @@ export default class Viewer {
330353
this._state.onNext = onNext
331354
this._state.onClose = onClose
332355
this._state.canLoop = canLoop
356+
this._state.startSlideshow = startSlideshow
333357
}
334358
}
335359

@@ -378,6 +402,7 @@ export default class Viewer {
378402
this._state.files = []
379403
this._state.enableSidebar = true
380404
this._state.canLoop = true
405+
this._state.startSlideshow = false
381406
this._state.loadMore = () => ([])
382407
this._state.overrideHandlerId = null
383408
}

src/views/Viewer.vue

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<!-- Modal view rendering -->
3030
<NcModal v-else-if="initiated || currentFile.modal"
3131
id="viewer"
32+
ref="modal"
3233
:additional-trap-elements="trapElements"
3334
:class="modalClass"
3435
:clear-view-delay="-1 /* disable fade-out because of accessibility reasons */"
@@ -37,7 +38,7 @@
3738
:light-backdrop="lightBackdrop"
3839
:data-handler="handlerId"
3940
:enable-slideshow="hasPrevious || hasNext"
40-
:slideshow-paused="editing"
41+
:slideshow-paused="editing || playingVideo"
4142
:enable-swipe="canSwipe && !editing"
4243
:has-next="hasNext"
4344
:has-previous="hasPrevious"
@@ -150,6 +151,7 @@
150151
:loaded.sync="currentFile.loaded"
151152
class="viewer__file viewer__file--active"
152153
@update:editing="toggleEditor"
154+
@update:playing="playingVideo = $event"
153155
@error="currentFailed" />
154156
<Error v-else
155157
:name="currentFile.basename" />
@@ -257,6 +259,8 @@ export default defineComponent({
257259
isLoaded: false,
258260
initiated: false,
259261
editing: false,
262+
slideshowStarted: false,
263+
playingVideo: false,
260264
261265
// cancellable requests
262266
cancelRequestFile: () => {},
@@ -313,6 +317,9 @@ export default defineComponent({
313317
canLoop() {
314318
return this.Viewer.canLoop
315319
},
320+
startSlideshow() {
321+
return this.Viewer.startSlideshow
322+
},
316323
isStartOfList() {
317324
return this.currentIndex === 0
318325
},
@@ -428,6 +435,12 @@ export default defineComponent({
428435
},
429436
430437
watch: {
438+
fileList(fileList) {
439+
if (fileList.length > 1) {
440+
this.beginSlideshow()
441+
}
442+
},
443+
431444
el(element) {
432445
logger.info(element)
433446
this.$nextTick(() => {
@@ -623,6 +636,34 @@ export default defineComponent({
623636
}
624637
},
625638
639+
async beginSlideshow() {
640+
if (!this.startSlideshow || this.slideshowStarted) {
641+
return
642+
}
643+
this.slideshowStarted = true
644+
645+
// Hack: NcModal is imported lazily, so its ref is only there once the chunk
646+
// has resolved and it has been rendered.
647+
await NcModal()
648+
await this.$nextTick()
649+
if (!this.$refs.modal) {
650+
await this.$nextTick()
651+
}
652+
653+
// const modal = this.$refs.modal;
654+
if (!this.$refs.modal) {
655+
logger.warn(
656+
'Could not start the slideshow, the viewer this.$refs.modal is not mounted',
657+
)
658+
return
659+
}
660+
this.$refs.modal.togglePlayPause()
661+
662+
if (this.playingVideo) {
663+
this.$refs.modal.slideshowTimeout?.pause()
664+
}
665+
},
666+
626667
/**
627668
* Open the view and display the clicked file
628669
*
@@ -1035,6 +1076,8 @@ export default defineComponent({
10351076
this.currentModal = null
10361077
this.fileList = []
10371078
this.initiated = false
1079+
this.slideshowStarted = false
1080+
this.playingVideo = false
10381081
this.theme = null
10391082
10401083
// cancel requests

0 commit comments

Comments
 (0)