Add auto play next video and fix watch progress issue on route change
This commit is contained in:
		
							parent
							
								
									c7762852f2
								
							
						
					
					
						commit
						df629ff7e1
					
				| 
						 | 
					@ -23,7 +23,6 @@
 | 
				
			||||||
.switch-label
 | 
					.switch-label
 | 
				
			||||||
  position: relative
 | 
					  position: relative
 | 
				
			||||||
  display: inline-block
 | 
					  display: inline-block
 | 
				
			||||||
  min-width: 112px
 | 
					 | 
				
			||||||
  cursor: pointer
 | 
					  cursor: pointer
 | 
				
			||||||
  font-weight: 500
 | 
					  font-weight: 500
 | 
				
			||||||
  text-align: left
 | 
					  text-align: left
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,10 +29,7 @@ export default Vue.extend({
 | 
				
			||||||
        360,
 | 
					        360,
 | 
				
			||||||
        480,
 | 
					        480,
 | 
				
			||||||
        720,
 | 
					        720,
 | 
				
			||||||
        1080,
 | 
					        1080
 | 
				
			||||||
        1440,
 | 
					 | 
				
			||||||
        2160,
 | 
					 | 
				
			||||||
        4320
 | 
					 | 
				
			||||||
      ]
 | 
					      ]
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
| 
						 | 
					@ -97,10 +94,7 @@ export default Vue.extend({
 | 
				
			||||||
        this.$t('Settings.Player Settings.Default Quality.360p'),
 | 
					        this.$t('Settings.Player Settings.Default Quality.360p'),
 | 
				
			||||||
        this.$t('Settings.Player Settings.Default Quality.480p'),
 | 
					        this.$t('Settings.Player Settings.Default Quality.480p'),
 | 
				
			||||||
        this.$t('Settings.Player Settings.Default Quality.720p'),
 | 
					        this.$t('Settings.Player Settings.Default Quality.720p'),
 | 
				
			||||||
        this.$t('Settings.Player Settings.Default Quality.1080p'),
 | 
					        this.$t('Settings.Player Settings.Default Quality.1080p')
 | 
				
			||||||
        this.$t('Settings.Player Settings.Default Quality.1440p'),
 | 
					 | 
				
			||||||
        this.$t('Settings.Player Settings.Default Quality.4k'),
 | 
					 | 
				
			||||||
        this.$t('Settings.Player Settings.Default Quality.8k')
 | 
					 | 
				
			||||||
      ]
 | 
					      ]
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -28,6 +28,12 @@
 | 
				
			||||||
          :default-value="proxyVideos"
 | 
					          :default-value="proxyVideos"
 | 
				
			||||||
          @change="updateProxyVideos"
 | 
					          @change="updateProxyVideos"
 | 
				
			||||||
        />
 | 
					        />
 | 
				
			||||||
 | 
					        <ft-toggle-switch
 | 
				
			||||||
 | 
					          :label="$t('Settings.Player Settings.Enable Theatre Mode by Default')"
 | 
				
			||||||
 | 
					          :compact="true"
 | 
				
			||||||
 | 
					          :default-value="defaultTheatreMode"
 | 
				
			||||||
 | 
					          @change="updateDefaultTheatreMode"
 | 
				
			||||||
 | 
					        />
 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
      <div class="switchColumn">
 | 
					      <div class="switchColumn">
 | 
				
			||||||
        <ft-toggle-switch
 | 
					        <ft-toggle-switch
 | 
				
			||||||
