Skip to content

Commit

Permalink
1.1.9: [fix - refactor]: change repeat logic & change start effect
Browse files Browse the repository at this point in the history
  • Loading branch information
Amir-Alipour committed Oct 22, 2023
1 parent d6982dd commit e9c2830
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reaplay",
"version": "1.1.8",
"version": "1.1.9",
"description": "the react HOC for create custom players with any styles you like",
"author": "amir-alipour",
"license": "MIT",
Expand Down
11 changes: 6 additions & 5 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReactNode, useEffect, useLayoutEffect, useRef, useState } from 'react'
import { ReactNode, useEffect, useRef, useState } from 'react'
import { ConvertTimeToText } from './helper'

interface Props {
Expand Down Expand Up @@ -99,7 +99,7 @@ export const Reaplay = ({ tracks, startIndex = 0, children }: Props) => {
const [buffered, setBuffered] = useState<number>(0)
// control the player mute, unmute

const [fourceRepeat, setFourceRepeat] = useState<number>(0)

const [isLoading, setIsLoading] = useState<boolean>(true)
const [isHaveError, setIsHaveError] = useState<boolean>(false)
const [forcePlayerUpdate, setForcePlayerUpdate] = useState<number>(0)
Expand Down Expand Up @@ -166,7 +166,8 @@ export const Reaplay = ({ tracks, startIndex = 0, children }: Props) => {
playRandom()
} else {
if (isRepeat) {
setFourceRepeat((prev) => prev + 1)
onScrub(0);
audioRef.current.play();
} else {
toNextTrack()
}
Expand Down Expand Up @@ -439,7 +440,7 @@ export const Reaplay = ({ tracks, startIndex = 0, children }: Props) => {
* if fource update be called, it do anything at first
*/

useLayoutEffect(() => {
useEffect(() => {
audioRef.current.pause()
setIsPlaying(false)
setIsLoading(true)
Expand All @@ -457,7 +458,7 @@ export const Reaplay = ({ tracks, startIndex = 0, children }: Props) => {
// Set the isReady ref as true for the next pass
isReady.current = true
}
}, [trackIndex, fourceRepeat, forcePlayerUpdate])
}, [trackIndex, forcePlayerUpdate])

/**
* clean the memory and pause the song for manage memory leak and
Expand Down

0 comments on commit e9c2830

Please sign in to comment.