Skip to content

Commit

Permalink
Merge pull request #1587 from saithsab877/Not-starting-at-the-correct…
Browse files Browse the repository at this point in the history
…-timestamp

Fixed(Video-Player): Not Starting at the Correct Timestamp
  • Loading branch information
Rassl authored Jun 7, 2024
2 parents c35fcf8 + ea87cf1 commit 94ca603
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/components/App/SideBar/SidebarSubView/MediaPlayer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import styled from 'styled-components'
import { Avatar } from '~/components/common/Avatar'
import { Flex } from '~/components/common/Flex'
import { usePlayerStore } from '~/stores/usePlayerStore'
import { colors } from '~/utils'
import { colors, videoTimeToSeconds } from '~/utils'
import { Toolbar } from './ToolBar'

type Props = {
Expand Down Expand Up @@ -75,9 +75,10 @@ const MediaPlayerComponent: FC<Props> = ({ hidden }) => {
const handleProgressChange = (_: Event, value: number | number[]) => {
const newValue = Array.isArray(value) ? value[0] : value

if (playerRef.current) {
playerRef.current.seekTo(newValue)
setPlayingTime(newValue)
setPlayingTime(newValue)

if (playerRef.current && !isSeeking) {
playerRef.current.seekTo(newValue, 'seconds')
}
}

Expand Down Expand Up @@ -107,6 +108,16 @@ const MediaPlayerComponent: FC<Props> = ({ hidden }) => {
const videoDuration = playerRef.current.getDuration()

setDuration(videoDuration)

if (!isSeeking && (playingTime === 0 || Math.abs(playingTime - videoTimeToSeconds('00:00:00')) < 1)) {
if (playingNode?.type === 'youtube' && playingNode?.timestamp) {
const [startTimestamp] = playingNode.timestamp.split('-')
const startTimeInSeconds = videoTimeToSeconds(startTimestamp)

playerRef.current.seekTo(startTimeInSeconds, 'seconds')
setPlayingTime(startTimeInSeconds)
}
}
}
}

Expand Down

0 comments on commit 94ca603

Please sign in to comment.