Skip to content

Instantly share code, notes, and snippets.

@trepidity
Created September 25, 2017 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trepidity/f8692c4a058ec7719f34e59701a25a82 to your computer and use it in GitHub Desktop.
Save trepidity/f8692c4a058ec7719f34e59701a25a82 to your computer and use it in GitHub Desktop.
Example of calling React Native Sound
function playMedia(media) {
alert(media);
const sound = new Sound(media, (error) => {
if (error) {
console.log(error);
} else {
console.log('Playing sound');
console.log(`Duration in seconds: ${sound.getDuration()}`);
// Get the current playback point in seconds
sound.getCurrentTime(seconds => console.log(`at ${seconds}`));
sound.play(() => {
// Release when it's done so we're not using up resources
sound.release();
});
}
});
}
_onPressItem = () => {
playMedia(this.props.media);
this.setState({ media: 'PLAYING' });
console.log(`state ${this.state.media}`);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment