HTMLAudioElement
åºçº¿
广æ³å¯ç¨
èª 2015å¹´7æ èµ·ï¼æ¤ç¹æ§å·²å¨ä¸»æµæµè§å¨ä¸å¾å°æ¯æï¼å¯å¨å¤§å¤æ°è®¾å¤åæµè§å¨çæ¬ä¸æ£å¸¸ä½¿ç¨ã
HTMLAudioElement æ¥å£æä¾å¯¹ <audio> å
ç´ ç屿§è®¿é®åä¸ç³»åææ§å®çæ¹æ³ï¼å®åºäºå¹¶ä» HTMLMediaElement æ¥å£ç»§æ¿å±æ§åæ¹æ³ã
æé 彿°
Audio()-
å建并è¿åä¸ä¸ªæ°ç
HTMLAudioElement对象ï¼å¦ææä¾é³é¢æä»¶ URLï¼åå¼å§å è½½é³é¢æä»¶ã
屿§
没æå
·ä½ç屿§ï¼ä»ç¶ç±» HTMLMediaElement å HTMLElement ç»§æ¿å±æ§ã
æ¹æ³
ä»ç¶ç±» HTMLMediaElement å HTMLElement ç»§æ¿æ¹æ³ï¼èªèº«ä¸æä¾æ¹æ³ã
åºå¼çä¸ä» éç¨äº Mozilla çæ¹æ³
以䏿¹æ³æ¯æªæ ååçï¼è¯·å¿ä½¿ç¨.
mozCurrentSampleOffset()-
Returns the number of samples form the beginning of the stream that have been written so far into the audio stream created by calling
mozWriteAudio(). mozSetup()-
Sets up the audio stream to allow writing, given the number of audio channels (1 or 2) and the sample rate in kHz.
mozWriteAudio()-
Writes a batch of audio frames to the stream at the current offset, returning the number of bytes actually written to the stream.
示ä¾
>åºæ¬ç¨æ³
ä½ å¯ä»¥å®å
¨ä½¿ç¨ JavaScript ç Audio() æé 彿°æ¥å建ä¸ä¸ª HTMLAudioElement ï¼
var audioElement = new Audio("car_horn.wav");
ç¶åä½ å¯ä»¥å¨è¿ä¸ªå
ç´ ä¸è°ç¨ play() æ¹æ³
audioElement.play();
夿³¨ï¼ä¸ä¸ªå¸¸è§çéæ±æ¯å¨é¡µé¢å è½½å马ä¸å»ææ¾é³é¢ï¼ç°ä»£æµè§å¨çé»è®¤èªå¨ææ¾çç¥ä¼é»æ¢è¿ä¸è¡ä¸ºï¼åè§ firefox å chrome å¯»æ¾æä½³å®è·µåè§£å³æ¹æ¡ã
ä¸äºç»å¸¸è¢«ä½¿ç¨ç屿§ï¼å
æ¬ srcãcurrentTimeãdurationãpausedãmuted å volumeã以ä¸è¿æ®µä»£ç èµå¼é³é¢æä»¶çææ¾æ¶é¿ç»ä¸ä¸ªåéï¼
var audioElement = new Audio("car_horn.wav");
audioElement.addEventListener("loadeddata", () => {
let duration = audioElement.duration;
// duration åéç°å¨åæ¾é³é¢çææ¾æ¶é¿ï¼åä½ç§ï¼
});
äºä»¶
ä»ç¶ç±» HTMLMediaElement åç¥å
HTMLElement ç»§æ¿æ¹æ³ãä½¿ç¨ addEventListener() çå¬äºä»¶æè
èµå¼ä¸ä¸ªäºä»¶çå¬å¨ç»è¿ä¸ªæ¥å£ç oneventname 屿§ã
è§è
| è§è |
|---|
| HTML > # htmlaudioelement > |
æµè§å¨å ¼å®¹æ§
åè§
- Web åªä½ææ¯
- å¨ HTML ä¸ä½¿ç¨é³è§é¢
- å®ç°æ¤æ¥å£ç HTML å
ç´ ï¼
<audio>ã