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 autoplay 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 

remaster

Sets and gets the smart remaster functionality status. If true the smart remaster affects the output sound. The default value is true.

let remasteringStatus = audio.remaster; // Gets remaster status as boolean (true/false)
audio.remaster = false; // Sets smart remaster functionality off 

volume

Sets or gets the output sound volume in decibels(dB) as integer. Minimum acceptable value is -100dB and maximum acceptable value is 0dB. The default value is 0;

let currentVolume = audio.volume; // Gets current output volume in decibels
audio.volume = -10; // Sets the output volume to -10dB

state

Returns the last state of the dAudio object.

let lastState = audio.state; // Gets the latest status

Note: For more details and state management please read the State Management page.

eq

eq is an object containing 12 frequency bands and their gain values in decibles. The minimum value for each band is -12dB and the maximum value is 3dB. The default value for each band is 0dB. The frequency bands are 31Hz, 63Hz, 125Hz, 250Hz, 500Hz, 1kHz, 2kHz, 4kHz, 8kHz, 12kHz, 16kHz and 20kHz. You can set or get the gain values like below:

audio.eq['31Hz']  = 0;
audio.eq['63Hz']  = 0;
audio.eq['125Hz'] = 0;
audio.eq['250Hz'] = 0;
audio.eq['500Hz'] = 0;
audio.eq['1kHz']  = 0;
audio.eq['2kHz']  = 0;
audio.eq['4kHz']  = 0;
audio.eq['8kHz']  = 0;
audio.eq['12kHz'] = 0;
audio.eq['16kHz'] = 0;
audio.eq['20kHz'] = 0;
Clone this wiki locally