Cross Platform audio streaming Module for React native
- Background play
- Notification
- Support for online streaming and offline files
npm install react-track-player --save
yarn add react-track-player
import { TrackPlayer } from "react-track-player";
load = () => {
TrackPlayer.load(
"https://dl.dropboxusercontent.com/s/8avcnxmjtdujytz/Sher%20Aaya%20Sher.mp3?dl=0"
).then(() => {
console.log("audio loaded");
});
};
play = () => {
TrackPlayer.play();
};
pause = () => {
TrackPlayer.pause();
};
import { DeviceEventEmitter } from "react-native";
subscription = DeviceEventEmitter.addListener("media", function (event) {
// handle event
console.log("from event listener", event);
if (event == "skip_to_next") {
dispatch(skipToNext());
} else if (event == "skip_to_previous") {
dispatch(skipToPrevious());
} else if (event == "completed") {
dispatch(skipToNext());
} else {
dispatch({
type: "STATUS",
status: event,
});
}
});
subscription.remove();
A component base that updates itself every second with a new position.
import { ProgressBar } from 'react-track-player';
ProgressBar interacts with native audio module and updates the progress. All you need to do is render <ProgressBar>
with your styles if you want.
Demo app is in /example
directory