Skip to content

Commit

Permalink
fix: media player bar fix
Browse files Browse the repository at this point in the history
  • Loading branch information
WaDadidou committed Sep 11, 2023
1 parent c397b84 commit 5ff6fb3
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 36 deletions.
10 changes: 6 additions & 4 deletions packages/components/FilePreview/AudioView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const AudioView: React.FC<{
media,
isPlaying,
handlePlayPause,
loadAndPlaySound,
loadAndPlayQueue,
playbackStatus,
} = useMediaPlayer();
const isInMediaPlayer = useMemo(
Expand All @@ -51,15 +51,17 @@ export const AudioView: React.FC<{
await handlePlayPause();
} else {
const songToPlay: Media = {
imageUrl: userInfo.metadata.image || undefined,
imageUrl:
file?.thumbnailFileData?.url || userInfo.metadata.image || undefined,
name: "Song from Social Feed",
createdBy: authorId,
fileUrl: file.url,
duration: file.audioMetadata?.duration,
// postId is used to difference audios from Social Feed (News feed or Article consultation)
// postId is used to difference audios from Social Feed (News feed or Article consultation)
postId: postId || Math.floor(Math.random() * 200000).toString(),
};
await loadAndPlaySound(songToPlay);
// TODO: Play songs of social feed: Add songs of next posts in queue
await loadAndPlayQueue([songToPlay]);
}
};

