I'm trying to get an mp3 file, so I can play it as audio. Here is a portion of my code:
export default function App() {
const sound = new Audio.Sound();
const [text, setText] = useState('NOT LOADED');
let test = "idek.mp3"
test = "idek_backup_hd.mp3"
async function playSound() {
if (sound._loaded) {
setText("UNLOADING");
await sound.unloadAsync();
}
setText("LOADING");
await sound.loadAsync(Image.resolveAssetSource({ 'uri': `asset:/${test}` }), {shouldPlay: true});
setText("PLAYING");
}
return (
<View style={styles.container}>
<Text style={styles.text}>{text}</Text>
<TouchableOpacity style={styles.button} onPress={async () => {
await playSound('idek_backup_hd.mp3');
}}>
<Text style={styles.text}>Play</Text>
</TouchableOpacity>
<StatusBar style="auto" />
</View>
);
}
For whatever reason, asset:/
doesn't seem to work here. In the error it outputs, it says:
Error: com.google.android.exoplayer2.upstream.AssetDataSource$AssetDataSourceException: java.io.FileNotFoundException: idek_backup_hd.mp3
I tried it in an emulator and on my physical Android device, and it didn't work.
I haven't tried anything to fix this, as I genuinely don't know how (which is why I'm making this question). Well, I have gone onto the documentation, but that didn't help me... unless I'm missing something? I don't know.
So, can someone help me fix this please?
Edit: I found a question just like this, except that one is for videos and has no answers.