From 35e2f9ebd56ff6b59fd66915ea4ca1f982d0e572 Mon Sep 17 00:00:00 2001 From: Pawel Kaczmarczyk Date: Thu, 8 Feb 2018 10:57:15 +0100 Subject: [PATCH] [Media] Fix deprecated API [Verification] tct-media-cordova-tizen-tests passrate 100% tested in Chromium console AudioContext.createJavaScriptNode method has been marked as obsolete and is no longer supported by Chromium. Navigator.getUserMedia has been marked as deprecated and will be replaced by navigator.mediaDevices.getUserMedia Change-Id: I7938d1a1016c67f3862d49dabed02b2d510154a2 Signed-off-by: Pawel Kaczmarczyk --- .../cordova-plugin-media/tizen/Media.js | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/lib/plugins/cordova-plugin-media/tizen/Media.js b/src/lib/plugins/cordova-plugin-media/tizen/Media.js index 0f29b19..717be92 100755 --- a/src/lib/plugins/cordova-plugin-media/tizen/Media.js +++ b/src/lib/plugins/cordova-plugin-media/tizen/Media.js @@ -36,25 +36,37 @@ cordova.define(plugin_name, function(require, exports, module) { var sampleRate = null; var filename = _filename; var audioBlob = null; + var leftchannel = []; + var rightchannel = []; this.rec = function(){ - - if (!navigator.getUserMedia) + if (navigator.mediaDevices.getUserMedia){ + navigator.mediaDevices.getUserMedia({audio:true}) + .then(onGetUserMedia) + .catch(function(e) { + console.log('Error capturing audio: ' + e.name + ': ' + e.message); + }); + } else { navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia; - - if (navigator.getUserMedia){ - navigator.getUserMedia({audio:true}, onGetUserMedia, function(e) { - console.log('Error capturing audio.'); - }); - } else { - console.log('getUserMedia not supported in this browser.'); + if(navigator.getUserMedia) { + navigator.getUserMedia({audio: true}, onGetUserMedia, function(e) { + console.log('Error capturing audio: ' + e.name + ': ' + e.message); + }) + } else { + console.log('getUserMedia not supported in this browser.'); + } } } this.stop = function (){ recording = false; - audioBlob.stop(); + var tracks = audioBlob.getAudioTracks(); + + tracks.forEach(function(track) { + track.stop(); + }); + recorder.disconnect(); // flat the left and right channels down @@ -100,8 +112,6 @@ cordova.define(plugin_name, function(require, exports, module) { function onGetUserMedia(stream){ recording = true; - var leftchannel = []; - var rightchannel = []; recordingLength = 0; audioBlob = stream; @@ -123,7 +133,7 @@ cordova.define(plugin_name, function(require, exports, module) { Lower values for buffer size will result in a lower (better) latency. Higher values will be necessary to avoid audio breakup and glitches */ var bufferSize = 2048; - recorder = context.createJavaScriptNode(bufferSize, 2, 2); + recorder = context.createScriptProcessor(bufferSize, 2, 2); recorder.onaudioprocess = function(sample){ if (!recording) { -- 2.34.1