Property | Type | Description | is_loaded | boolean | Whether the audio element is loaded or not |
is_paused | boolean | Whether the audio element is paused or not |
current_time | number | The current time of the audio element in seconds |
duration | number | The duration of the audio element in seconds |
timestamp_current | string | The current time of the audio element in timestamp format (hh:mm:ss) |
timestamp_end | string | The end time of the audio element in timestamp format (hh:mm:ss) |
Subscribe to specific changes in the audio attributes. This will
return a readable store that you can use to access the attributes.
<script>
import { audio } from 'svelte-podcast';
const attributes = $audio;
audio.subscribe((attr) => {
console.log(attr);
});
</script>
<p>Current timestamp {attributes.timestamp_current}.</p>
<p>{attributes.is_paused ? 'Paused...' : 'Playing!'}.</p>
Load a new audio source. This will stop the current audio source and
replace it with the new one.
Alternatively, unload the current audio source. This will stop the
current audio source and remove it from the audio state.
import { audio } from 'svelte-podcast';
audio.src.load(
'/episode-377.mp3',
{
title: 'Supper Club × Rich Harris, Author of Svelte',
artwork:
'https://ssl-static.libsyn.com/p/assets/b/3/c/d/b3cdf28da11ad39fe5bbc093207a2619/Syntax_-_499.jpg',
guests: ['Rich Harris'],
hosts: ['Wes Bos', 'Scott Tolinski'],
},
);
audio.src.unload();
Set or toggle the play state.
import { audio } from 'svelte-podcast';
audio.play(true);
audio.play(false);
audio.play('toggle');
Set or toggle the mute state.
import { audio } from 'svelte-podcast';
audio.mute(true);
audio.mute(false);
audio.mute('toggle');
Seek to a specific time in the audio. The `from` parameter
determines whether the time is relative to the start or end of the
audio.
import { audio } from 'svelte-podcast';
audio.seek_to(200);
audio.seek_to(200, 'from-end');
Skip forward or backward in the audio by a specific number of
seconds.
import { audio } from 'svelte-podcast';
audio.skip_by(30);
audio.skip_by(30, 'backward');