Skip to content

Commit

Permalink
forceUpdatePlayr function was added
Browse files Browse the repository at this point in the history
  • Loading branch information
Amir-Alipour committed Sep 12, 2023
1 parent 1c91484 commit 3afb709
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Param | Type | Default | Notes
Prop | Type | Default | Notes
--- | --- | --- | ---
`isLoading` | Boolean | false | if use Uri tracks, you need wait for the uri will be load
`isHaveError` | Boolean | false | use it for start at custom index of your tracks array
`isHaveError` | Boolean | false | if your track returned error, it give you a boolean
`trackIndex` | Number | 0 | the playing index of the tracks array
`duration` | Number | song duration | the duration of the playing song
`durationText` | String | song duration converted | the duration of the playing song converted to 00:00 string
Expand Down Expand Up @@ -167,9 +167,15 @@ Event | param | Description | Example
`unmute` | () | unmute the player | player.unmute()
`forward` | () | forward to 5s later | player.forward()
`backward` | () | backward to 5s before | player.backward()
`forceUpdatePlayer` | () | forece Re-Render player | player.forceUpdatePlayer()

</br>
</br>

### Fix Player Start by itself : </br>
<img width="798" alt="242920537-9cedf5bb-ad7e-4488-aa03-29765826182b" src="https://github-production-user-asset-6210df.s3.amazonaws.com/73488911/267464235-98384f28-a7f8-440b-9c2c-6745bfe9135a.png">


</br>

## License
Expand Down
12 changes: 10 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ interface Props {
* @property {string} player.bufferedText
* @property {function} player.forward
* @property {function} player.backward
* @property {function} player.forceUpdatePlayer
*/
export const Reaplay = ({ tracks, startIndex = 0, children }: Props) => {
if (startIndex < 0 || startIndex > tracks.length) {
Expand Down Expand Up @@ -101,6 +102,7 @@ export const Reaplay = ({ tracks, startIndex = 0, children }: Props) => {
const [fourceRepeat, setFourceRepeat] = useState<number>(0)
const [isLoading, setIsLoading] = useState<boolean>(true)
const [isHaveError, setIsHaveError] = useState<boolean>(false)
const [forcePlayerUpdate, setForcePlayerUpdate] = useState<number>(0)
// helper states

// =====================================================
Expand Down Expand Up @@ -383,6 +385,10 @@ export const Reaplay = ({ tracks, startIndex = 0, children }: Props) => {
setTrackIndex(random)
}

const forceUpdatePlayer = (): void => {
setForcePlayerUpdate((prev) => prev + 1)
}

/**
* manage isPlay state for play or pause the song
* start timer for detect when the song ended or more ..
Expand Down Expand Up @@ -439,7 +445,7 @@ export const Reaplay = ({ tracks, startIndex = 0, children }: Props) => {
// Set the isReady ref as true for the next pass
isReady.current = true
}
}, [trackIndex, fourceRepeat])
}, [trackIndex, fourceRepeat, forcePlayerUpdate])

/**
* clean the memory and pause the song for manage memory leak and
Expand Down Expand Up @@ -518,7 +524,8 @@ export const Reaplay = ({ tracks, startIndex = 0, children }: Props) => {
speed, // the speed range, 0.5 or 1 or 2
playSlow, // play slow playbackRate of track
playNormal, // play normal playbackRate of track
playFast // play fast playbackRate of track
playFast, // play fast playbackRate of track
forceUpdatePlayer // force Re-Render Player
}

// @ts-ignore
Expand Down Expand Up @@ -566,4 +573,5 @@ export interface PlayerType {
bufferedText: string
forward: Function
backward: Function
forceUpdatePlayer: Function
}
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"noImplicitThis": true,
"noImplicitAny": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"allowSyntheticDefaultImports": true
Expand Down

0 comments on commit 3afb709

Please sign in to comment.