<template>
  <unitv-page
    id="curriculumPlayPage"
    ref="curriculumPlayPage"
    class="curriculumPlayPage"
    :show="true"
  >
    <unitv-video
      id="player"
      :src="url"
      :title="title"
      :initial-time="time"
      @timeupdate="fnTimeupdate"
    />
  </unitv-page>
</template>

<script>
export default {
  data() {
    return {
      videoContext: null,
      url: "",
      title: "",
      time: 0,
    };
  },
  onLoad(query) {
    this.url = query.url;
    this.title = query.title;
    this.time = +query.time;
  },
  onReady() {
    this.videoContext = uni.createVideoContext("player");
    this.videoContext.play();
    this.videoContext.seek(this.time);
  },
  onUnload() {
    const eventChannel = this.getOpenerEventChannel();
    eventChannel.emit("timeupdate", { time: this.time });
  },
  methods: {
    fnTimeupdate(time) {
      this.time = time;
    },
  },
};
</script>

<style scoped lang="scss"></style>
