Git Product home page Git Product logo

music_stream_app's Introduction

react-native-music-streamer

A react-native audio streaming module (for Android only), using ExoPlayer.

THIS IS NOT PRODUCTION READY. Last I recall things are a bit broken. Feel free to build upon it, but use at own risk.

Features

  • Music playback using foreground service
  • Fast playback start due to using ExoPlayer
  • Configurable notification
  • Autoupdate current title from stream (Shoutcast/Icecast compatible format)
  • Stops when headphone unplugs and for incoming calls

Installation

TODO

Usage

Basic

import RNMusicStreamer from 'react-native-music-streamer';

// Prepare player
RNMusicStreamer.prepare(
  'http://someurl', // stream url
  {
    title: str // "title" for notification (optional)
    album: str, // "album" for notification (optional)
    artist: str, // "artist" for notification (optional)
    metadataFromStream: bool, // If true, title will be set from stream metadata. Updates every 10s. 'title' property will be used as placeholder. (optional)
    artwork: obj/str, // artwork for notification. Either a url as string, or a react-native format {uri: ...} object for local image. (optional)
  }
)
RNMusicStreamer.play()
RNMusicStreamer.pause()
RNMusicStreamer.stop()
RNMusicStreamer.seekToTime(16) //seconds
RNMusicStreamer.duration().then(duration => {
  console.log(duration) //seconds
})
RNMusicStreamer.currentTime().then(currentTime => {
  console.log(currentTime) //seconds
})

// Player Status:
// - PLAYING
// - PAUSED
// - STOPPED
// - FINISHED
// - BUFFERING
// - ERROR
RNMusicStreamer.status().then(status => {
  console.log(status)
})

RNMusicStreamer.getCurrentUrl().then(url => {
  console.log(url)
})

Status Change Observer

The status changes a lot upon preparation, so you should consider some debounce mechanism.

const {
  DeviceEventEmitter
} = 'react-native'

// Player Status:
// - PLAYING
// - PAUSED
// - STOPPED
// - FINISHED
// - BUFFERING
// - ERROR
DeviceEventEmitter.addListener(
  'RNMusicStreamerStatusChanged',
  status => console.log('Status changed: ', status)
)

Metadata Change Observer

Called every 10 seconds if using {metadataFromStream: true} in prepare(). Lets you use the metadata in your application.

const {
  DeviceEventEmitter
} = 'react-native'

DeviceEventEmitter.addListener(
  'RNMusicStreamerMetadataChanged',
  metadata => console.log('Metadata changed: ', metadata)
)

TODO

  • Code cleanup
  • Add bandwith usage data
  • Better handling of service lifecycle (it now lives as long as the module)

Credits

This project is built upon react-native-audio-streamer (MIT), adding more functionality for Android.

Icons by Font Awesome.

music_stream_app's People

Contributors

kailos301 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.