Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function playSongAsync({ audio }) {
if (playingAudio) {
await playingAudio.pauseAsync();
}
playingAudio = new Audio.Sound();
try {
await playingAudio.loadAsync(
{ uri: audio },
{ progressUpdateIntervalMillis: 100 },
);
await playingAudio.playAsync();
// soundObject.setOnPlaybackStatusUpdate(this._updateStateToStatus);
// const status = await soundObject.getStatusAsync();
// this._updateStateToStatus(status);
// this._sound = soundObject;
} catch (error) {
alert(error.message);
// this.setState({ errorMessage: error.message });
}
}
.then(() => {
const newSoundObject = new Audio.Sound()
newSoundObject
.loadAsync({ uri: audio })
.then((response) => {
newSoundObject.setOnPlaybackStatusUpdate((statusData) => {
const { didJustFinish } = statusData
if (didJustFinish) {
this.setState({ playingRecording: '', soundObject: undefined })
}
})
return newSoundObject.playAsync()
})
.then(() => {
this.setState({ playingRecording: _id, soundObject: newSoundObject })
})
.catch((error) => {
console.log(error)
constructor () {
this.soundObject = new Audio.Sound()
this.soundObject.setOnPlaybackStatusUpdate(this._onPlaybackStatusUpdate)
}
useEffect(() => {
const sound = new Audio.Sound();
sound.setOnPlaybackStatusUpdate(status => {
handlePlaybackStatusUpdate(sound, status);
});
sound.loadAsync(props.source, { progressUpdateIntervalMillis: 150 }).catch(setError);
return () => {
setPlayback({ isLoaded: false });
sound.setOnPlaybackStatusUpdate(null);
sound.unloadAsync();
};
}, [props.source.uri]);
public getSound(id: string) {
return new Audio.Sound();
}
_loadSoundAsync = async (source: PlaybackSource) => {
const soundObject = new Audio.Sound();
try {
await soundObject.loadAsync(source, { progressUpdateIntervalMillis: 150 });
soundObject.setOnPlaybackStatusUpdate(this._updateStateToStatus);
const status = await soundObject.getStatusAsync();
this._updateStateToStatus(status);
this._sound = soundObject;
} catch (error) {
this.setState({ errorMessage: error.message });
}
};