incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [8/10] js commit: Added MediaProxy.js
Date Fri, 17 Aug 2012 18:37:56 GMT
Added MediaProxy.js


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/a6e4d9e4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/a6e4d9e4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/a6e4d9e4

Branch: refs/heads/master
Commit: a6e4d9e4b479163dc49d36bd4301635d3e3341e2
Parents: 94a4290
Author: mpberk <matthew.p.berk@intel.com>
Authored: Tue Aug 14 18:59:29 2012 -0700
Committer: mpberk <matthew.p.berk@intel.com>
Committed: Tue Aug 14 18:59:29 2012 -0700

----------------------------------------------------------------------
 lib/win8metro/exec.js                        |    1 +
 lib/win8metro/plugin/win8metro/MediaProxy.js |  145 +++++++++++++++++++++
 2 files changed, 146 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/a6e4d9e4/lib/win8metro/exec.js
----------------------------------------------------------------------
diff --git a/lib/win8metro/exec.js b/lib/win8metro/exec.js
index e03151d..54604c5 100644
--- a/lib/win8metro/exec.js
+++ b/lib/win8metro/exec.js
@@ -32,6 +32,7 @@ var CommandProxy  = {
     "Compass":require('cordova/plugin/win8metro/CompassProxy'),
     "Device":require('cordova/plugin/win8metro/DeviceProxy'),
     "File":require('cordova/plugin/win8metro/FileProxy'),
+    "Media":require('cordova/plugin/win8metro/MediaProxy'),
     "NetworkStatus":require('cordova/plugin/win8metro/NetworkStatusProxy')
 };
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/a6e4d9e4/lib/win8metro/plugin/win8metro/MediaProxy.js
----------------------------------------------------------------------
diff --git a/lib/win8metro/plugin/win8metro/MediaProxy.js b/lib/win8metro/plugin/win8metro/MediaProxy.js
new file mode 100644
index 0000000..515b0f3
--- /dev/null
+++ b/lib/win8metro/plugin/win8metro/MediaProxy.js
@@ -0,0 +1,145 @@
+var cordova = require('cordova');
+
+module.exports = {
+    mediaCaptureMrg:null,
+
+    // Initiates the audio file
+    create:function(win, lose, args) {
+		var id = args[0];
+		var src = args[1];
+        Media.prototype.node = null;
+
+        var fn = src.split('.').pop(); // gets the file extension
+        if ((Media.get(id)).node === null) {
+            if (fn === 'mp3' || fn === 'wma' || fn === 'wma' ||
+                fn === 'cda' || fn === 'adx' || fn === 'wm' ||
+                fn === 'm3u' || fn === 'wmx') {
+                (Media.get(id)).node = new Audio(src);
+                (Media.get(id)).node.load();
+            } else {
+                lose("Invalid file type");
+            }
+        }
+    },
+
+    // Start playing the audio
+    startPlayingAudio:function(win, lose, args) {
+		var id = args[0];
+		//var src = args[1];
+		//var options = args[2];
+        (Media.get(id)).node.play();
+    },
+
+    // Stops the playing audio
+    stopPlayingAudio:function(win, lose, args) {
+        var id = args[0];
+        try {
+            (Media.get(id)).node.pause();
+            (Media.get(id)).node.currentTime = 0;
+            win();
+        } catch (err) {
+            lose("Failed to stop: "+err);
+        };
+    },
+
+    // Seeks to the postion in the audio
+    seekToAudio:function(win, lose, args) {
+        var id = args[0];
+        var milliseconds = args[1];
+        try {
+            (Media.get(id)).node.currentTime = milliseconds / 1000;
+            win();
+        } catch (err) {
+            lose("Failed to seek: "+err);
+        };
+    },
+
+    // Pauses the playing audio
+    pausePlayingAudio:function(win, lose, args) {
+        var id = args[0];
+        try {
+            (Media.get(id)).node.pause();
+        } catch (err) {
+            lose("Failed to pause: "+err);
+        }
+    },
+
+    // Gets current position in the audio
+    getCurrentPositionAudio:function(win, lose, args) {
+        var id = args[0];
+        try {
+            var p = (Media.get(id)).node.currentTime;
+            win(p);
+        } catch (err) {
+            lose(err);
+        }
+    },
+
+    // Start recording audio
+    startRecordingAudio:function(win, lose, args) {
+        var id = args[0];
+        var src = args[1];
+        // Initialize device
+        Media.prototype.mediaCaptureMgr = null;
+        var thisM = (Media.get(id));
+        var captureInitSettings = new Windows.Media.Capture.MediaCaptureInitializationSettings();
+        captureInitSettings.streamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.audio;
+        thisM.mediaCaptureMgr = new Windows.Media.Capture.MediaCapture();
+        thisM.mediaCaptureMgr.addEventListener("failed", lose);
+
+        thisM.mediaCaptureMgr.initializeAsync(captureInitSettings).done(function (result)
{
+            thisM.mediaCaptureMgr.addEventListener("recordlimitationexceeded", lose);
+            thisM.mediaCaptureMgr.addEventListener("failed", lose);
+        }, lose);
+        // Start recording
+        Windows.Storage.KnownFolders.musicLibrary.createFileAsync(src, Windows.Storage.CreationCollisionOption.replaceExisting).done(function
(newFile) {
+            var storageFile = newFile;
+            var fileType = this.src.split('.').pop();
+            var encodingProfile = null;
+            switch (fileType) {
+                case 'm4a':
+                    encodingProfile = Windows.Media.MediaProperties.MediaEncodingProfile.createM4a(Windows.Media.MediaProperties.AudioEncodingQuality.auto);
+                    break;
+                case 'mp3':
+                    encodingProfile = Windows.Media.MediaProperties.MediaEncodingProfile.createMp3(Windows.Media.MediaProperties.AudioEncodingQuality.auto);
+                    break;
+                case 'wma':
+                    encodingProfile = Windows.Media.MediaProperties.MediaEncodingProfile.createWma(Windows.Media.MediaProperties.AudioEncodingQuality.auto);
+                    break;
+                default:
+                    lose("Invalid file type for record");
+                    break;
+            };
+            thisM.mediaCaptureMgr.startRecordToStorageFileAsync(encodingProfile, storageFile).done(win,
lose);
+        }, lose);
+    },
+
+    // Stop recording audio
+    stopRecordingAudio:function(win, lose, args) {
+        var id = args[0];
+        var thisM = Media.get(id);
+        thisM.mediaCaptureMgr.stopRecordAsync().done(win, lose);
+    },
+
+    // Release the media object
+    release:function(win, lose, args) {
+    	var id = args[0];
+    	var thisM = Media.get(id);
+    	try {
+            delete thisM.node;
+        } catch (err) {
+            lose("Failed to release: "+err);
+        }
+    },
+    setVolume:function(win, lose, args) {
+		var id = args[0];
+		var volume = args[1];
+		var thisM = Media.get(id);
+		thisM.volume = volume;
+	}
+
+	//	Still need code for Media.onStatus
+	//		Need to fire event when duration is looked up
+	//								position is looked up
+	//								media is stopped
+};


Mime
View raw message