mirror of
https://github.com/jellyfin/jellyfin-expo.git
synced 2024-11-27 08:10:32 +00:00
Fix seeking in native audio player
This commit is contained in:
parent
0253a01376
commit
9826f8be1f
@ -29,6 +29,7 @@ const AudioPlayer = observer(() => {
|
||||
});
|
||||
|
||||
return () => {
|
||||
player?.stopAsync();
|
||||
player?.unloadAsync();
|
||||
};
|
||||
}, []);
|
||||
@ -36,29 +37,36 @@ const AudioPlayer = observer(() => {
|
||||
// Update the player when media type or uri changes
|
||||
useEffect(() => {
|
||||
const createPlayer = async ({ uri, positionMillis }) => {
|
||||
const { sound } = await Audio.Sound.createAsync({
|
||||
uri
|
||||
}, {
|
||||
positionMillis,
|
||||
shouldPlay: true
|
||||
}, ({
|
||||
isPlaying,
|
||||
positionMillis: positionMs,
|
||||
didJustFinish
|
||||
}) => {
|
||||
if (
|
||||
didJustFinish === undefined ||
|
||||
isPlaying === undefined ||
|
||||
positionMs === undefined ||
|
||||
rootStore.mediaStore.isFinished
|
||||
) {
|
||||
return;
|
||||
}
|
||||
rootStore.mediaStore.isFinished = didJustFinish;
|
||||
rootStore.mediaStore.isPlaying = isPlaying;
|
||||
rootStore.mediaStore.positionTicks = msToTicks(positionMs);
|
||||
});
|
||||
setPlayer(sound);
|
||||
const { isLoaded } = await player?.getStatusAsync() || { isLoaded: false };
|
||||
if (isLoaded) {
|
||||
// If the player is already loaded, seek to the correct position
|
||||
player.setPositionAsync(positionMillis);
|
||||
} else {
|
||||
// Create the player if not already loaded
|
||||
const { sound } = await Audio.Sound.createAsync({
|
||||
uri
|
||||
}, {
|
||||
positionMillis,
|
||||
shouldPlay: true
|
||||
}, ({
|
||||
isPlaying,
|
||||
positionMillis: positionMs,
|
||||
didJustFinish
|
||||
}) => {
|
||||
if (
|
||||
didJustFinish === undefined ||
|
||||
isPlaying === undefined ||
|
||||
positionMs === undefined ||
|
||||
rootStore.mediaStore.isFinished
|
||||
) {
|
||||
return;
|
||||
}
|
||||
rootStore.mediaStore.isFinished = didJustFinish;
|
||||
rootStore.mediaStore.isPlaying = isPlaying;
|
||||
rootStore.mediaStore.positionTicks = msToTicks(positionMs);
|
||||
});
|
||||
setPlayer(sound);
|
||||
}
|
||||
};
|
||||
|
||||
if (rootStore.mediaStore.type === MediaTypes.Audio) {
|
||||
|
Loading…
Reference in New Issue
Block a user