Home > front end >  IOS audio audio automatically play there will be 2 seconds delay, could you tell me how to solve the
IOS audio audio automatically play there will be 2 seconds delay, could you tell me how to solve the

Time:09-22

& lt; ! DOCTYPE html>
& lt; HTML lang="en" & gt;
& lt; head>
& lt; Meta charset="utf-8" & gt;
& lt; Meta name="viewport" content="width=device - width, initial - scale=1, the user - scalable=0" & gt;
& lt; title> Document
& lt; The script type="text/javascript" SRC="http://res.wx.qq.com/open/js/jweixin-1.0.0.js" & gt; & lt;/script>

& lt; script>
//audio preloaded
Document. The addEventListener (" WeixinJSBridgeReady ", function () {
Document. The getElementById (' JGG). Play ()
}, false);
& lt;/script>
& lt;/head>
& lt; body>
& lt; JGG audio id="" SRC=" https://bbs.csdn.net/topics/style/jgg.mp3 "the autoplay=" the autoplay "& gt; & lt;/audio>
& lt;/body>
& lt;/html>

CodePudding user response:

Have a great god know how the whole?

CodePudding user response:

To a great god, and fast,

CodePudding user response:

 & lt; ! DOCTYPE html> 
& lt; HTML lang="en" & gt;
& lt; head>
& lt; Meta charset="utf-8" & gt;
& lt; Meta name="viewport" content="width=device - width, initial - scale=1, the user - scalable=0" & gt;
& lt; title> Document
& lt; The script type="text/javascript" SRC="http://res.wx.qq.com/open/js/jweixin-1.0.0.js" & gt; & lt;/script>

& lt; script>
//audio preloaded
Document. The addEventListener (" WeixinJSBridgeReady ", function () {
Document. The getElementById (' JGG). Play ()
}, false);
& lt;/script>
& lt;/head>
& lt; body>
& lt; JGG audio id="" SRC=" https://bbs.csdn.net/topics/style/jgg.mp3 "the autoplay=" the autoplay "& gt; & lt;/audio>
& lt;/body>
& lt;/html>

Haven't met, is the network?

CodePudding user response:

The quality of zhang elder brother audio compressed audio compression software

CodePudding user response:

Just transferred through a solution said once:

1. At the beginning of the audio of the SRC is empty, after the page is loaded directly play a (this is particularly important)
2. Load data and assign a value to the SRC (I use the blob, direct copy the SRC can't row)
3. Click on the manual trigger player

The test code is as follows:
 
& lt; ! DOCTYPE html>
& lt; html>
& lt; head>
& lt; Meta HTTP - equiv="content-type" content="text/HTML. Charset=utf-8 "& gt;
& lt;/head>
& lt; body>
& lt; Audio id="audio" preload="auto" & gt; & lt;/audio & gt;
& lt; BtnStart button id="" style=" width: 100 px; height: 100px; border-radius: 50%; cursor: pointer;"> Play6 & lt;/button>
& lt; Script SRC="https://bbs.csdn.net/topics/js/jquery.min.js" & gt; & lt;/script>
& lt; script>
The function audioAutoPlay (id) {
Var audio=document. GetElementById (id);
Audio. The play ();
}

The function loadData () {
//create the XMLHttpRequest object
Var XHR=new XMLHttpRequest ();
//configuration request, request address and whether synchronous
XHR. Open (' GET 'and' http://xxx.com/201911101575950144866.mp3 ', true);
//set the request result type for blob
XHR. ResponseType='blob';
//request success callback function
XHR. onl oad=function (e) {
If (this. Status==200) {//request success
//get a blob object
Var blob=this. The response;
//get a blob object address, and assign values to the container
$(" # audio "). Attr (" SRC ", URL. CreateObjectURL (blob));
}
};
XHR. The send ();
}

//this way no
The function loadData2 () {
$(" # audio "). Attr (' SRC ', 'http://xxx.com/201911101575950144866.mp3');
}

The $(document). Ready (function () {
AudioAutoPlay (' audio ');
LoadData ();
$(" # btnStart "). Click (function () {
AudioAutoPlay (' audio ');
});
})
& lt;/script>
& lt;/body>
& lt;/html>


I hope it can help you
  • Related