Skip to content

Commit

Permalink
fix lamejs plugin (#267)
Browse files Browse the repository at this point in the history
* update dev dependencies
* fix lamejs plugin
* update changelog
  • Loading branch information
thijstriemstra committed Aug 1, 2018
1 parent f728c60 commit cae1e62
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 39 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
videojs-record changelog
========================

2.4.1 - unreleased
------------------

- Fix lamejs plugin (#265)


2.4.0 - 2018/07/31
------------------

Expand Down
35 changes: 22 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
"opus-recorder": ">=4.1.4",
"recorderjs": "git+https://github.com/mattdiamond/Recorderjs.git",
"rimraf": "^2.6.2",
"sass-loader": "^7.0.3",
"sass-loader": "^7.1.0",
"style-loader": "^0.21.0",
"uglifyjs-webpack-plugin": "^1.2.7",
"url-loader": "^1.0.1",
Expand Down
41 changes: 18 additions & 23 deletions src/js/plugins/lamejs-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,23 @@ class LamejsEngine extends RecordEngine {
bitRate: this.bitRate
};

let AudioContext = window.AudioContext || window.webkitAudioContext;
this.audioContext = new AudioContext();
this.audioSourceNode = this.audioContext.createMediaStreamSource(
this.inputStream);
this.processor = this.audioContext.createScriptProcessor(
16384, 1, 1);

this.engine = new Worker(this.audioWorkerURL);
this.engine.onmessage = this.onWorkerMessage.bind(this);
this.engine.postMessage({cmd: 'init', config: this.config});
}

/**
* Start recording.
*/
start() {
this.engine.postMessage({cmd: 'init', config: this.config});
let AudioContext = window.AudioContext || window.webkitAudioContext;
this.audioContext = new AudioContext();

this.audioSourceNode = this.audioContext.createMediaStreamSource(
this.inputStream);
// a bufferSize of 0 instructs the browser to choose the best bufferSize
this.processor = this.audioContext.createScriptProcessor(
0, 1, 1);
this.processor.onaudioprocess = this.onAudioProcess.bind(this);
this.audioSourceNode.connect(this.processor);
this.processor.connect(this.audioContext.destination);
Expand All @@ -52,26 +53,20 @@ class LamejsEngine extends RecordEngine {
* Stop recording.
*/
stop() {
this.audioSourceNode.disconnect();
this.processor.disconnect();
this.processor.onaudioprocess = null;
if (this.processor && this.audioSourceNode) {
this.audioSourceNode.disconnect();
this.processor.disconnect();
this.processor.onaudioprocess = null;
}
if (this.audioContext) {
// ignore errors about already being closed
this.audioContext.close().then(() => {}).catch((reason) => {});
}

// free up memory
this.engine.postMessage({cmd: 'finish'});
}

/**
* Remove any temporary data and references to streams.
*/
dispose() {
super.dispose();

this.inputStream.getAudioTracks().forEach(track => track.stop());

// ignore errors about already being closed
this.audioContext.close().then(() => {}).catch((reason) => {});
}

/**
* Received a message from the worker.
*/
Expand Down
3 changes: 1 addition & 2 deletions src/js/videojs.record.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,7 @@ class Record extends Plugin {
try {
// connect stream to recording engine
this.engine = new EngineClass(this.player, this.player.options_);
}
catch (err) {
} catch (err) {
console.error(err);
throw new Error('Could not load ' + this.audioEngine +
' plugin');
Expand Down

0 comments on commit cae1e62

Please sign in to comment.