本文介绍了如何打之前完全加载声音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要玩它之前完全加载声音。玩家应该完全加载后会自动播放音频。不应该有暂停按钮/用户不能暂停。这里是我的code,但未能如愿。

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.

超文本标记语言:

<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?

推荐答案

尝试使用 XMLHtt prequest 返回的Blob 音频文件,新音频() .load()。玩()

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();

这篇关于如何打之前完全加载声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 22:21