I am using Audio API from 'expo-av' library. On pressing the button I should hear audio but I am getting the warning Possible Unhandled Promise Rejection (id: 2): Error: Player does not exist.
On first it was running fine but after one or two tries this error kept on persisting even on removing the $setTimeout() $
export default class App extends Component {
async playAudio (Number){
const SoundObject = new Audio.Sound();
try {
let path = AudioList[Number];
await SoundObject.loadAsync(path);
await SoundObject.playAsync()
.then(async playbackStatus => {
setTimeout(() => {
SoundObject.unloadAsync();
},playbackStatus.playbackDurationMillis)
})
.catch((error) => {
console.log(error);
})
} catch (err) {
console.log(err);
}
}
render(){
return (
<View style={styles.container}>
<View style={styles.grid}>
<Image
source={require('./assets/logo.png')}
style={styles.image}
/>
<View style={styles.row}>
<TouchableOpacity
style={[{backgroundColor: BackgroundNumber[1]}, styles.item]}
onPress={() => this.playAudio("one")}
>
<Text style={styles.itemText}>One</Text>
</TouchableOpacity>
</View>
</View>
</View>
);
}
}