adds autoplay option

This commit is contained in:
Ollie Taylor
2023-02-24 14:01:43 +00:00
parent 20fc307099
commit d7d81ce732
4 changed files with 18 additions and 5 deletions
+2 -1
View File
@@ -1,5 +1,6 @@
<script lang="ts">
import {
audio_autoplay,
audio_current_time,
audio_element,
audio_metadata,
@@ -22,7 +23,7 @@
<audio
bind:this={element}
{src}
autoplay={false}
autoplay={$audio_autoplay}
bind:currentTime
bind:muted
preload="metadata"
+3 -1
View File
@@ -1,9 +1,11 @@
import type { PlayerElement, PlayerMetadata } from '$lib/types/types';
import { writable } from 'svelte/store';
export const audio_element = writable<PlayerElement>();
export const audio_current_time = writable<number>(0);
export const audio_src = writable<string | null>(null);
export const audio_element = writable<PlayerElement>();
export const audio_autoplay = writable<boolean>(false);
export const audio_metadata = writable<PlayerMetadata>({
duration: 0,
muted: false,
+7 -1
View File
@@ -1,4 +1,5 @@
import {
audio_autoplay,
audio_current_time,
audio_element,
audio_metadata,
@@ -65,8 +66,13 @@ function unmute(type: HandleType = 'set') {
})();
}
function load(src: string) {
type LoadOptions = {
autoplay: boolean;
};
function load(src: string, opts: LoadOptions) {
info('load: ', src);
audio_autoplay.set(opts.autoplay);
audio_src.set(src);
return audio_element.subscribe((el) => {
if (!el) return warn('no audio element');