Audio Playback stops on Android after Short Duration, but plays fully on IOS.

Hello All,

I am in the process of working to implement some very simple Audio playback functionality in an App I’m creating with Expo. There are two pieces of audio currently and they both are playing and stopping perfectly fine on IOS (real device and simulator). When tested on Android, the audio plays for a period of time, then stops before reaching the full duration (normally about 30 secs total on either track. Full duration between the two tracks vary from 4 to 8 mins.)

Here’s a few snippets of my code, if more is needed please let me know:

const sounds = {
one: require(’…/asset/sound1.mp3’),
two: require(’…/asset/sound2.mp3’),
}

const [soundObj, setSoundObj] = useState(null);

handlePlaySound = async track => {
    
    if (soundObj === null) { 
        setSoundObj(new Audio.Sound());
    }

    try {

        let source = sounds[track]
        await soundObj.loadAsync(source) 

        await soundObj
            .playAsync()
            .then(async playbackStatus => {
                setTimeout(() => {
                    soundObj.unloadAsync()
                }, playbackStatus.playableDurationMillis)
            }).catch(error => {
                console.log(error)
            })
        } catch (error) { console.log(error) }
    }
    handleStopSound = async () => {
        await soundObj.stopAsync(); setSoundObj(null);
    }

SDK Version: 4.0.11
Platforms: Android/iOS

Hey @dvnerite, unfortunately there’s a good amount of nuance here that the code snippet simply can not cover. Can you please provide a public github repo that we can clone and test locally on our end? Also, please make sure you provide two remote urls for assets that you can confirm reproduce the incorrect android stoppage issue.

Lastly, can you let me know what device(s)/emulator(s) and android version(s) you’ve reproduced this on?

Cheers,
Adam

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.