| 
						 | 
					@ -43,18 +49,11 @@
 | 
				
			||||||
          @change="updateAutoplayPlaylists"
 | 
					          @change="updateAutoplayPlaylists"
 | 
				
			||||||
        />
 | 
					        />
 | 
				
			||||||
        <ft-toggle-switch
 | 
					        <ft-toggle-switch
 | 
				
			||||||
          v-if="false"
 | 
					 | 
				
			||||||
          :label="$t('Settings.Player Settings.Play Next Video')"
 | 
					          :label="$t('Settings.Player Settings.Play Next Video')"
 | 
				
			||||||
          :compact="true"
 | 
					          :compact="true"
 | 
				
			||||||
          :default-value="playNextVideo"
 | 
					          :default-value="playNextVideo"
 | 
				
			||||||
          @change="updatePlayNextVideo"
 | 
					          @change="updatePlayNextVideo"
 | 
				
			||||||
        />
 | 
					        />
 | 
				
			||||||
        <ft-toggle-switch
 | 
					 | 
				
			||||||
          :label="$t('Settings.Player Settings.Enable Theatre Mode by Default')"
 | 
					 | 
				
			||||||
          :compact="true"
 | 
					 | 
				
			||||||
          :default-value="defaultTheatreMode"
 | 
					 | 
				
			||||||
          @change="updateDefaultTheatreMode"
 | 
					 | 
				
			||||||
        />
 | 
					 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
    <ft-flex-box>
 | 
					    <ft-flex-box>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,15 @@
 | 
				
			||||||
 | 
					.relative {
 | 
				
			||||||
 | 
						position: relative;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.watchVideoRecommendations {
 | 
					.watchVideoRecommendations {
 | 
				
			||||||
	display: grid;
 | 
						display: grid;
 | 
				
			||||||
	grid-gap: 8px;
 | 
						grid-gap: 8px;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.autoPlayToggle {
 | 
				
			||||||
 | 
						width: 120px;
 | 
				
			||||||
 | 
						position: absolute;
 | 
				
			||||||
 | 
						top: 10px;
 | 
				
			||||||
 | 
						right: 0px;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,22 +1,37 @@
 | 
				
			||||||
import Vue from 'vue'
 | 
					import Vue from 'vue'
 | 
				
			||||||
 | 
					import { mapActions } from 'vuex'
 | 
				
			||||||
import FtCard from '../ft-card/ft-card.vue'
 | 
					import FtCard from '../ft-card/ft-card.vue'
 | 
				
			||||||
import FtListVideo from '../ft-list-video/ft-list-video.vue'
 | 
					import FtListVideo from '../ft-list-video/ft-list-video.vue'
 | 
				
			||||||
 | 
					import FtToggleSwitch from '../ft-toggle-switch/ft-toggle-switch.vue'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default Vue.extend({
 | 
					export default Vue.extend({
 | 
				
			||||||
  name: 'WatchVideoRecommendations',
 | 
					  name: 'WatchVideoRecommendations',
 | 
				
			||||||
  components: {
 | 
					  components: {
 | 
				
			||||||
    'ft-card': FtCard,
 | 
					    'ft-card': FtCard,
 | 
				
			||||||
    'ft-list-video': FtListVideo
 | 
					    'ft-list-video': FtListVideo,
 | 
				
			||||||
 | 
					    'ft-toggle-switch': FtToggleSwitch
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  props: {
 | 
					  props: {
 | 
				
			||||||
    data: {
 | 
					    data: {
 | 
				
			||||||
      type: Array,
 | 
					      type: Array,
 | 
				
			||||||
      required: true
 | 
					      required: true
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    watchingPlaylist: {
 | 
				
			||||||
 | 
					      type: Boolean,
 | 
				
			||||||
 | 
					      default: false
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  computed: {
 | 
					  computed: {
 | 
				
			||||||
    listType: function () {
 | 
					    listType: function () {
 | 
				
			||||||
      return this.$store.getters.getListType
 | 
					      return this.$store.getters.getListType
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    playNextVideo: function () {
 | 
				
			||||||
 | 
					      return this.$store.getters.getPlayNextVideo
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  methods: {
 | 
				
			||||||
 | 
					    ...mapActions([
 | 
				
			||||||
 | 
					      'updatePlayNextVideo'
 | 
				
			||||||
 | 
					    ])
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,14 @@
 | 
				
			||||||
    <h3>
 | 
					    <h3>
 | 
				
			||||||
      {{ $t("Up Next") }}
 | 
					      {{ $t("Up Next") }}
 | 
				
			||||||
    </h3>
 | 
					    </h3>
 | 
				
			||||||
 | 
					    <ft-toggle-switch
 | 
				
			||||||
 | 
					      v-if="!watchingPlaylist"
 | 
				
			||||||
 | 
					      class="autoPlayToggle"
 | 
				
			||||||
 | 
					      :label="$t('Video.Autoplay')"
 | 
				
			||||||
 | 
					      :compact="true"
 | 
				
			||||||
 | 
					      :default-value="playNextVideo"
 | 
				
			||||||
 | 
					      @change="updatePlayNextVideo"
 | 
				
			||||||
 | 
					    />
 | 
				
			||||||
    <ft-list-video
 | 
					    <ft-list-video
 | 
				
			||||||
      v-for="(video, index) in data"
 | 
					      v-for="(video, index) in data"
 | 
				
			||||||
      :key="index"
 | 
					      :key="index"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -70,54 +70,45 @@ export default Vue.extend({
 | 
				
			||||||
    isDev: function () {
 | 
					    isDev: function () {
 | 
				
			||||||
      return process.env.NODE_ENV === 'development'
 | 
					      return process.env.NODE_ENV === 'development'
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					 | 
				
			||||||
    usingElectron: function () {
 | 
					    usingElectron: function () {
 | 
				
			||||||
      return this.$store.getters.getUsingElectron
 | 
					      return this.$store.getters.getUsingElectron
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					 | 
				
			||||||
    historyCache: function () {
 | 
					    historyCache: function () {
 | 
				
			||||||
      return this.$store.getters.getHistoryCache
 | 
					      return this.$store.getters.getHistoryCache
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					 | 
				
			||||||
    rememberHistory: function () {
 | 
					    rememberHistory: function () {
 | 
				
			||||||
      return this.$store.getters.getRememberHistory
 | 
					      return this.$store.getters.getRememberHistory
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					 | 
				
			||||||
    saveWatchedProgress: function () {
 | 
					    saveWatchedProgress: function () {
 | 
				
			||||||
      return this.$store.getters.getSaveWatchedProgress
 | 
					      return this.$store.getters.getSaveWatchedProgress
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					 | 
				
			||||||
    backendPreference: function () {
 | 
					    backendPreference: function () {
 | 
				
			||||||
      return this.$store.getters.getBackendPreference
 | 
					      return this.$store.getters.getBackendPreference
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					 | 
				
			||||||
    backendFallback: function () {
 | 
					    backendFallback: function () {
 | 
				
			||||||
      return this.$store.getters.getBackendFallback
 | 
					      return this.$store.getters.getBackendFallback
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					 | 
				
			||||||
    invidiousInstance: function () {
 | 
					    invidiousInstance: function () {
 | 
				
			||||||
      return this.$store.getters.getInvidiousInstance
 | 
					      return this.$store.getters.getInvidiousInstance
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					 | 
				
			||||||
    proxyVideos: function () {
 | 
					    proxyVideos: function () {
 | 
				
			||||||
      return this.$store.getters.getProxyVideos
 | 
					      return this.$store.getters.getProxyVideos
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					 | 
				
			||||||
    defaultTheatreMode: function () {
 | 
					    defaultTheatreMode: function () {
 | 
				
			||||||
      return this.$store.getters.getDefaultTheatreMode
 | 
					      return this.$store.getters.getDefaultTheatreMode
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					 | 
				
			||||||
    defaultVideoFormat: function () {
 | 
					    defaultVideoFormat: function () {
 | 
				
			||||||
      return this.$store.getters.getDefaultVideoFormat
 | 
					      return this.$store.getters.getDefaultVideoFormat
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					 | 
				
			||||||
    forceLocalBackendForLegacy: function () {
 | 
					    forceLocalBackendForLegacy: function () {
 | 
				
			||||||
      return this.$store.getters.getForceLocalBackendForLegacy
 | 
					      return this.$store.getters.getForceLocalBackendForLegacy
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					 | 
				
			||||||
    thumbnailPreference: function () {
 | 
					    thumbnailPreference: function () {
 | 
				
			||||||
      return this.$store.getters.getThumbnailPreference
 | 
					      return this.$store.getters.getThumbnailPreference
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					    playNextVideo: function () {
 | 
				
			||||||
 | 
					      return this.$store.getters.getPlayNextVideo
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    thumbnail: function () {
 | 
					    thumbnail: function () {
 | 
				
			||||||
      let baseUrl
 | 
					      let baseUrl
 | 
				
			||||||
| 
						 | 
					@ -145,6 +136,7 @@ export default Vue.extend({
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  watch: {
 | 
					  watch: {
 | 
				
			||||||
    $route() {
 | 
					    $route() {
 | 
				
			||||||
 | 
					      this.handleRouteChange()
 | 
				
			||||||
      // react to route changes...
 | 
					      // react to route changes...
 | 
				
			||||||
      this.videoId = this.$route.params.id
 | 
					      this.videoId = this.$route.params.id
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -586,6 +578,46 @@ export default Vue.extend({
 | 
				
			||||||
            })
 | 
					            })
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
 | 
					      } else if (this.playNextVideo) {
 | 
				
			||||||
 | 
					        const timeout = setTimeout(() => {
 | 
				
			||||||
 | 
					          const nextVideoId = this.recommendedVideos[0].videoId
 | 
				
			||||||
 | 
					          this.$router.push(
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					              path: `/watch/${nextVideoId}`
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					          )
 | 
				
			||||||
 | 
					          this.showToast({
 | 
				
			||||||
 | 
					            message: this.$t('Playing Next Video')
 | 
				
			||||||
 | 
					          })
 | 
				
			||||||
 | 
					        }, 5000)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        this.showToast({
 | 
				
			||||||
 | 
					          message: this.$t('Playing next video in 5 seconds.  Click to cancel'),
 | 
				
			||||||
 | 
					          time: 5500,
 | 
				
			||||||
 | 
					          action: () => {
 | 
				
			||||||
 | 
					            clearTimeout(timeout)
 | 
				
			||||||
 | 
					            this.showToast({
 | 
				
			||||||
 | 
					              message: this.$t('Canceled next video autoplay')
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    handleRouteChange: function () {
 | 
				
			||||||
 | 
					      if (this.rememberHistory && !this.isLoading && !this.isLive) {
 | 
				
			||||||
 | 
					        const player = this.$refs.videoPlayer.player
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (player !== null && this.saveWatchedProgress) {
 | 
				
			||||||
 | 
					          const currentTime = this.$refs.videoPlayer.player.currentTime()
 | 
				
			||||||
 | 
					          const payload = {
 | 
				
			||||||
 | 
					            videoId: this.videoId,
 | 
				
			||||||
 | 
					            watchProgress: currentTime
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          console.log('update watch progress')
 | 
				
			||||||
 | 
					          this.updateWatchProgress(payload)
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -739,21 +771,7 @@ export default Vue.extend({
 | 
				
			||||||
    ])
 | 
					    ])
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  beforeRouteLeave: function (to, from, next) {
 | 
					  beforeRouteLeave: function (to, from, next) {
 | 
				
			||||||
    if (this.rememberHistory && !this.isLoading && !this.isLive) {
 | 
					    this.handleRouteChange()
 | 
				
			||||||
      const player = this.$refs.videoPlayer.player
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      if (player !== null && this.saveWatchedProgress) {
 | 
					 | 
				
			||||||
        const currentTime = this.$refs.videoPlayer.player.currentTime()
 | 
					 | 
				
			||||||
        const payload = {
 | 
					 | 
				
			||||||
          videoId: this.videoId,
 | 
					 | 
				
			||||||
          watchProgress: currentTime
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        console.log('update watch progress')
 | 
					 | 
				
			||||||
        this.updateWatchProgress(payload)
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    next()
 | 
					    next()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -80,6 +80,7 @@
 | 
				
			||||||
      />
 | 
					      />
 | 
				
			||||||
      <watch-video-recommendations
 | 
					      <watch-video-recommendations
 | 
				
			||||||
        v-if="!isLoading"
 | 
					        v-if="!isLoading"
 | 
				
			||||||
 | 
					        :watching-playlist="watchingPlaylist"
 | 
				
			||||||
        :data="recommendedVideos"
 | 
					        :data="recommendedVideos"
 | 
				
			||||||
        class="watchVideoSideBar watchVideoRecommendations"
 | 
					        class="watchVideoSideBar watchVideoRecommendations"
 | 
				
			||||||
        :class="{
 | 
					        :class="{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -338,6 +338,7 @@ Video:
 | 
				
			||||||
  # Context is "X People Watching"
 | 
					  # Context is "X People Watching"
 | 
				
			||||||
  Watching: Watching
 | 
					  Watching: Watching
 | 
				
			||||||
  Watched: Watched
 | 
					  Watched: Watched
 | 
				
			||||||
 | 
					  Autoplay: Autoplay
 | 
				
			||||||
  # As in a Live Video
 | 
					  # As in a Live Video
 | 
				
			||||||
  Live: Live
 | 
					  Live: Live
 | 
				
			||||||
  Live Now: Live Now
 | 
					  Live Now: Live Now
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue