feat: download button in player

This commit is contained in:
Adrian Castro
2024-03-21 12:06:35 +01:00
parent 460580b5c5
commit 30bf4c3d7a
2 changed files with 42 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ import { usePlayerStore } from "~/stores/player/store";
import { AudioTrackSelector } from "./AudioTrackSelector";
import { CaptionsSelector } from "./CaptionsSelector";
import { Controls } from "./Controls";
import { DownloadButton } from "./DownloadButton";
import { PlaybackSpeedSelector } from "./PlaybackSpeedSelector";
import { ProgressBar } from "./ProgressBar";
import { SeasonSelector } from "./SeasonEpisodeSelector";
@@ -79,6 +80,7 @@ export const BottomControls = () => {
<SourceSelector />
<AudioTrackSelector />
<PlaybackSpeedSelector />
<DownloadButton />
</View>
</View>
);

View File

@@ -0,0 +1,40 @@
import { MaterialCommunityIcons } from "@expo/vector-icons";
import { useTheme } from "tamagui";
import { findHighestQuality } from "@movie-web/provider-utils";
import { useDownloadManager } from "~/hooks/DownloadManagerContext";
import { usePlayerStore } from "~/stores/player/store";
import { MWButton } from "../ui/Button";
import { Controls } from "./Controls";
export const DownloadButton = () => {
const theme = useTheme();
const stream = usePlayerStore((state) => state.interface.currentStream);
const { startDownload } = useDownloadManager();
if (stream?.type !== "file") return null;
const highestQuality = findHighestQuality(stream);
const url = highestQuality ? stream.qualities[highestQuality]?.url : null;
if (!url) return null;
return (
<>
<Controls>
<MWButton
type="secondary"
icon={
<MaterialCommunityIcons
name="download"
size={24}
color={theme.buttonSecondaryText.val}
/>
}
onPress={() => startDownload(url, "mp4")}
>
Download
</MWButton>
</Controls>
</>
);
};