Delete src/core/plugins/CustomBackgroundMusic directory
This commit is contained in:
parent
d8b35b5501
commit
40726d5b9a
2 changed files with 0 additions and 98 deletions
|
|
@ -1,33 +0,0 @@
|
|||
import { storage } from "@vendetta/plugin";
|
||||
import { useProxy } from "@vendetta/storage";
|
||||
import { getAssetIDByName } from "@vendetta/ui/assets";
|
||||
import { Forms, General } from "@vendetta/ui/components";
|
||||
import { settings, playFromUrl } from ".";
|
||||
|
||||
const { FormSection, FormRow, FormIcon, FormInput } = Forms;
|
||||
|
||||
export default function Settings() {
|
||||
useProxy(storage);
|
||||
|
||||
return (
|
||||
<General.ScrollView style={{ flex: 1 }}>
|
||||
<FormSection title="Background Music">
|
||||
<FormRow
|
||||
label="Music URL"
|
||||
leading={<FormIcon source={getAssetIDByName("ic_link")} />}
|
||||
/>
|
||||
<FormInput
|
||||
title=""
|
||||
keyboardType="url"
|
||||
placeholder="https://link.to/music.mp3"
|
||||
value={settings.url}
|
||||
onChange={(x: string) => {
|
||||
settings.url = x;
|
||||
if (x) playFromUrl(x);
|
||||
}}
|
||||
style={{ marginTop: -25, marginHorizontal: 12 }}
|
||||
/>
|
||||
</FormSection>
|
||||
</General.ScrollView>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
import { findByProps } from "@vendetta/metro";
|
||||
import { ReactNative } from "@vendetta/metro/common";
|
||||
import { storage } from "@vendetta/plugin";
|
||||
import Settings from "./Settings";
|
||||
import { defineCorePlugin } from "..";
|
||||
|
||||
const { DCDSoundManager } = ReactNative.NativeModules;
|
||||
|
||||
export const settings: { url?: string } = storage;
|
||||
|
||||
const SOUND_ID = 6973;
|
||||
|
||||
let isPlaying = false;
|
||||
let loopTimeoutId: ReturnType<typeof setTimeout> | null = null;
|
||||
let currentUrl: string | null = null;
|
||||
|
||||
function prepareSound(url: string): Promise<number> {
|
||||
return new Promise((resolve) => {
|
||||
DCDSoundManager.prepare(url, "music", SOUND_ID, (error: any, sound: any) => {
|
||||
if (error) return resolve(-1);
|
||||
resolve(sound?.duration ?? -1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function stopLoop() {
|
||||
isPlaying = false;
|
||||
if (loopTimeoutId) {
|
||||
clearTimeout(loopTimeoutId);
|
||||
loopTimeoutId = null;
|
||||
}
|
||||
DCDSoundManager.stop(SOUND_ID);
|
||||
}
|
||||
|
||||
// Exported so Settings.tsx can call this the moment the URL changes
|
||||
export async function playFromUrl(url: string) {
|
||||
if (!url) return;
|
||||
|
||||
stopLoop();
|
||||
currentUrl = url;
|
||||
|
||||
const duration = await prepareSound(url);
|
||||
if (duration === -1 || currentUrl !== url) return;
|
||||
|
||||
isPlaying = true;
|
||||
|
||||
const cycle = async () => {
|
||||
if (!isPlaying || currentUrl !== url) return;
|
||||
await DCDSoundManager.play(SOUND_ID);
|
||||
loopTimeoutId = setTimeout(cycle, duration);
|
||||
};
|
||||
|
||||
cycle();
|
||||
}
|
||||
|
||||
export default {
|
||||
onLoad: () => {
|
||||
if (settings.url) playFromUrl(settings.url);
|
||||
},
|
||||
onUnload: () => {
|
||||
stopLoop();
|
||||
currentUrl = null;
|
||||
},
|
||||
settings: Settings,
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue