Skip to content

Commit 784a64e

Browse files
committed
Use setSource() to change the audio URL
1 parent 90ef500 commit 784a64e

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/app/waveform-view/waveform-view.component.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AfterViewInit, Component, ElementRef, Input, SimpleChanges, ViewChild } from '@angular/core';
2-
import Peaks, { PeaksInstance, PeaksOptions } from 'peaks.js';
2+
import Peaks, { PeaksInstance, PeaksOptions, SetSourceOptions } from 'peaks.js';
33

44
import ExampleAudio from '../example-audio';
55

@@ -74,7 +74,8 @@ export class WaveformViewComponent implements AfterViewInit {
7474
}
7575

7676
onPeaksReady(): void {
77-
console.log('Peaks ready');
77+
// Do something when the Peaks instance is ready for use
78+
console.log("Peaks.js is ready");
7879
}
7980

8081
ngOnChanges(changes: SimpleChanges): void {
@@ -88,6 +89,21 @@ export class WaveformViewComponent implements AfterViewInit {
8889
if (!audioChange.previousValue ||
8990
audioChange.currentValue.audioUrl !== audioChange.previousValue.audioUrl) {
9091
this.selectedAudio = audioChange.currentValue;
92+
93+
if (this.peaks) {
94+
const options: SetSourceOptions = {
95+
mediaUrl: audioChange.currentValue.audioUrl,
96+
dataUri: {
97+
arraybuffer: audioChange.currentValue.waveformDataUrl
98+
}
99+
};
100+
101+
this.peaks.setSource(options, (error: Error) => {
102+
if (error) {
103+
console.error(error);
104+
}
105+
});
106+
}
91107
this.initPeaks();
92108
}
93109
}

0 commit comments

Comments
 (0)