项目作者: AllThatSeries

项目描述 :
Streaming audio player for both iOS and android
高级语言: Java
项目地址: git://github.com/AllThatSeries/react-native-streaming-audio-player.git
创建时间: 2017-02-21T15:55:31Z
项目社区:https://github.com/AllThatSeries/react-native-streaming-audio-player

开源协议:MIT License

下载


react-native-streaming-audio-player npm version

Streaming audio player for iOS + Android

Features

  • Play remote streaming audio source
  • Handle audio focus for…
    • incoming and outgoing calls
    • switching application contexts
  • Control audio from notification and lock screen (Android)
  • Control audio from control center and lock screen (iOS)
  • Control audio from headsets

Installation

First, install the library from npm:

  1. npm install react-native-streaming-audio-player --save

Second, link the native dependencies.

  1. react-native link react-native-streaming-audio-player

Running a sample app

In the Example directory:

  1. cd Examples
  2. npm install
  3. react-native run-ios or run-android

Usage

  1. import Player from 'react-native-streaming-audio-player';
  2. export default class Example extends Component {
  3. constructor(props) {
  4. super(props);
  5. this.state = { currentTime: 0 }
  6. this.onUpdatePosition = this.onUpdatePosition.bind(this);
  7. }
  8. onPlay() {
  9. Player.play(source.url, {
  10. title: source,
  11. artist: source.artist,
  12. album_art_uri: source.arworkUrl,
  13. });
  14. }
  15. onPause() {
  16. Player.pause();
  17. }
  18. render() {
  19. return (
  20. <View style={styles.container}>
  21. <View style={{ flexDirection: 'row', alignSelf: 'stretch', justifyContent: 'space-around' }}>
  22. <Button
  23. title='Play'
  24. onPress={() => this.onPlay()}
  25. color='red'
  26. />
  27. <Button
  28. title='Pause'
  29. onPress={() => this.onPause()}
  30. color='red'
  31. />
  32. </View>
  33. </View>
  34. );
  35. }
  36. }
  37. const styles = StyleSheet.create({
  38. container: {
  39. flex: 1,
  40. justifyContent: 'center',
  41. alignItems: 'center',
  42. },
  43. });

API and Configuration

Player Control

  • play(url: string, metadata: object)
    • metadata.title
    • metadata.artist
    • metadata.album_art_uri
  • pause()
  • stop()

Callbacks

  • onPlaybackStateChanged
  • onUpdatePosition

PlaybackState

  • NONE
  • PLAYING
  • BUFFERING
  • PAUSED
  • STOPPED
  • COMPLETED

PlayerAction

  • Play
  • Pause
  • SkipToNext
  • SkipToPrevious

Roadmap

  • Unit tests
  • Clean up

Contribute

License

This project is licensed under the MIT License - see the LICENSE file for details