Skip to content

Properties

Farshad Javan edited this page Dec 17, 2019 · 12 revisions

src

dAudio accepts two kind of sources, Blob or URL. The src property sets the new audio source or gets the current source file name/url. If your source is a audio file url, it will return the current source url and if your source is an audio file blob, it will return the file name. The initial value is empty string.

audio.src = 'http://www.example.com/audio.mp3'; // Sets the source to URL
let currentSource = audio.src; // Gets the current source's URL

You can set the source with an HTML file input as a blob:

<input type="file" id="fileInput" accept="audio/*">
<script>
  document.querySelector('#fileInput').onchange = e => {
    if (e.target.files.length) audio.src = e.target.files[0]; // Sets the source to user selected file
    let currentFileName = audio.src; // Gets the source file name
  };
</script>

Note: Audio streams are not supported by dAudio. If you need stream playback please check the eAudio project which supports online stream playback.

type

Returns current source file mime-type when the file loads. The initial value is null.

let mimeType = audio.type; // Gets the file mime-type

size

Returns current source file size in bytes when the file loads. The initial value is 0.

let fileSize = audio.size; // Gets the file size

duration

Returns current source total duration in seconds when the file loads. The initial value is 0.

let audioDuration = audio.duration; // Gets the total audio duration

currentTime

Gets the current playback time or seeks to your target position in seconds. Seek functionality also works when the player is paused or stopped. The initial value is 0.

let currentTime = audio.currentTime; // Gets the current playback time in seconds
audio.currentTime = 10; // Seeks to target time (10 Seconds)

isPlaying

Returns true if audio is playing and false when playback is paused or stopped. The initial value is false.

let isAudioPlaying = audio.isPlaying; // Gets playing status as boolean (true/false)

repeat

Sets and gets the repeat functionality status. If true the player repeats the current audio source when it ends and if false player stops at the end of audio playback. The default value is false.

let currentRepeatStatus = audio.repeat; // Gets repeat status as boolean (true/false)
audio.repeat = true; // Sets repeat functionality on

autoplay

Sets and gets the repeat functionality status. If true the player starts playing immediately when ready. The default value is false.

let autoplayStatus = audio.autoplay; // Gets autoplay status as boolean (true/false)
audio.autoplay = true; // Sets autoplay functionality on 
Clone this wiki locally