Skip to content

Commit

Permalink
fix loading peaks data from JSON files
Browse files Browse the repository at this point in the history
  • Loading branch information
thijstriemstra committed Oct 11, 2019
1 parent 3c86b8b commit a3c6154
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ videojs-wavesurfer changelog
2.11.0 - unreleased
-------------------

- Fix loading peaks data from JSON files (#90)
- Add `style` and `sass` entries to `package.json`
- Specify non-minified videojs-wavesurfer in `main` entry of `package.json`


2.10.0 - 2019/09/30
-------------------

Expand Down
9 changes: 8 additions & 1 deletion src/js/videojs.wavesurfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,14 @@ class Wavesurfer extends Plugin {

request.once('success', data => {
this.log('Loaded Peak Data URL: ' + peaks);
this.surfer.load(url, data);
// check for data property containing peaks
if (data && data.data) {
this.surfer.load(url, data.data);
} else {
this.player.trigger(Event.ERROR,
'Could not load peaks data from ' + peaks);
this.log(err, 'error');
}
});
request.on('error', e => {
this.log('Unable to retrieve peak data from ' + peaks +
Expand Down
3 changes: 3 additions & 0 deletions test/test-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const TestHelpers = {
/** Peaks data for example audio clip */
EXAMPLE_AUDIO_PEAKS_FILE: '/base/test/support/demo-peaks.json',

/** File with invalid peaks data */
EXAMPLE_AUDIO_PEAKS_INVALID_FILE: '/base/test/support/demo-peaks-invalid.json',

/** Example VTT clip */
EXAMPLE_VTT_FILE: '/base/test/support/demo.vtt',

Expand Down
16 changes: 16 additions & 0 deletions test/videojs.wavesurfer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,22 @@ describe('Wavesurfer', () => {
});
});

/** @test {Wavesurfer#load} */
it('throws error if peaks data cannot be found in file', (done) => {
player.one(Event.ERROR, (e) => {
expect(e).toEqual('data:image/jpeg;base64,');
done();
});

player.one(Event.WAVE_READY, () => {
// try loading from peaks file without a data property
player.wavesurfer().load(
TestHelpers.EXAMPLE_AUDIO_FILE,
TestHelpers.EXAMPLE_AUDIO_PEAKS_INVALID_FILE
);
});
});

/** @test {Wavesurfer#setAudioOutput} */
it('throws error for non-existing device', (done) => {

Expand Down

0 comments on commit a3c6154

Please sign in to comment.