Skip to content

Commit

Permalink
fix: avoid shared player bar on map posts
Browse files Browse the repository at this point in the history
  • Loading branch information
WaDadidou committed Sep 17, 2024
1 parent 3ea8b8c commit 8adc320
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
19 changes: 12 additions & 7 deletions packages/components/mediaPlayer/MediaPlayerBarRefined.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ export const MediaPlayerBarRefined: FC<{
}> = ({ mediaToPlay }) => {
const { handlePlayPause, media, loadAndPlaySoundsQueue, playbackStatus } =
useMediaPlayer();
const isInMediaPlayer = media?.postId === mediaToPlay.postId;

const onPressPlayPause = async () => {
if (!media && mediaToPlay) {
await loadAndPlaySoundsQueue([mediaToPlay]);
} else {
await handlePlayPause();
}
if (isInMediaPlayer) await handlePlayPause();
else await loadAndPlaySoundsQueue([mediaToPlay]);
};

return (
Expand All @@ -36,7 +34,9 @@ export const MediaPlayerBarRefined: FC<{
<CustomPressable onPress={onPressPlayPause}>
<SVG
source={
playbackStatus?.isPlaying && !playbackStatus?.didJustFinish
isInMediaPlayer &&
playbackStatus?.isPlaying &&
!playbackStatus?.didJustFinish
? pauseSVG
: playSVG
}
Expand All @@ -48,7 +48,12 @@ export const MediaPlayerBarRefined: FC<{
<SpacerRow size={0.5} />

<TimerSliderAlt
duration={mediaToPlay.duration || playbackStatus?.durationMillis || 0}
duration={
(isInMediaPlayer
? playbackStatus?.durationMillis
: mediaToPlay.duration) || 0
}
playbackStatus={isInMediaPlayer ? playbackStatus : undefined}
/>
</View>
);
Expand Down
6 changes: 4 additions & 2 deletions packages/components/mediaPlayer/TimerSliderAlt.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Slider from "@react-native-community/slider";
import { AVPlaybackStatusSuccess } from "expo-av";
import React, { FC, useState } from "react";
import { View } from "react-native";

Expand All @@ -20,8 +21,9 @@ import FlexRow from "@/components/FlexRow";
// Same as TimerSlider but with duration above the Slider
export const TimerSliderAlt: FC<{
duration: number;
}> = ({ duration }) => {
const { media, onChangeTimerPosition, playbackStatus } = useMediaPlayer();
playbackStatus?: AVPlaybackStatusSuccess;
}> = ({ duration, playbackStatus }) => {
const { media, onChangeTimerPosition } = useMediaPlayer();
const [isHovered, setIsHovered] = useState(false);
const [isSliding, setIsSliding] = useState(false);

Expand Down

0 comments on commit 8adc320

Please sign in to comment.