Objek Audio DOM HTML

  • Halaman sebelumnya <aside>
  • Halaman berikutnya <b>

Audio object

The Audio object is a new object in HTML5.

The Audio object represents the HTML <audio> element.

Access Audio object

You can access the <audio> element by using getElementById():

var x = document.getElementById("myAudio");

Try it yourself

Create Audio object

You can create an <audio> element by using the document.createElement() method:

var x = document.createElement("AUDIO");

Try it yourself

Audio object properties

Sifat Penerangan
audioTracks Return the AudioTrackList object representing the available audio tracks.
autoplay Set or return whether the audio should play immediately after being ready (loaded).
buffered Return the TimeRanges object representing the buffered parts of the audio.
controller Return the MediaController object representing the current media controller of the audio.
controls Set or return whether the audio controls (such as play/pause) should be displayed.
crossOrigin Set or return the CORS settings of the audio.
currentSrc Return the current URL of the audio.
currentTime Set or return the current playback position in the audio (in seconds).
defaultMuted Set or return whether the audio is muted by default.
defaultPlaybackRate Set or return the default playback speed of the audio.
duration Return the length of the audio (in seconds).
ended Return whether the playback of the audio has ended.
error Return the MediaError object representing the audio error state.
loop Set or return whether the audio should play again at the end.
mediaGroup Set or return the name of the media group the audio belongs to.
muted Set or return whether the sound is turned off.
networkState Return the current network state of the audio.
paused Set or return whether the audio is paused.
playbackRate Tetapkan atau kembalikan kelajuan mainan audio.
played Kembalikan objek TimeRanges yang mewakili bahagian audio yang dimainkan.
preload Tetapkan atau kembalikan nilai sifat preload audio.
readyState Kembalikan status kemas kini audio.
seekable Kembalikan objek TimeRanges yang mewakili bahagian audio yang boleh dicari.
seeking Kembalikan sama ada pengguna sedang mencari audio sekarang.
src Tetapkan atau kembalikan nilai sifat src audio.
textTracks Kembalikan objek TextTrackList yang mewakili laluan teks yang tersedia.
volume Tetapkan atau kembalikan volum audio.

Method objek Audio

Method Penerangan
addTextTrack() Tambah laluan teks baru kepada audio.
canPlayType() Periksa sama ada pemeriksa boleh memainkan jenis audio yang ditentukan.
fastSeek() Tentukan masa mainan di pemutar audio.
getStartDate() Kembalikan objek Date baru yang mewakili offset timeline saat ini.
load() Ulangi elemen audio.
play() Mulai mainan audio.
pause() Henti mainan audio saat ini.

Sifat dan peristiwa standar

Objek Audio mendukung standarSifatdanPeristiwa

Halaman yang berhubungan

Panduan HTML:Audio HTML5

Panduan referensi HTML:Tanda <audio> HTML

  • Halaman sebelumnya <aside>
  • Halaman berikutnya <b>