react-native-sound-demo
Version:
react-native-sound demo project
48 lines (42 loc) • 923 B
JavaScript
;
import React, {
Component,
StyleSheet,
Text,
TouchableOpacity,
View
} from 'react-native';
var Sound = require('react-native-sound');
class MainView extends Component {
render() {
return <View style={styles.container}>
<TouchableOpacity onPress={this.playSound}>
<Text style={styles.button}>play</Text>
</TouchableOpacity>
</View>;
}
playSound() {
var s = new Sound('advertising.mp3', Sound.MAIN_BUNDLE, (e) => {
if (e) {
console.log('error', e);
} else {
console.log('duration', s.getDuration());
s.play();
}
});
}
}
var styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
},
button: {
fontSize: 20,
backgroundColor: 'silver',
padding: 5,
},
});
export default MainView;