|
10 | 10 | import VolumeLevels from "./VolumeLevels.svelte";
|
11 | 11 | import VolumeControl from "./VolumeControl.svelte";
|
12 | 12 |
|
13 |
| - export let waveform: WaveSurfer; |
| 13 | + export let waveform: WaveSurfer | undefined; |
14 | 14 | export let audio_duration: number;
|
15 | 15 | export let i18n: I18nFormatter;
|
16 | 16 | export let playing: boolean;
|
|
30 | 30 | let playbackSpeeds = [0.5, 1, 1.5, 2];
|
31 | 31 | let playbackSpeed = playbackSpeeds[1];
|
32 | 32 |
|
33 |
| - let trimRegion: RegionsPlugin; |
| 33 | + let trimRegion: RegionsPlugin | null = null; |
34 | 34 | let activeRegion: Region | null = null;
|
35 | 35 |
|
36 | 36 | let leftRegionHandle: HTMLDivElement | null;
|
|
39 | 39 |
|
40 | 40 | let currentVolume = 1;
|
41 | 41 |
|
42 |
| - $: trimRegion = waveform.registerPlugin(RegionsPlugin.create()); |
| 42 | + $: trimRegion = |
| 43 | + container && waveform |
| 44 | + ? waveform.registerPlugin(RegionsPlugin.create()) |
| 45 | + : null; |
43 | 46 |
|
44 | 47 | $: trimRegion?.on("region-out", (region) => {
|
45 | 48 | region.play();
|
|
56 | 59 | });
|
57 | 60 |
|
58 | 61 | const addTrimRegion = (): void => {
|
59 |
| - activeRegion = trimRegion.addRegion({ |
| 62 | + if (!trimRegion) return; |
| 63 | + activeRegion = trimRegion?.addRegion({ |
60 | 64 | start: audio_duration / 4,
|
61 | 65 | end: audio_duration / 2,
|
62 | 66 | ...trim_region_settings
|
|
190 | 194 | (playbackSpeeds.indexOf(playbackSpeed) + 1) % playbackSpeeds.length
|
191 | 195 | ];
|
192 | 196 |
|
193 |
| - waveform.setPlaybackRate(playbackSpeed); |
| 197 | + waveform?.setPlaybackRate(playbackSpeed); |
194 | 198 | }}
|
195 | 199 | >
|
196 | 200 | <span>{playbackSpeed}x</span>
|
|
205 | 209 | waveform_options.skip_length
|
206 | 210 | )} seconds`}
|
207 | 211 | on:click={() =>
|
208 |
| - waveform.skip( |
| 212 | + waveform?.skip( |
209 | 213 | get_skip_rewind_amount(audio_duration, waveform_options.skip_length) *
|
210 | 214 | -1
|
211 | 215 | )}
|
|
214 | 218 | </button>
|
215 | 219 | <button
|
216 | 220 | class="play-pause-button icon"
|
217 |
| - on:click={() => waveform.playPause()} |
| 221 | + on:click={() => waveform?.playPause()} |
218 | 222 | aria-label={playing ? i18n("audio.pause") : i18n("audio.play")}
|
219 | 223 | >
|
220 | 224 | {#if playing}
|
|
230 | 234 | waveform_options.skip_length
|
231 | 235 | )} seconds"
|
232 | 236 | on:click={() =>
|
233 |
| - waveform.skip( |
| 237 | + waveform?.skip( |
234 | 238 | get_skip_rewind_amount(audio_duration, waveform_options.skip_length)
|
235 | 239 | )}
|
236 | 240 | >
|
|
0 commit comments