rPlayer is a player play streaming radio, this player, offers the possibility to change different audio format. Example: .m3u8, .mp3, .aac.
npm install @davland7/rplayer
import audio from '@davland7/rplayer';
<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 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');
Important
rPlayer is optimized for HLS content. While HLS is native to Apple devices, for Windows and Android, it's crucial to use the hls.js library for proper .m3u8 stream functionality. Please ensure the use of hls.js on devices other than iPhone and iPad.
In addition to .m3u8, you can also use .mp3, .aac, .ogg and others. 😮
audio.playSrc('URL.aac');
Tip
You can use rPlayer without hls.js if you don't need to support HLS formats like .m3u8. juste not add hls.js to your project.
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. 😎
audio.stop();
audio.mute();
audio.rewind(10); // seconds
audio.upVolume();
A way not to make a mistake if the range is not good. 😉
10 levels up and down and blocks both ends. 😁
audio.downVolume();
Warning
On iOS devices such as iPad and iPhone, the audio level is always controlled by the user physically. This means that the volume property is not adjustable through JavaScript on iOS devices. When you read the volume property on iOS, it will always return 1, reflecting that the user has direct control over the device's volume. Additionally, the library will always return 1 on iOS.
The timeupdate event is fired when the time indicated by the currentTime attribute has been updated.
audio.ontimeupdate = function() {
console.log('Time:', audio.currentTime);
};
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.isHls);
console.log('Time:', audio.currentTime);
rPlayer 2.2.4