Last active
August 12, 2018 09:44
-
-
Save shihabbinali/abe6fad299e6fb01199bbdea45df4b68 to your computer and use it in GitHub Desktop.
audio player
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {Component} from 'react'; | |
import {StyleSheet, TouchableOpacity, View, ScrollView, Alert} from 'react-native'; | |
import { | |
Button, | |
Header, | |
ListItem, | |
Text, | |
Left, | |
List, | |
Title, | |
Row, | |
Content, | |
Right, | |
Icon, | |
Container, | |
Body, | |
Grid, | |
Col | |
} from 'native-base'; | |
import Sound from 'react-native-sound'; | |
const Button = ({title, onPress}) => ( | |
<Button onPress={onPress}> | |
<Text>{title}</Text> | |
</Button> | |
); | |
const audioTests = [ | |
{ | |
title: '1.mp3', | |
url: '1.mp3', | |
}, | |
{ | |
title: '2.mp3', | |
url: '2.mp3', | |
}, | |
{ | |
title: '3.mp3', | |
url: '3.mp3', | |
}, | |
{ | |
title: '4.mp3', | |
url: '4.mp3', | |
}, | |
{ | |
title: '5.mp3', | |
url: '5.mp3', | |
}, | |
]; | |
function playSound(testInfo, component) { | |
that = component; | |
song = new Sound('audio_'+testInfo.url, Sound.MAIN_BUNDLE, (error) => { | |
that.setState({duration: song.getDuration(), isLoaded:true }); | |
if (error){ | |
// | |
} | |
else { | |
song.play((success) => { | |
song.release(); | |
}); | |
} | |
}); | |
} | |
function playAll(component) { | |
that = component; | |
Object.keys(audioTests).forEach(function(key) { | |
setTimeout(function(key) { | |
playSound2(audioTests[key], that) | |
}, key * that.state.duration, key); | |
}); | |
} | |
class MainView extends Component { | |
constructor(props) { | |
super(props); | |
// Sound.setCategory('Playback', true); // true = mixWithOthers | |
this.state = { | |
tests: {}, | |
duration: 0, | |
isLoaded: false | |
}; | |
} | |
render() { | |
return ( | |
<Container> | |
<Header/> | |
<Content> | |
<Button onPress={() => { return playAll(this)}}> | |
<Icon name="play"/> | |
</Button> | |
</Content> | |
</Container> | |
); | |
} | |
} | |
export default MainView; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment