I have to load audio completely before playing it. Player should play audio automatically after loading it completely. There should not be pause button/user can not pause it. Here's my code, but unable to do so.
Hyper Text Markup Language:
<audio class="audio-player" onloadeddata="myOnLoadedData()" onprogress="myOnProgress()" src="<?php echo $audio_link;?>" controls>
JavaScript:
function myOnLoadedData() {
console.log('Loaded data');
$('audio.audio-player').attr('autoplay','autoplay');
}
function myOnProgress(){
console.log('downloading');
}
Or is there any other player that meets my requirement?
Try using XMLHttpRequest
to return Blob
of audio file, new Audio()
, .load()
, .play()
var request = new XMLHttpRequest();
request.open("GET", "/path/to/audio/file/", true);
request.responseType = "blob";
request.onload = function() {
if (this.status == 200) {
var audio = new Audio(URL.createObjectURL(this.response));
audio.load();
audio.play();
}
}
request.send();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With