From: Pawel Andruszkiewicz Date: Thu, 7 Apr 2016 12:27:51 +0000 (+0200) Subject: [Media] Code structure changed to match cordova architecture. X-Git-Tag: submit/tizen/20160411.115901^2~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=32823eec2aba6888da89350a7db5fe9136939279;p=platform%2Fcore%2Fapi%2Fcordova-plugins.git [Media] Code structure changed to match cordova architecture. Change-Id: Id08058932daaa612b887badf48aa498e942bec4b Signed-off-by: Pawel Andruszkiewicz --- diff --git a/src/cordova-api.gyp b/src/cordova-api.gyp index 8b1b5f2..af8643b 100644 --- a/src/cordova-api.gyp +++ b/src/cordova-api.gyp @@ -12,7 +12,6 @@ 'file/cordova_file.gyp:*', 'globalization/cordova_globalization.gyp:*', 'networkinformation/cordova_networkinformation.gyp:*', - 'media/cordova_media.gyp:*', ], }, ], # end targets diff --git a/src/lib/cordova_plugins.js b/src/lib/cordova_plugins.js index a19039e..9d4303a 100644 --- a/src/lib/cordova_plugins.js +++ b/src/lib/cordova_plugins.js @@ -266,6 +266,11 @@ module.exports = [ "clobbers": [ "window.Media" ] + }, + { + "file": "plugins/cordova-plugin-media/tizen/Media.js", + "id": "cordova-plugin-media.tizen.Media", + "runs": true } ]; module.exports.metadata = diff --git a/src/lib/plugins/cordova-plugin-media/tizen/Media.js b/src/lib/plugins/cordova-plugin-media/tizen/Media.js new file mode 100755 index 0000000..0f29b19 --- /dev/null +++ b/src/lib/plugins/cordova-plugin-media/tizen/Media.js @@ -0,0 +1,422 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TODO: remove when added to public cordova repository -> begin +var plugin_name = 'cordova-plugin-media.tizen.Media'; + +cordova.define(plugin_name, function(require, exports, module) { +// TODO: remove -> end + + var audioObjects = {}; + var recorder = null; + + // creates the audio context + var audioContext = window.AudioContext || window.webkitAudioContext; + var context = new audioContext(); + + function Recorder(_filename) { + var recorder = null; + var recording = false; + var recordingLength = 0; + var volume = null; + var audioInput = null; + var sampleRate = null; + var filename = _filename; + var audioBlob = null; + + this.rec = function(){ + + if (!navigator.getUserMedia) + 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.'); + } + } + + this.stop = function (){ + recording = false; + audioBlob.stop(); + recorder.disconnect(); + + // flat the left and right channels down + var leftBuffer = mergeBuffers(leftchannel, recordingLength); + var rightBuffer = mergeBuffers(rightchannel, recordingLength); + // interleave both channels together + var interleaved = interleave(leftBuffer, rightBuffer); + + // create the buffer and view to create the .WAV file + var buffer = new ArrayBuffer(44 + interleaved.length * 2); + var view = new DataView(buffer); + + // write the WAV container + // RIFF chunk descriptor + writeUTFBytes(view, 0, 'RIFF'); + view.setUint32(4, 44 + interleaved.length * 2, true); + writeUTFBytes(view, 8, 'WAVE'); + // FMT sub-chunk + writeUTFBytes(view, 12, 'fmt '); + view.setUint32(16, 16, true); + view.setUint16(20, 1, true); + // stereo (2 channels) + view.setUint16(22, 2, true); + view.setUint32(24, sampleRate, true); + view.setUint32(28, sampleRate * 4, true); + view.setUint16(32, 4, true); + view.setUint16(34, 16, true); + // data sub-chunk + writeUTFBytes(view, 36, 'data'); + view.setUint32(40, interleaved.length * 2, true); + + // write the PCM samples + var lng = interleaved.length; + var index = 44; + var volume = 1; + for (var i = 0; i < lng; i++){ + view.setInt16(index, interleaved[i] * (0x7FFF * volume), true); + index += 2; + } + + handleReadBlob(buffer); + } + + function onGetUserMedia(stream){ + recording = true; + var leftchannel = []; + var rightchannel = []; + recordingLength = 0; + + audioBlob = stream; + + // retrieve the current sample rate to be used for WAV packaging + sampleRate = context.sampleRate; + + // creates a gain node + volume = context.createGain(); + + // creates an audio node from the microphone incoming stream + audioInput = context.createMediaStreamSource(stream); + + // connect the stream to the gain node + audioInput.connect(volume); + + /* From the spec: This value controls how frequently the audioprocess event is + dispatched and how many sample-frames need to be processed each call. + 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.onaudioprocess = function(sample){ + if (!recording) { + return; + } + var left = sample.inputBuffer.getChannelData(0); + var right = sample.inputBuffer.getChannelData(1); + // clone the samples + leftchannel.push(new Float32Array(left)); + rightchannel.push(new Float32Array(right)); + recordingLength += bufferSize; + } + + // connect the recorder + volume.connect (recorder); + recorder.connect (context.destination); + } + + function handleReadBlob(buffer) { + var array = new Uint8Array(buffer); + var arr = []; + for (var i=0; i ' + MediaError.MEDIA_ERR_ABORTED); + + var err = new MediaError(MediaError.MEDIA_ERR_ABORTED, 'Stalled'); + + Media.onStatus(id, Media.MEDIA_ERROR, err); + }, 2000); + }; + + audioObjects[id].onEndedCB = function () { + console.log('media::onEndedCB() - MEDIA_STATE -> MEDIA_STOPPED'); + + Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_STOPPED); + }; + + audioObjects[id].onErrorCB = function (event) { + var err = event.srcElement.error.code === MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED ? + { code: MediaError.MEDIA_ERR_ABORTED } : + event.srcElement.error; + Object.freeze(err); + + console.log('media::onErrorCB() - MEDIA_ERROR -> ' + err); + + Media.onStatus(id, Media.MEDIA_ERROR, err); + if (errorCallback) { + errorCallback(err); + } + }; + + audioObjects[id].onPlayCB = function () { + console.log('media::onPlayCB() - MEDIA_STATE -> MEDIA_STARTING ' + audioObjects[id].src); + + Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_STARTING); + }; + + audioObjects[id].onPlayingCB = function () { + console.log('media::onPlayingCB() - MEDIA_STATE -> MEDIA_RUNNING ' + audioObjects[id].src); + + Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_RUNNING); + }; + + audioObjects[id].onDurationChangeCB = function () { + console.log('media::onDurationChangeCB() - MEDIA_DURATION -> ' + audioObjects[id].duration); + + Media.onStatus(id, Media.MEDIA_DURATION, audioObjects[id].duration); + }; + + audioObjects[id].onTimeUpdateCB = function () { + console.log('media::onTimeUpdateCB() - MEDIA_POSITION -> ' + audioObjects[id].currentTime); + + Media.onStatus(id, Media.MEDIA_POSITION, audioObjects[id].currentTime); + }; + + audioObjects[id].onSeekedCB = function () { + console.log('media::onSeekedCB() - MEDIA_POSITION -> ' + audioObjects[id].currentTime); + + Media.onStatus(id, Media.MEDIA_POSITION, audioObjects[id].currentTime); + }; + + audioObjects[id].onCanPlayCB = function () { + console.log('media::onCanPlayCB() ' + audioObjects[id].src); + + window.clearTimeout(audioObjects[id].timer); + + if (audioObjects[id].isReady) { + audioObjects[id].play(); + } + }; + + audioObjects[id].addEventListener('error', audioObjects[id].onErrorCB); + audioObjects[id].addEventListener('stalled', audioObjects[id].onStalledCB); + audioObjects[id].addEventListener('canplay', audioObjects[id].onCanPlayCB); + audioObjects[id].addEventListener('ended', audioObjects[id].onEndedCB); + audioObjects[id].addEventListener('timeupdate', audioObjects[id].onTimeUpdateCB); + audioObjects[id].addEventListener('durationchange', audioObjects[id].onDurationChangeCB); + audioObjects[id].addEventListener('playing', audioObjects[id].onPlayingCB); + audioObjects[id].addEventListener('play', audioObjects[id].onPlayCB); + audioObjects[id].addEventListener('seeked', audioObjects[id].onSeekedCB); + }, + startPlayingAudio: function(successCallback, errorCallback, args) { + var id = args[0], src = args[1]; + + console.log('media::startPlayingAudio() - id =' + id + ', src =' + src); + + audioObjects[id].isReady = true; + + if (!audioObjects[id].src) { + //assigning src sets playbackRate to default value equal to 1 + //so if playbackRate was set before first run of play() function + //it should be saved and restored. + var rate = audioObjects[id].playbackRate; + + audioObjects[id].src = src; + audioObjects[id].playbackRate = rate; + return; + } + + audioObjects[id].play(); + }, + stopPlayingAudio: function(successCallback, errorCallback, args) { + var id = args[0]; + + clearTimeout(audioObjects[id].timer); + + audioObjects[id].pause(); + audioObjects[id].isReady = false; + + if (audioObjects[id].currentTime !== 0) + audioObjects[id].currentTime = 0; + + console.log('media::stopPlayingAudio() - MEDIA_STATE -> MEDIA_STOPPED'); + + audioObjects[id].removeEventListener('canplay', audioObjects[id].onCanPlayCB); + audioObjects[id].removeEventListener('ended', audioObjects[id].onEndedCB); + audioObjects[id].removeEventListener('timeupdate', audioObjects[id].onTimeUpdateCB); + audioObjects[id].removeEventListener('durationchange', audioObjects[id].onDurationChangeCB); + audioObjects[id].removeEventListener('playing', audioObjects[id].onPlayingCB); + audioObjects[id].removeEventListener('play', audioObjects[id].onPlayCB); + audioObjects[id].removeEventListener('error', audioObjects[id].onErrorCB); + audioObjects[id].removeEventListener('error', audioObjects[id].onStalledCB); + audioObjects[id].removeEventListener('seeked', audioObjects[id].onSeekedCB); + + Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_STOPPED); + }, + seekToAudio: function(successCallback, errorCallback, args) { + console.log('media::seekToAudio()'); + var id = args[0], seconds = args[1] / 1000; + + audioObjects[id].currentTime = seconds; + }, + pausePlayingAudio: function(successCallback, errorCallback, args) { + var id = args[0]; + + console.log('media::pausePlayingAudio() - MEDIA_STATE -> MEDIA_PAUSED'); + + audioObjects[id].pause(); + audioObjects[id].isReady = false; + + Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_PAUSED); + }, + getCurrentPositionAudio: function(successCallback, errorCallback, args) { + var id = args[0]; + console.log('media::getCurrentPositionAudio()'); + if (audioObjects[id].src === 'undefined') { + audioObjects[id].src = args[1]; + } + successCallback(audioObjects[id].currentTime); + }, + startRecordingAudio: function(successCallback, errorCallback, args) { + var id = args[0]; + console.log('media::startRecordingAudio()'); + if (audioObjects[id].src === 'undefined') { + audioObjects[id].src = args[1]; + } + recorder.rec(); + }, + stopRecordingAudio: function(successCallback, errorCallback, args) { + var id = args[0]; + console.log('media::stopRecordingAudio()'); + if (audioObjects[id].src === 'undefined') { + audioObjects[id].src = args[1]; + } + recorder.stop(); + }, + release: function(successCallback, errorCallback, args) { + exports.stopPlayingAudio(successCallback, errorCallback, args); + var id = args[0]; + delete audioObjects[id]; + console.log('media::release()'); + }, + setVolume: function(successCallback, errorCallback, args) { + var id = args[0], volume = args[1]; + + console.log('media::setVolume()'); + + audioObjects[id].volume = volume; + }, + //cordova common layer supports setRate function for ios platform only + //it is for future use + setRate: function(successCallback, errorCallback, args) { + var id = args[0], rate = args[1]; + + console.log('media::setRate()'); + + audioObjects[id].playbackRate = rate; + } +}; +require('cordova/exec/proxy').add('Media', exports); + +console.log('Loaded cordova.media API'); + +// TODO: remove when added to public cordova repository -> begin +}); +// TODO: remove -> end diff --git a/src/media/cordova_media.gyp b/src/media/cordova_media.gyp deleted file mode 100644 index 4a43c14..0000000 --- a/src/media/cordova_media.gyp +++ /dev/null @@ -1,25 +0,0 @@ -{ - 'includes':[ - '/usr/include/webapi-plugins/src/common/common.gypi', - ], - 'targets': [ - { - 'target_name': 'tizen_cordova_media', - 'type': 'loadable_module', - 'sources': [ - 'cordova_media_api.js', - 'cordova_media_extension.cc', - 'cordova_media_extension.h', - ], - 'include_dirs': [ - '../', - '<(SHARED_INTERMEDIATE_DIR)', - ], - 'variables': { - 'packages': [ - 'webapi-plugins', - ], - }, - }, - ], -} diff --git a/src/media/cordova_media_api.js b/src/media/cordova_media_api.js deleted file mode 100755 index d7aa46b..0000000 --- a/src/media/cordova_media_api.js +++ /dev/null @@ -1,426 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO: remove when added to public cordova repository -> begin -var plugin_name = 'cordova-plugin-media.tizen.Media'; - -cordova.define(plugin_name, function(require, exports, module) { -// TODO: remove -> end - - var audioObjects = {}; - var recorder = null; - - // creates the audio context - var audioContext = window.AudioContext || window.webkitAudioContext; - var context = new audioContext(); - - function Recorder(_filename) { - var recorder = null; - var recording = false; - var recordingLength = 0; - var volume = null; - var audioInput = null; - var sampleRate = null; - var filename = _filename; - var audioBlob = null; - - this.rec = function(){ - - if (!navigator.getUserMedia) - 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.'); - } - } - - this.stop = function (){ - recording = false; - audioBlob.stop(); - recorder.disconnect(); - - // flat the left and right channels down - var leftBuffer = mergeBuffers(leftchannel, recordingLength); - var rightBuffer = mergeBuffers(rightchannel, recordingLength); - // interleave both channels together - var interleaved = interleave(leftBuffer, rightBuffer); - - // create the buffer and view to create the .WAV file - var buffer = new ArrayBuffer(44 + interleaved.length * 2); - var view = new DataView(buffer); - - // write the WAV container - // RIFF chunk descriptor - writeUTFBytes(view, 0, 'RIFF'); - view.setUint32(4, 44 + interleaved.length * 2, true); - writeUTFBytes(view, 8, 'WAVE'); - // FMT sub-chunk - writeUTFBytes(view, 12, 'fmt '); - view.setUint32(16, 16, true); - view.setUint16(20, 1, true); - // stereo (2 channels) - view.setUint16(22, 2, true); - view.setUint32(24, sampleRate, true); - view.setUint32(28, sampleRate * 4, true); - view.setUint16(32, 4, true); - view.setUint16(34, 16, true); - // data sub-chunk - writeUTFBytes(view, 36, 'data'); - view.setUint32(40, interleaved.length * 2, true); - - // write the PCM samples - var lng = interleaved.length; - var index = 44; - var volume = 1; - for (var i = 0; i < lng; i++){ - view.setInt16(index, interleaved[i] * (0x7FFF * volume), true); - index += 2; - } - - handleReadBlob(buffer); - } - - function onGetUserMedia(stream){ - recording = true; - var leftchannel = []; - var rightchannel = []; - recordingLength = 0; - - audioBlob = stream; - - // retrieve the current sample rate to be used for WAV packaging - sampleRate = context.sampleRate; - - // creates a gain node - volume = context.createGain(); - - // creates an audio node from the microphone incoming stream - audioInput = context.createMediaStreamSource(stream); - - // connect the stream to the gain node - audioInput.connect(volume); - - /* From the spec: This value controls how frequently the audioprocess event is - dispatched and how many sample-frames need to be processed each call. - 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.onaudioprocess = function(sample){ - if (!recording) { - return; - } - var left = sample.inputBuffer.getChannelData(0); - var right = sample.inputBuffer.getChannelData(1); - // clone the samples - leftchannel.push(new Float32Array(left)); - rightchannel.push(new Float32Array(right)); - recordingLength += bufferSize; - } - - // connect the recorder - volume.connect (recorder); - recorder.connect (context.destination); - } - - function handleReadBlob(buffer) { - var array = new Uint8Array(buffer); - var arr = []; - for (var i=0; i ' + MediaError.MEDIA_ERR_ABORTED); - - var err = new MediaError(MediaError.MEDIA_ERR_ABORTED, 'Stalled'); - - Media.onStatus(id, Media.MEDIA_ERROR, err); - }, 2000); - }; - - audioObjects[id].onEndedCB = function () { - console.log('media::onEndedCB() - MEDIA_STATE -> MEDIA_STOPPED'); - - Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_STOPPED); - }; - - audioObjects[id].onErrorCB = function (event) { - var err = event.srcElement.error.code === MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED ? - { code: MediaError.MEDIA_ERR_ABORTED } : - event.srcElement.error; - Object.freeze(err); - - console.log('media::onErrorCB() - MEDIA_ERROR -> ' + err); - - Media.onStatus(id, Media.MEDIA_ERROR, err); - if (errorCallback) { - errorCallback(err); - } - }; - - audioObjects[id].onPlayCB = function () { - console.log('media::onPlayCB() - MEDIA_STATE -> MEDIA_STARTING ' + audioObjects[id].src); - - Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_STARTING); - }; - - audioObjects[id].onPlayingCB = function () { - console.log('media::onPlayingCB() - MEDIA_STATE -> MEDIA_RUNNING ' + audioObjects[id].src); - - Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_RUNNING); - }; - - audioObjects[id].onDurationChangeCB = function () { - console.log('media::onDurationChangeCB() - MEDIA_DURATION -> ' + audioObjects[id].duration); - - Media.onStatus(id, Media.MEDIA_DURATION, audioObjects[id].duration); - }; - - audioObjects[id].onTimeUpdateCB = function () { - console.log('media::onTimeUpdateCB() - MEDIA_POSITION -> ' + audioObjects[id].currentTime); - - Media.onStatus(id, Media.MEDIA_POSITION, audioObjects[id].currentTime); - }; - - audioObjects[id].onSeekedCB = function () { - console.log('media::onSeekedCB() - MEDIA_POSITION -> ' + audioObjects[id].currentTime); - - Media.onStatus(id, Media.MEDIA_POSITION, audioObjects[id].currentTime); - }; - - audioObjects[id].onCanPlayCB = function () { - console.log('media::onCanPlayCB() ' + audioObjects[id].src); - - window.clearTimeout(audioObjects[id].timer); - - if (audioObjects[id].isReady) { - audioObjects[id].play(); - } - }; - - audioObjects[id].addEventListener('error', audioObjects[id].onErrorCB); - audioObjects[id].addEventListener('stalled', audioObjects[id].onStalledCB); - audioObjects[id].addEventListener('canplay', audioObjects[id].onCanPlayCB); - audioObjects[id].addEventListener('ended', audioObjects[id].onEndedCB); - audioObjects[id].addEventListener('timeupdate', audioObjects[id].onTimeUpdateCB); - audioObjects[id].addEventListener('durationchange', audioObjects[id].onDurationChangeCB); - audioObjects[id].addEventListener('playing', audioObjects[id].onPlayingCB); - audioObjects[id].addEventListener('play', audioObjects[id].onPlayCB); - audioObjects[id].addEventListener('seeked', audioObjects[id].onSeekedCB); - }, - startPlayingAudio: function(successCallback, errorCallback, args) { - var id = args[0], src = args[1]; - - console.log('media::startPlayingAudio() - id =' + id + ', src =' + src); - - audioObjects[id].isReady = true; - - if (!audioObjects[id].src) { - //assigning src sets playbackRate to default value equal to 1 - //so if playbackRate was set before first run of play() function - //it should be saved and restored. - var rate = audioObjects[id].playbackRate; - - audioObjects[id].src = src; - audioObjects[id].playbackRate = rate; - return; - } - - audioObjects[id].play(); - }, - stopPlayingAudio: function(successCallback, errorCallback, args) { - var id = args[0]; - - clearTimeout(audioObjects[id].timer); - - audioObjects[id].pause(); - audioObjects[id].isReady = false; - - if (audioObjects[id].currentTime !== 0) - audioObjects[id].currentTime = 0; - - console.log('media::stopPlayingAudio() - MEDIA_STATE -> MEDIA_STOPPED'); - - audioObjects[id].removeEventListener('canplay', audioObjects[id].onCanPlayCB); - audioObjects[id].removeEventListener('ended', audioObjects[id].onEndedCB); - audioObjects[id].removeEventListener('timeupdate', audioObjects[id].onTimeUpdateCB); - audioObjects[id].removeEventListener('durationchange', audioObjects[id].onDurationChangeCB); - audioObjects[id].removeEventListener('playing', audioObjects[id].onPlayingCB); - audioObjects[id].removeEventListener('play', audioObjects[id].onPlayCB); - audioObjects[id].removeEventListener('error', audioObjects[id].onErrorCB); - audioObjects[id].removeEventListener('error', audioObjects[id].onStalledCB); - audioObjects[id].removeEventListener('seeked', audioObjects[id].onSeekedCB); - - Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_STOPPED); - }, - seekToAudio: function(successCallback, errorCallback, args) { - console.log('media::seekToAudio()'); - var id = args[0], seconds = args[1] / 1000; - - audioObjects[id].currentTime = seconds; - }, - pausePlayingAudio: function(successCallback, errorCallback, args) { - var id = args[0]; - - console.log('media::pausePlayingAudio() - MEDIA_STATE -> MEDIA_PAUSED'); - - audioObjects[id].pause(); - audioObjects[id].isReady = false; - - Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_PAUSED); - }, - getCurrentPositionAudio: function(successCallback, errorCallback, args) { - var id = args[0]; - console.log('media::getCurrentPositionAudio()'); - if (audioObjects[id].src === 'undefined') { - audioObjects[id].src = args[1]; - } - successCallback(audioObjects[id].currentTime); - }, - startRecordingAudio: function(successCallback, errorCallback, args) { - var id = args[0]; - console.log('media::startRecordingAudio()'); - if (audioObjects[id].src === 'undefined') { - audioObjects[id].src = args[1]; - } - recorder.rec(); - }, - stopRecordingAudio: function(successCallback, errorCallback, args) { - var id = args[0]; - console.log('media::stopRecordingAudio()'); - if (audioObjects[id].src === 'undefined') { - audioObjects[id].src = args[1]; - } - recorder.stop(); - }, - release: function(successCallback, errorCallback, args) { - exports.stopPlayingAudio(successCallback, errorCallback, args); - var id = args[0]; - delete audioObjects[id]; - console.log('media::release()'); - }, - setVolume: function(successCallback, errorCallback, args) { - var id = args[0], volume = args[1]; - - console.log('media::setVolume()'); - - audioObjects[id].volume = volume; - }, - //cordova common layer supports setRate function for ios platform only - //it is for future use - setRate: function(successCallback, errorCallback, args) { - var id = args[0], rate = args[1]; - - console.log('media::setRate()'); - - audioObjects[id].playbackRate = rate; - } -}; -require('cordova/exec/proxy').add('Media', exports); - -console.log('Loaded cordova.media API'); - -// TODO: remove when added to public cordova repository -> begin -}); - -exports = function(require) { - require('cordova-tizen').addPlugin('cordova-plugin-media.Media', plugin_name, 'runs'); -}; -// TODO: remove -> end diff --git a/src/media/cordova_media_extension.cc b/src/media/cordova_media_extension.cc deleted file mode 100755 index 6565afc..0000000 --- a/src/media/cordova_media_extension.cc +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "media/cordova_media_extension.h" - -// This will be generated from cordova_media_api.js -extern const char kSource_cordova_media_api[]; - -common::Extension* CreateExtension() { - return new extension::cordova::media::CordovaMediaExtension(); -} - -namespace extension { -namespace cordova { -namespace media { - -CordovaMediaExtension::CordovaMediaExtension() { - SetExtensionName("tizen.cordova.media"); - SetJavaScriptAPI(kSource_cordova_media_api); -} - -CordovaMediaExtension::~CordovaMediaExtension() {} - -} // media -} // cordova -} // extension diff --git a/src/media/cordova_media_extension.h b/src/media/cordova_media_extension.h deleted file mode 100755 index 3db047c..0000000 --- a/src/media/cordova_media_extension.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CORDOVA_MEDIA_MEDIA_EXTENSION_H_ -#define CORDOVA_MEDIA_MEDIA_EXTENSION_H_ - -#include "common/extension.h" - -namespace extension { -namespace cordova { -namespace media { - -class CordovaMediaExtension : public common::Extension { - public: - CordovaMediaExtension(); - virtual ~CordovaMediaExtension(); -}; - -} //media -} //cordova -} //extension - -#endif // CORDOVA_MEDIA_MEDIA_EXTENSION_H_