Expand Down
8 changes: 5 additions & 3 deletions packages/components/FilePreview/EditableAudioPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const EditableAudioPreview: React.FC<AudioPreviewProps> = ({
media,
isPlaying,
handlePlayPause,
loadAndPlaySound,
loadAndPlayQueue,
playbackStatus,
removeSound,
} = useMediaPlayer();
Expand All @@ -60,13 +60,15 @@ export const EditableAudioPreview: React.FC<AudioPreviewProps> = ({
await handlePlayPause();
} else {
const songToAdd: Media = {
imageUrl: userInfo.metadata.image || undefined,
imageUrl:
file.thumbnailFileData?.url || userInfo.metadata.image || undefined,
name: file.fileName,
createdBy: userId,
fileUrl: file.url,
duration: file.audioMetadata?.duration,
};
await loadAndPlaySound(songToAdd);
// TODO: Play songs of social feed: Add songs of next posts in queue
await loadAndPlayQueue([songToAdd]);
}
};
useEffect(() => {
Expand Down
18 changes: 14 additions & 4 deletions packages/components/mediaPlayer/MediaNameImage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FC } from "react";
import { Image, View } from "react-native";
import { Image, StyleProp, View, ViewStyle } from "react-native";

import { useMediaPlayer } from "../../context/MediaPlayerProvider";
import { useNSUserInfo } from "../../hooks/useNSUserInfo";
Expand All @@ -12,7 +12,9 @@ import { BrandText } from "../BrandText";
import { OmniLink } from "../OmniLink";
import { SpacerRow } from "../spacer";

export const MediaNameImage: FC = () => {
export const MediaNameImage: FC<{
style?: StyleProp<ViewStyle>;
}> = ({ style }) => {
const { media } = useMediaPlayer();
const authorNSInfo = useNSUserInfo(media?.createdBy);
const [, userAddress] = parseUserId(media?.createdBy);
Expand All @@ -26,6 +28,7 @@ export const MediaNameImage: FC = () => {
if (!media) return <View />;
return (
<OmniLink
style={[{ alignSelf: "flex-start" }, style]}
to={
media?.albumId
? {
Expand All @@ -52,11 +55,18 @@ export const MediaNameImage: FC = () => {
<View
style={{
justifyContent: "space-between",
flex: 1,
}}
>
<BrandText style={fontSemibold12}>{media.name}</BrandText>
<BrandText style={fontSemibold12} isTicker>
{media.name}
</BrandText>
{media?.createdBy && (
<BrandText style={[fontSemibold12, { color: neutral77 }]}>
<BrandText
style={[fontSemibold12, { color: neutral77 }]}
ellipsizeMode="middle"
numberOfLines={1}
>
{"@" + username}
</BrandText>
)}
Expand Down
17 changes: 14 additions & 3 deletions packages/components/mediaPlayer/MediaPlayerBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,25 @@ export const MediaPlayerBar: FC<{
color={playbackStatus?.isLooping ? secondaryColor : neutralA3}
/>
</CustomPressable>
<SpacerRow size={4} />
</View>
<SpacerRow size={4} />

<View style={{ flexDirection: "row", alignItems: "center" }}>
<View
style={{
flexDirection: "row",
alignItems: "center",
justifyContent: "flex-end",
flex: 1,
}}
>
<TimerSlider />
<SpacerRow size={4} />
<MediaNameImage />
<View style={{ maxWidth: 600, flex: 1 }}>
<MediaNameImage style={{ maxWidth: 600 }} />
</View>
</View>
<SpacerRow size={4} />

<VolumeSlider />
</View>
);
Expand Down
5 changes: 3 additions & 2 deletions packages/components/mediaPlayer/MediaPlayerBarMobile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const MediaPlayerBarMobile: FC<{
}}
>
{/*TODO: Test this on mobile*/}
<GestureHandlerRootView>
<GestureHandlerRootView style={{ flex: 1 }}>
<Swipeable
containerStyle={{
height: "100%",
Expand All @@ -67,9 +67,10 @@ export const MediaPlayerBarMobile: FC<{
onSwipeableRightOpen={canPrev ? prevMedia : undefined}
onSwipeableLeftOpen={canNext ? nextMedia : undefined}
>
<MediaNameImage />
<MediaNameImage style={{ width: "100%" }} />
</Swipeable>
</GestureHandlerRootView>
<SpacerRow size={2} />

<View style={{ flexDirection: "row", alignItems: "center" }}>
<CustomPressable onPress={() => setIsRandom((isRandom) => !isRandom)}>
Expand Down
34 changes: 17 additions & 17 deletions packages/components/mediaPlayer/TimerSliderMobile.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import Slider from "@react-native-community/slider";
import React, { FC, useState } from "react";
import { View } from "react-native";

import { useMediaPlayer } from "../../context/MediaPlayerProvider";
import { neutral55, secondaryColor } from "../../utils/style/colors";

export const TimerSliderMobile: FC = () => {
const { media, playbackStatus } = useMediaPlayer();
const [width, setWidth] = useState(0);
const minimumTrackWidth =
width && media?.duration && playbackStatus?.positionMillis
? width / (media.duration / playbackStatus.positionMillis)
: 0;
const { media, playbackStatus, onChangeTimerPosition } = useMediaPlayer();

return (
<View
style={{ flexDirection: "row", width: "100%" }}
onLayout={(e) => setWidth(e.nativeEvent.layout.width)}
>
<View
style={{
width: minimumTrackWidth,
height: 4,
backgroundColor: secondaryColor,
}}
/>
<View
style={{
width: width - minimumTrackWidth,
height: 4,
backgroundColor: neutral55,
<Slider
onSlidingComplete={(a: number) => onChangeTimerPosition(a)}
value={playbackStatus?.positionMillis}
tapToSeek
// @ts-expect-error FIXME: thumbStyle only allowed in SliderPropsWindows
thumbStyle={{
width: 0,
height: 0,
}}
thumbTintColor={secondaryColor}
maximumValue={media?.duration}
minimumTrackTintColor={secondaryColor}
maximumTrackTintColor={neutral55}
//TODO: Increase bar height is isSliding. By extension, change style, remove borderRadius etc. But this style prop doesn't allow to style the bar :'(
style={{ width }}
disabled={!media}
/>
</View>
);
Expand Down
3 changes: 0 additions & 3 deletions packages/context/MediaPlayerProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ interface DefaultValue {
isMediaPlayerOpen: boolean;
setIsMediaPlayerOpen: Dispatch<SetStateAction<boolean>>;
loadAndPlayQueue: (queue: Media[], mediaToStart?: Media) => Promise<void>;
loadAndPlaySound: (media: Media, queue?: Media[]) => Promise<void>;
removeSound: () => Promise<void>;
canNext: boolean;
canPrev: boolean;
Expand All @@ -44,7 +43,6 @@ const defaultValue: DefaultValue = {
isMediaPlayerOpen: false,
setIsMediaPlayerOpen: () => {},
loadAndPlayQueue: async () => {},
loadAndPlaySound: async () => {},
removeSound: async () => {},
canNext: false,
canPrev: false,
Expand Down Expand Up @@ -212,7 +210,6 @@ export const MediaPlayerContextProvider: React.FC = ({ children }) => {
isMediaPlayerOpen,
setIsMediaPlayerOpen,
loadAndPlayQueue,
loadAndPlaySound,
removeSound,
canNext,
canPrev,
Expand Down

0 comments on commit 5ff6fb3

Please sign in to comment.