Play some audio.
npm install audic
import {playAudioFile} from 'audic';
await playAudioFile('audio.mp3');
import Audic from 'audic';
const audic = new Audic('audio.mp3');
await audic.play();
audic.addEventListener('ended', () => {
audic.destroy();
});
Convenience function that plays an audio file. Returns a promise that resolves when playback has completed.
Play the audio if it is not already playing.
Pause the audio if it not already paused.
Destroy the player instance.
Type: string
The path to the file that is being played.
Type: number
The volume of the audio as a decimal between 0
and 1
.
Type: number
The current playing time of the audio.
Type: number
The duration of the audio.
Type: boolean
\
Default: false
Whether audio playback is looped.
Type: boolean
Whether the audio is currently playing.
These events from the Web Audio API are also emitted by Audic:
timeupdate
- When currentTime
changesended
- When the current song has finished playingplaying
- When playing
is set to true
pause
- When playback is pausedvolumechange
- When the volume is changedcanplay
- When the audio is ready to start playingcanplaythrough
- When the audio is ready to play through to the endseeking
- When an audio seek has been initiatedseeked
- When an audio seek has completedplay
- When audio playback is started or restarted