cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [1/2] git commit: Add preliminary support for Tizen.
Date Tue, 28 Jan 2014 06:46:58 GMT
Updated Branches:
  refs/heads/dev a8cd8f992 -> 563b4b6dc


Add preliminary support for Tizen.


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/commit/94e2a27f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/tree/94e2a27f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/diff/94e2a27f

Branch: refs/heads/dev
Commit: 94e2a27f3d1f752dbdd682cb099fd435baa3e71e
Parents: a309eba
Author: Salvatore Iovene <salvatore@iovene.com>
Authored: Mon Dec 2 10:56:48 2013 +0200
Committer: Salvatore Iovene <salvatore@iovene.com>
Committed: Mon Dec 2 10:56:48 2013 +0200

----------------------------------------------------------------------
 plugin.xml              |   9 +-
 src/tizen/MediaProxy.js | 202 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 209 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/94e2a27f/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 47231bf..383ac8d 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -98,6 +98,11 @@ id="org.apache.cordova.media"
             <merges target="" />
         </js-module>
     </platform>
-    
-            
+
+    <!-- tizen -->
+    <platform name="tizen">
+        <js-module src="src/tizen/MediaProxy.js" name="MediaProxy">
+            <runs/>
+        </js-module>
+    </platform>
 </plugin>

http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/94e2a27f/src/tizen/MediaProxy.js
----------------------------------------------------------------------
diff --git a/src/tizen/MediaProxy.js b/src/tizen/MediaProxy.js
new file mode 100644
index 0000000..c035dd5
--- /dev/null
+++ b/src/tizen/MediaProxy.js
@@ -0,0 +1,202 @@
+var cordova = require('cordova'),
+    Media = require('org.apache.cordova.media.Media');
+
+var MediaError = require('org.apache.cordova.media.MediaError'),
+    audioObjects = {};
+
+module.exports = {
+    // Initiates the audio file
+    create:function(successCallback, errorCallback, args) {
+        var id = args[0], src = args[1];
+
+        console.log("media::create() - id =" + id + ", src =" + src);
+
+        audioObjects[id] = new Audio(src);
+
+        audioObjects[id].onStalledCB = function () {
+            console.log("media::onStalled()");
+
+            audioObjects[id].timer = window.setTimeout(
+                    function () {
+                        audioObjects[id].pause();
+
+                        if (audioObjects[id].currentTime !== 0)
+                            audioObjects[id].currentTime = 0;
+
+                        console.log("media::onStalled() - MEDIA_ERROR -> " + 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 () {
+            console.log("media::onErrorCB() - MEDIA_ERROR -> " + event.srcElement.error);
+
+            Media.onStatus(id, Media.MEDIA_ERROR, event.srcElement.error);
+        };
+
+        audioObjects[id].onPlayCB = function () {
+            console.log("media::onPlayCB() - MEDIA_STATE -> MEDIA_STARTING");
+
+            Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_STARTING);
+        };
+
+        audioObjects[id].onPlayingCB = function () {
+            console.log("media::onPlayingCB() - MEDIA_STATE -> MEDIA_RUNNING");
+
+            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].onCanPlayCB = function () {
+            console.log("media::onCanPlayCB()");
+
+            window.clearTimeout(audioObjects[id].timer);
+
+            audioObjects[id].play();
+        };
+
+    },
+
+    // Start playing the audio
+    startPlayingAudio:function(successCallback, errorCallback, args) {
+        var id = args[0], src = args[1], options = args[2];
+
+        console.log("media::startPlayingAudio() - id =" + id + ", src =" + src + ", options
=" + options);
+
+        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('error', audioObjects[id].onErrorCB);
+        audioObjects[id].addEventListener('stalled', audioObjects[id].onStalledCB);
+
+        audioObjects[id].play();
+    },
+
+    // Stops the playing audio
+    stopPlayingAudio:function(successCallback, errorCallback, args) {
+        var id = args[0];
+
+        window.clearTimeout(audioObjects[id].timer);
+
+        audioObjects[id].pause();
+
+        if (audioObjects[id].currentTime !== 0)
+            audioObjects[id].currentTime = 0;
+
+        console.log("media::stopPlayingAudio() - MEDIA_STATE -> MEDIA_STOPPED");
+
+        Media.onStatus(id, Media.MEDIA_STATE, Media.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);
+    },
+
+    // Seeks to the position in the audio
+    seekToAudio:function(successCallback, errorCallback, args) {
+        var id = args[0], milliseconds = args[1];
+
+        console.log("media::seekToAudio()");
+
+        audioObjects[id].currentTime = milliseconds;
+        successCallback( audioObjects[id].currentTime);
+    },
+
+    // Pauses the playing audio
+    pausePlayingAudio:function(successCallback, errorCallback, args) {
+        var id = args[0];
+
+        console.log("media::pausePlayingAudio() - MEDIA_STATE -> MEDIA_PAUSED");
+
+        audioObjects[id].pause();
+
+        Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_PAUSED);
+    },
+
+    // Gets current position in the audio
+    getCurrentPositionAudio:function(successCallback, errorCallback, args) {
+        var id = args[0];
+        console.log("media::getCurrentPositionAudio()");
+        successCallback(audioObjects[id].currentTime);
+    },
+
+    // Start recording audio
+    startRecordingAudio:function(successCallback, errorCallback, args) {
+        var id = args[0], src = args[1];
+
+        console.log("media::startRecordingAudio() - id =" + id + ", src =" + src);
+
+        function gotStreamCB(stream) {
+            audioObjects[id].src = webkitURL.createObjectURL(stream);
+            console.log("media::startRecordingAudio() - stream CB");
+        }
+
+        function gotStreamFailedCB(error) {
+            console.log("media::startRecordingAudio() - error CB:" + error.toString());
+        }
+
+        if (navigator.webkitGetUserMedia) {
+            audioObjects[id] = new Audio();
+            navigator.webkitGetUserMedia('audio', gotStreamCB, gotStreamFailedCB);
+        } else {
+            console.log("webkitGetUserMedia not supported");
+        }
+        successCallback();
+    },
+
+    // Stop recording audio
+    stopRecordingAudio:function(successCallback, errorCallback, args) {
+        var id = args[0];
+
+        console.log("media::stopRecordingAudio() - id =" + id);
+
+        audioObjects[id].pause();
+        successCallback();
+    },
+
+    // Release the media object
+    release:function(successCallback, errorCallback, args) {
+        var id = args[0];
+        window.clearTimeout(audioObjects[id].timer);
+        console.log("media::release()");
+    },
+
+    setVolume:function(successCallback, errorCallback, args) {
+        var id = args[0], volume = args[1];
+
+        console.log("media::setVolume()");
+
+        audioObjects[id].volume = volume;
+    }
+};
+
+require("cordova/tizen/commandProxy").add("Media", module.exports);


Mime
View raw message