-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from THEOplayer/feature/replace_slider
Feature/replace slider
- Loading branch information
Showing
18 changed files
with
440 additions
and
379 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { useCallback, useContext, useSyncExternalStore } from 'react'; | ||
import { PlayerContext } from '@theoplayer/react-native-ui'; | ||
import { type PlayerEventMap, PlayerEventType } from 'react-native-theoplayer'; | ||
|
||
const TIME_CHANGE_EVENTS = [PlayerEventType.TIME_UPDATE, PlayerEventType.SEEKING, PlayerEventType.SEEKED] satisfies ReadonlyArray< | ||
keyof PlayerEventMap | ||
>; | ||
|
||
/** | ||
* Returns {@link react-native-theoplayer!THEOplayer.duration | the player's current time}, automatically updating whenever it changes. | ||
* | ||
* This hook must only be used in a component mounted inside a {@link THEOplayerDefaultUi} or {@link UiContainer}, | ||
* or alternatively any other component that provides a {@link PlayerContext}. | ||
* | ||
* @group Hooks | ||
*/ | ||
export const useCurrentTime = () => { | ||
const { player } = useContext(PlayerContext); | ||
const subscribe = useCallback( | ||
(callback: () => void) => { | ||
TIME_CHANGE_EVENTS.forEach((event) => player?.addEventListener(event, callback)); | ||
return () => TIME_CHANGE_EVENTS.forEach((event) => player?.removeEventListener(event, callback)); | ||
}, | ||
[player], | ||
); | ||
return useSyncExternalStore(subscribe, () => (player ? player.currentTime : 0)); | ||
}; |
Oops, something went wrong.