我当前正在尝试暂停或停止正在播放的声音。我正在使用博览会的“音频”。
handlePlaySound方法可以完美地工作,可以播放给定的声音,但是我无法停止播放声音。
这是我的代码:
handlePlaySound = async note => {
const soundObject = new Audio.Sound()
try {
let source = xyloSounds[note]
await soundObject.loadAsync(source)
await soundObject
.playAsync()
.then(async playbackStatus => {
setTimeout(() => {
soundObject.unloadAsync()
}, playbackStatus.playableDurationMillis)
})
.catch(error => {
console.log(error)
})
} catch (error) {
console.log(error)
}
}
Stop = async note => {
const soundObject = new Audio.Sound()
try {
let source = xyloSounds[note]
await soundObject.stopAsync();
} catch (error) {
console.log(error)
}
}
const SoundScreen = props => {
return (
<ScrollView>
<TouchableOpacity style={styles.color3}
onPress={() => this.Stop('sound1')}>
<Text>STOP</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.color3}
onPress={() => this.handlePlaySound('sound2')}>
<Text>PLAY</Text>
</TouchableOpacity>
提前谢谢