rPlayer in Action

rPlayer is a player play streaming radio, this player, offers the possibility to change different audio format. Example: .m3u8, .mp3, .aac.

You listening The Beat 92.5

Source: 
Playing: 
Paused: 
Muted: 
Volume: 
hls.js: 
Time: 

Easy to use

NPM

Install the package via npm.

npm install @davland7/rplayer

Import the package and use it in your project.

import rPlayer from '@davland7/rplayer';

const audio = new rPlayer();

CDN

<script src="https://cdn.jsdelivr.net/npm/hls.js@1.5.3/dist/hls.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@davland7/rplayer@2.2.4/dist/rplayer.umd.min.js"></script>
const audio = new rPlayer();

rPlayer is extending Audio HTMLMediaElement

Play

Play doesn't work with HLS. 🙁

const audio = new Audio('URL.m3u8');
audio.play();

Or

audio.src = 'URL.m3u8';
audio.play();

Works with HLS. It's Magic 💪

audio.playSrc('URL.m3u8');

In addition to .m3u8, you can also use .mp3, .aac, .ogg and others. 😮

audio.playSrc('URL.aac');

Set Volume

The volume must not be outside the range [0, 1].

audio.volume = 0.2; // 0.2 Default set in local storage

localStorage is very cool. 😎

Extras

Stop

audio.stop();

Mute

audio.mute();

Rewind

audio.rewind(10); // seconds

Volume Up

audio.upVolume();

A way not to make a mistake if the range is not good. 😉

Volume Down

10 levels up and down and blocks both ends. 😁

audio.downVolume();

timeupdate event

The timeupdate event is fired when the time indicated by the currentTime attribute has been updated.

audio.ontimeupdate = function() {
  console.log('Time:', audio.currentTime);
};

Infos

console.log('Source:', audio.url);
console.log('Playing:', audio.playing);
console.log('Paused:', audio.paused);
console.log('Muted:', audio.muted);
console.log('Volume:', audio.volume * 100);
console.log('hls.js:', audio.isHlsjs);
console.log('Time:', audio.currentTime);