Created
September 25, 2017 16:58
-
-
Save trepidity/f8692c4a058ec7719f34e59701a25a82 to your computer and use it in GitHub Desktop.
Example of calling React Native Sound
This file contains 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
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