Use events and emits for finding currentTime.

This commit is contained in:
Kavin 2022-07-19 21:59:03 +05:30
parent f96a7fa86a
commit 25d82169b6
No known key found for this signature in database
GPG Key ID: 49451E4482CC5BCD
3 changed files with 23 additions and 18 deletions

View File

@ -69,24 +69,21 @@
@apply truncate overflow-hidden inline-block w-10em; @apply truncate overflow-hidden inline-block w-10em;
} }
</style> </style>
<script type="text/javascript">
export default { <script setup>
emits: ["seek"], import { defineProps, defineEmits } from "vue";
props: {
defineProps({
chapters: Object, chapters: Object,
mobileLayout: { mobileLayout: {
type: Boolean, type: Boolean,
default: () => true, default: () => true,
}, },
playerPosition: {
type: Number,
default: () => 0,
}, },
data() { });
return { playerPosition: 0 };
}, defineEmits(["seek"]);
mounted() {
// get current video position in regular intervals
setInterval(() => {
this.playerPosition = document.querySelector("video").currentTime;
}, 2000);
},
};
</script> </script>

View File

@ -42,6 +42,7 @@ export default {
selectedAutoLoop: Boolean, selectedAutoLoop: Boolean,
isEmbed: Boolean, isEmbed: Boolean,
}, },
emits: ["timeupdate"],
data() { data() {
return { return {
lastUpdate: new Date().getTime(), lastUpdate: new Date().getTime(),
@ -343,6 +344,7 @@ export default {
if (noPrevPlayer) { if (noPrevPlayer) {
videoEl.addEventListener("timeupdate", () => { videoEl.addEventListener("timeupdate", () => {
const time = videoEl.currentTime; const time = videoEl.currentTime;
this.$emit("timeupdate", time);
this.updateProgressDatabase(time); this.updateProgressDatabase(time);
if (this.sponsors && this.sponsors.segments) { if (this.sponsors && this.sponsors.segments) {
this.sponsors.segments.map(segment => { this.sponsors.segments.map(segment => {

View File

@ -25,11 +25,13 @@
:index="index" :index="index"
:selected-auto-play="selectedAutoPlay" :selected-auto-play="selectedAutoPlay"
:selected-auto-loop="selectedAutoLoop" :selected-auto-loop="selectedAutoLoop"
@timeupdate="onTimeUpdate"
/> />
<ChaptersBar <ChaptersBar
:mobileLayout="isMobile" :mobileLayout="isMobile"
v-if="video?.chapters?.length > 0" v-if="video?.chapters?.length > 0"
:chapters="video.chapters" :chapters="video.chapters"
:player-position="currentTime"
@seek="navigate" @seek="navigate"
/> />
</div> </div>
@ -242,6 +244,7 @@ export default {
smallView: smallViewQuery.matches, smallView: smallViewQuery.matches,
showModal: false, showModal: false,
isMobile: true, isMobile: true,
currentTime: 0,
}; };
}, },
computed: { computed: {
@ -465,6 +468,9 @@ export default {
navigate(time) { navigate(time) {
this.$refs.videoPlayer.seek(time); this.$refs.videoPlayer.seek(time);
}, },
onTimeUpdate(time) {
this.currentTime = time;
},
}, },
}; };
</script> </script>