Baseline Widely available
å®éªæ§: è¿æ¯ä¸é¡¹å®éªæ§ææ¯
å¨å°å
¶ç¨äºç产ä¹åï¼è¯·ä»ç»æ£æ¥æµè§å¨å
¼å®¹æ§è¡¨æ ¼ã
Response
ä¸çæ¹æ³ arrayBuffer()
æ¥åä¸ä¸ª Response
æµï¼å¹¶çå¾
å
¶è¯»å宿ãå®è¿åä¸ä¸ª promise å®ä¾ï¼å¹¶ resolve ä¸ä¸ª ArrayBuffer
对象ã
response.arrayBuffer().then(function(buffer) {
// do something with buffer
)};
åæ°
æ ã
è¿åå¼A promise that resolves with an ArrayBuffer
.
In our fetch array buffer example (run fetch array buffer live), we have a Play button. When pressed, the getData()
function is run.
In getData()
we create a new request using the Request.Request
constructor, then use it to fetch an OGG music track. We also use AudioContext.createBufferSource
to create an audio buffer source. When the fetch is successful, we read an ArrayBuffer
out of the response using arrayBuffer()
, decode the audio data using AudioContext.decodeAudioData
, set the decoded data as the audio buffer source's buffer (source.buffer
), then connect the source up to the AudioContext.destination
.
Once getData()
has finished running, we start the audio source playing with start(0)
, then disable the play button so it can't be clicked again when it is already playing (this would cause an error.)
function getData() {
source = audioCtx.createBufferSource();
var myRequest = new Request("viper.ogg");
fetch(myRequest).then(function (response) {
response.arrayBuffer().then(function (buffer) {
audioCtx.decodeAudioData(buffer, function (decodedData) {
source.buffer = decodedData;
source.connect(audioCtx.destination);
});
});
});
}
// wire up buttons to stop and play audio
play.onclick = function () {
getData();
source.start(0);
play.setAttribute("disabled", "disabled");
};
è§è æµè§å¨å
¼å®¹æ§ åè
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4