Skip to content

Commit

Permalink
feat: use state in Watch for playback rate value instead defaultPlayb…
Browse files Browse the repository at this point in the history
…ack store value directly
  • Loading branch information
ikizey committed Dec 25, 2024
1 parent e5d59ed commit 8ecdf29
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,18 @@ export default defineComponent({
type: String,
default: null
},
currentPlaybackRate: {
type: Number,
default: () => 1.0
},
},
emits: [
'error',
'loaded',
'ended',
'timeupdate',
'toggle-theatre-mode'
'toggle-theatre-mode',
'current-playback-rate-update'
],
setup: function (props, { emit, expose }) {
const { locale, t } = useI18n()
Expand Down Expand Up @@ -235,11 +240,6 @@ export default defineComponent({
})
})

/** @type {import('vue').ComputedRef<number>} */
const defaultPlayback = computed(() => {
return store.getters.getDefaultPlayback
})

/** @type {import('vue').ComputedRef<number>} */
const defaultSkipInterval = computed(() => {
return store.getters.getDefaultSkipInterval
Expand Down Expand Up @@ -901,8 +901,8 @@ export default defineComponent({
// stop shaka-player's click handler firing
event.stopPropagation()

video.value.playbackRate = defaultPlayback.value
video.value.defaultPlaybackRate = defaultPlayback.value
video.value.playbackRate = props.currentPlaybackRate
video.value.defaultPlaybackRate = props.currentPlaybackRate
}
}

Expand Down Expand Up @@ -2310,8 +2310,8 @@ export default defineComponent({
videoElement.muted = (muted === 'true')
}

videoElement.playbackRate = defaultPlayback.value
videoElement.defaultPlaybackRate = defaultPlayback.value
videoElement.playbackRate = props.currentPlaybackRate
videoElement.defaultPlaybackRate = props.currentPlaybackRate

const localPlayer = new shaka.Player()

Expand Down Expand Up @@ -2413,6 +2413,10 @@ export default defineComponent({
container.value.classList.add('no-cursor')

await performFirstLoad()

player.addEventListener('ratechange', () => {
emit('current-playback-rate-update', video.value.playbackRate)
})
})

async function performFirstLoad() {
Expand Down
7 changes: 6 additions & 1 deletion src/renderer/views/Watch/Watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ export default defineComponent({
customErrorIcon: null,
videoGenreIsMusic: false,
/** @type {Date|null} */
streamingDataExpiryDate: null
streamingDataExpiryDate: null,
currentPlaybackRate: parseFloat(this.$store.getters.getDefaultPlayback)
}
},
computed: {
Expand Down Expand Up @@ -1670,6 +1671,10 @@ export default defineComponent({
this.blockVideoAutoplay = false
},

updatePlaybackRate(newRate) {
this.currentPlaybackRate = newRate
},

...mapActions([
'updateHistory',
'updateWatchProgress',
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/views/Watch/Watch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@
:theatre-possible="theatrePossible"
:use-theatre-mode="useTheatreMode"
:vr-projection="vrProjection"
:current-playback-rate="currentPlaybackRate"
class="videoPlayer"
@error="handlePlayerError"
@loaded="handleVideoLoaded"
@timeupdate="updateCurrentChapter"
@ended="handleVideoEnded"
@toggle-theatre-mode="useTheatreMode = !useTheatreMode"
@current-playback-rate-update="updatePlaybackRate"
/>
<div
v-if="!isLoading && (isUpcoming || errorMessage)"
Expand Down

0 comments on commit 8ecdf29

Please sign in to comment.