-
Notifications
You must be signed in to change notification settings - Fork 12
/
simple.ts
27 lines (18 loc) · 874 Bytes
/
simple.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { Factory } from '../../src/index';
import { toggleClass } from './utils';
document.addEventListener('DOMContentLoaded', async () => {
// Create a new player instance
const player = Factory.createPlayer({ container: '#waveform' });
const button = document.getElementById('playback-button') as HTMLButtonElement | null;
if (!button) return;
// Load a track and activate the playback button when finished
await player.load('../audio/extase_1.mp3', { type: 'json', url: '../audio/extase_1.json' });
button.disabled = false;
button.onclick = () => {
if (!button.firstElementChild) return;
const icon = button.firstElementChild.firstElementChild as HTMLLIElement | null;
if (!icon) return;
toggleClass(icon, 'fa-pause', 'fa-play');
player.paused ? player.play() : player.pause();
};
});