我正在使用react-native-sound来实现播放音频的功能,但是我不希望它从一开始就播放,而是从特定的时间开始播放,如何实现呢?我尝试使用sound.setCurrentTime(),但是没有用! 我想在sound.play之后立即执行sound.setCurrentTime(),但是没有用。
import React from 'react';
import { View, Text, Dimensions, StyleSheet, Image, ImageBackground, Button, TouchableOpacity } from 'react-native';
import Sound from 'react-native-sound';
let demoAudio = require('../resource/video/test/61yz.mp3');
var sound = new Sound(demoAudio, (e) => {
if (e) {
alert('error');
return;
}
});
export default class Book extends React.Component {
static navigationOptions =
({ navigation }) =>({
title: navigation.state.params.name,
});
constructor(){
super();
}
render() {
return (
<View style={styles.container}>
<ImageBackground style={styles.img} source={require('../resource/pdf/test/img237.jpg')} >
<TouchableOpacity style={styles.border} onPress={this.read}>
</TouchableOpacity>
</ImageBackground>
</View>
)
}
read = ()=>{
setTimeout(()=>{
sound.play();
setTimeout(()=>{sound.setCurrentTime(5.0)},1);
}
,1)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'flex-start',
},
img: {
marginTop: 25,
width: '100%',
height: '100%',
},
border: {
marginTop: 40,
marginLeft: '5%',
alignItems: 'center',
borderColor: '#ff0000',
width: '90%',
height: 90,
borderWidth: 3,
},
});