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