2

So I'm fairly new to using EXPO and building apps. I've been tasked to add a media player to a client's app and the setup I have currently works fine on iOS on both physical and emulator devices but when the play action is issued, the app crashes on Android, both physical and emulator devices.

Any help would be greatly appreciated. Below is a snippet of my code.

async function playSound() {
    console.log(`Loading link`);
    setIPlayer(true);
    
    const { sound } = await Audio.Sound.createAsync(
        source = {
            uri : "https://radio.canstream.co.uk:9129/live.mp3"
        }
    );

    setSound(sound);
    setIsPlaying(true);

    await sound.playAsync();
    
}

async function stopSound () {
    // await sound.stopAsync();
    await sound.pauseAsync();
    setIPlayer(false);
    setIsPlaying(false); 
}

useEffect(() => {

    const getNetwork = async () => {
        const res = await Network.getNetworkStateAsync();
        if(res.isConnected === false && res.isInternetReachable === false){
            setError(true);
        }
    }

    getNetwork();

    Audio.setAudioModeAsync({
        allowsRecordingIOS: false,
        // interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX,
        interruptionModeIOS: InterruptionModeIOS.DoNotMix,
        playsInSilentModeIOS: true,
        // interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DUCK_OTHERS,
        interruptionModeAndroid: InterruptionModeAndroid.DuckOthers,
        shouldDuckAndroid: true,
        staysActiveInBackground: true,
        playThroughEarpieceAndroid: false,
        androidImplementation: 'MediaPlayer'
    })

    return sound ? () => {
        sound.unloadAsync(); }
    : undefined;
}, [sound]);
  • I'm new as well, but I noticed that you're not using `await sound.stopAsync()` and `sound.unloadAsync()`. maybe this is why it's crashing? – WrRaThY Aug 26 '22 at 07:08
  • if you're getting a hard crash (i.e. at the native level -- the app closes and you see the launcher) it's always useful to open up logcat and see what the stacktrace says in the crash buffer – Kai Aug 26 '22 at 18:26
  • @WrRaThY yes, i do not have "await sound.stopAsync()" because it gives me a "Seeking interruption" error when i call that. I found that using "await sound.pauseAsync()" works fine since the audio source is a live stream. – Kwadwo Asante-Kwabiah Aug 27 '22 at 23:55

1 Answers1

0

So the crashing issue was caused by a component that was being toggled when the play action was triggered. Essentially a UI bug, had to tear down the app and rebuild from scratch just to spot it.

Thanks everyone!