Skip to content

Instantly share code, notes, and snippets.

@lmansur
Created December 24, 2018 16:56
Show Gist options
  • Save lmansur/91bde714c2cb72bbcf17c21e28ed4270 to your computer and use it in GitHub Desktop.
Save lmansur/91bde714c2cb72bbcf17c21e28ed4270 to your computer and use it in GitHub Desktop.
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/
import React, {PureComponent} from 'react';
import {
AppRegistry, Button, StyleSheet, View
} from 'react-native';
import TrackPlayer from 'react-native-track-player';
export default class App extends PureComponent {
play() {
TrackPlayer.play();
}
pause() {
TrackPlayer.pause();
}
stop() {
TrackPlayer.stop();
}
render() {
TrackPlayer.setupPlayer().then(async () => {
TrackPlayer.updateOptions({
capabilities: [
TrackPlayer.CAPABILITY_PLAY,
TrackPlayer.CAPABILITY_PAUSE,
TrackPlayer.CAPABILITY_STOP
],
});
// Adds a track to the queue
await TrackPlayer.add({
id: 'trackId',
url: 'https://dts.podtrac.com/redirect.mp3/download.softskills.audio/sse-136.mp3',
title: 'Episode 136',
artist: 'Soft Skills',
});
});
return (
<View style={styles.container}>
<Button
onPress={this.play}
style={styles.playButton}
title="Play"
/>
<Button
onPress={this.pause}
style={styles.pauseButton}
title="Pause"
/>
<Button
onPress={this.stop}
style={styles.stopButton}
title="Stop"
/>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
justifyContent: 'space-evenly',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
playButton: {
flex: 0.5
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
AppRegistry.registerComponent('App', () => App);
TrackPlayer.registerEventHandler(require('./player-handler.js'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment