Created
December 24, 2018 16:56
-
-
Save lmansur/91bde714c2cb72bbcf17c21e28ed4270 to your computer and use it in GitHub Desktop.
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
/** | |
* 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