You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sg...@apache.org on 2015/02/05 15:53:19 UTC

[2/2] cordova-plugin-media git commit: CB-8426 Add Windows platform section to Media plugin

CB-8426 Add Windows platform section to Media plugin


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/bae9b8cf
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/tree/bae9b8cf
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/diff/bae9b8cf

Branch: refs/heads/master
Commit: bae9b8cf42e90ced5d6b2f263732bcd72a2b0285
Parents: 52bccd0
Author: sgrebnov <v-...@microsoft.com>
Authored: Wed Feb 4 21:38:08 2015 +0300
Committer: sgrebnov <v-...@microsoft.com>
Committed: Thu Feb 5 17:52:39 2015 +0300

----------------------------------------------------------------------
 doc/index.md               |   8 +-
 plugin.xml                 |  14 ++-
 src/windows/MediaProxy.js  | 230 ++++++++++++++++++++++++++++++++++++++++
 src/windows8/MediaProxy.js | 217 -------------------------------------
 4 files changed, 247 insertions(+), 222 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/bae9b8cf/doc/index.md
----------------------------------------------------------------------
diff --git a/doc/index.md b/doc/index.md
index 297d1e7..03edc0a 100644
--- a/doc/index.md
+++ b/doc/index.md
@@ -46,7 +46,7 @@ Although in the global scope, it is not available until after the `deviceready`
 - iOS
 - Windows Phone 7 and 8
 - Tizen
-- Windows 8
+- Windows
 
 ## Windows Phone Quirks
 
@@ -361,7 +361,7 @@ Starts recording an audio file.
 - Android
 - iOS
 - Windows Phone 7 and 8
-- Windows 8
+- Windows
 
 ### Quick Example
 
@@ -400,7 +400,7 @@ Starts recording an audio file.
 
         var myMedia = new Media("documents://beer.mp3")
 
-### Windows 8 Quirks
+### Windows Quirks
 
 - If a full path is not provided, the recording is placed in the AppData/temp directory. This can be accessed via the `File` API using `LocalFileSystem.TEMPORARY` or 'ms-appdata:///temp/<filename>' URI.
 
@@ -454,7 +454,7 @@ Stops recording an audio file.
 - Android
 - iOS
 - Windows Phone 7 and 8
-- Windows 8
+- Windows
 
 ### Quick Example
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/bae9b8cf/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index d00f8a2..4cbb392 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -149,7 +149,19 @@ id="org.apache.cordova.media"
 
     <!-- windows8 -->
     <platform name="windows8">
-        <js-module src="src/windows8/MediaProxy.js" name="MediaProxy">
+        <js-module src="src/windows/MediaProxy.js" name="MediaProxy">
+            <merges target="" />
+        </js-module>
+
+        <config-file target="package.appxmanifest" parent="/Package/Capabilities">
+            <Capability Name="musicLibrary" />
+            <DeviceCapability Name="microphone" />
+        </config-file>
+    </platform>
+
+    <!-- windows -->
+    <platform name="windows">
+        <js-module src="src/windows/MediaProxy.js" name="MediaProxy">
             <merges target="" />
         </js-module>
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/bae9b8cf/src/windows/MediaProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/MediaProxy.js b/src/windows/MediaProxy.js
new file mode 100644
index 0000000..a76c800
--- /dev/null
+++ b/src/windows/MediaProxy.js
@@ -0,0 +1,230 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ *
+*/
+
+/*global Windows:true */
+
+var cordova = require('cordova'),
+    Media = require('org.apache.cordova.media.Media');
+
+var MediaError = require('org.apache.cordova.media.MediaError');
+
+var recordedFile;
+
+module.exports = {
+    mediaCaptureMrg:null,
+
+    // Initiates the audio file
+    create:function(win, lose, args) {
+        var id = args[0];
+        var src = args[1];
+        var thisM = Media.get(id);
+        Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_STARTING);
+
+        Media.prototype.node = null;
+
+        var fn = src.split('.').pop(); // gets the file extension
+        if (thisM.node === null) {
+            if (fn === 'mp3' || fn === 'wma' || fn === 'wav' ||
+                fn === 'cda' || fn === 'adx' || fn === 'wm' ||
+                fn === 'm3u' || fn === 'wmx' || fn === 'm4a') {
+                thisM.node = new Audio(src);
+                thisM.node.load();
+
+                var getDuration = function () {
+                    var dur = thisM.node.duration;
+                    if (isNaN(dur)) {
+                        dur = -1;
+                    }
+                    Media.onStatus(id, Media.MEDIA_DURATION, dur);
+                };
+
+                thisM.node.onloadedmetadata = getDuration;
+                getDuration();
+            }
+            else {
+                lose && lose({ code: MediaError.MEDIA_ERR_ABORTED });
+                return false; // unable to create
+            }
+        }
+
+        return true; // successfully created
+    },
+
+    // Start playing the audio
+    startPlayingAudio:function(win, lose, args) {
+        var id = args[0];
+        //var src = args[1];
+        //var options = args[2];
+
+        var thisM = Media.get(id);
+        // if Media was released, then node will be null and we need to create it again
+        if (!thisM.node) {
+            if (!module.exports.create(win, lose, args)) {
+                // there is no reason to continue if we can't create media
+                // corresponding callback has been invoked in create so we don't need to call it here
+                return;
+            }
+        }
+
+        try {
+            thisM.node.play();
+            Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_RUNNING);
+        } catch (err) {
+            lose && lose({code:MediaError.MEDIA_ERR_ABORTED});
+        }
+    },
+
+    // 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;
+            Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_STOPPED);
+            win();
+        } catch (err) {
+            lose("Failed to stop: "+err);
+        }
+    },
+
+    // Seeks to the position 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];
+        var thisM = Media.get(id);
+        try {
+            thisM.node.pause();
+            Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_PAUSED);
+        } 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;
+            Media.onStatus(id, Media.MEDIA_POSITION, p);
+            win(p);
+        } catch (err) {
+            lose(err);
+        }
+    },
+
+    // Start recording audio
+    startRecordingAudio:function(win, lose, args) {
+        var id = args[0];
+        var src = args[1];
+
+        var normalizedSrc = src.replace(/\//g, '\\');
+        var destPath = normalizedSrc.substr(0, normalizedSrc.lastIndexOf('\\'));
+        var destFileName = normalizedSrc.replace(destPath + '\\', '');
+
+        // 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);
+            
+            // Start recording
+            Windows.Storage.ApplicationData.current.temporaryFolder.createFileAsync(destFileName, Windows.Storage.CreationCollisionOption.replaceExisting).done(function (newFile) {
+                recordedFile = newFile;
+                var encodingProfile = null;
+                switch (newFile.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, newFile).done(win, lose);
+            }, lose);
+        }, lose);
+    },
+
+    // Stop recording audio
+    stopRecordingAudio:function(win, lose, args) {
+        var id = args[0];
+        var thisM = Media.get(id);
+
+        var normalizedSrc = thisM.src.replace(/\//g, '\\');
+        var destPath = normalizedSrc.substr(0, normalizedSrc.lastIndexOf('\\'));
+        var destFileName = normalizedSrc.replace(destPath + '\\', '');
+
+        thisM.mediaCaptureMgr.stopRecordAsync().done(function () {
+            if (destPath) {
+                Windows.Storage.StorageFolder.getFolderFromPathAsync(destPath).done(function(destFolder) {
+                    recordedFile.copyAsync(destFolder, destFileName, Windows.Storage.CreationCollisionOption.replaceExisting).done(win, lose);
+                }, lose);
+            } else {
+                // if path is not defined, we leave recorded file in temporary folder (similar to iOS)
+                win();
+            }
+        }, lose);
+    },
+
+    // Release the media object
+    release:function(win, lose, args) {
+        var id = args[0];
+        var thisM = Media.get(id);
+        try {
+            if (thisM.node) {
+                thisM.node.onloadedmetadata = null;
+                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;
+    }
+};
+
+require("cordova/exec/proxy").add("Media",module.exports);

http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/bae9b8cf/src/windows8/MediaProxy.js
----------------------------------------------------------------------
diff --git a/src/windows8/MediaProxy.js b/src/windows8/MediaProxy.js
deleted file mode 100644
index e7ec51b..0000000
--- a/src/windows8/MediaProxy.js
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.
- *
-*/
-
-/*global Windows:true */
-
-var cordova = require('cordova'),
-    Media = require('org.apache.cordova.media.Media');
-
-var MediaError = require('org.apache.cordova.media.MediaError');
-
-var recordedFile;
-
-module.exports = {
-    mediaCaptureMrg:null,
-
-    // Initiates the audio file
-    create:function(win, lose, args) {
-        var id = args[0];
-        var src = args[1];
-        var thisM = Media.get(id);
-        Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_STARTING);
-
-        Media.prototype.node = null;
-
-        var fn = src.split('.').pop(); // gets the file extension
-        if (thisM.node === null) {
-            if (fn === 'mp3' || fn === 'wma' || fn === 'wav' ||
-                fn === 'cda' || fn === 'adx' || fn === 'wm' ||
-                fn === 'm3u' || fn === 'wmx' || fn === 'm4a') {
-                thisM.node = new Audio(src);
-                thisM.node.load();
-
-                var getDuration = function () {
-                    var dur = thisM.node.duration;
-                    if (isNaN(dur)) {
-                        dur = -1;
-                    }
-                    Media.onStatus(id, Media.MEDIA_DURATION, dur);
-                };
-
-                thisM.node.onloadedmetadata = getDuration;
-                getDuration();
-            }
-            else {
-                lose && lose({code:MediaError.MEDIA_ERR_ABORTED});
-            }
-        }
-    },
-
-    // Start playing the audio
-    startPlayingAudio:function(win, lose, args) {
-        var id = args[0];
-        //var src = args[1];
-        //var options = args[2];
-
-        var thisM = Media.get(id);
-        // if Media was released, then node will be null and we need to create it again
-        if (!thisM.node) {
-            module.exports.create(win, lose, args);
-        }
-
-        Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_RUNNING);
-
-        thisM.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;
-            Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_STOPPED);
-            win();
-        } catch (err) {
-            lose("Failed to stop: "+err);
-        }
-    },
-
-    // Seeks to the position 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];
-        var thisM = Media.get(id);
-        try {
-            thisM.node.pause();
-            Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_PAUSED);
-        } 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;
-            Media.onStatus(id, Media.MEDIA_POSITION, p);
-            win(p);
-        } catch (err) {
-            lose(err);
-        }
-    },
-
-    // Start recording audio
-    startRecordingAudio:function(win, lose, args) {
-        var id = args[0];
-        var src = args[1];
-
-        var normalizedSrc = src.replace(/\//g, '\\');
-        var destPath = normalizedSrc.substr(0, normalizedSrc.lastIndexOf('\\'));
-        var destFileName = normalizedSrc.replace(destPath + '\\', '');
-
-        // 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);
-            
-            // Start recording
-            Windows.Storage.ApplicationData.current.temporaryFolder.createFileAsync(destFileName, Windows.Storage.CreationCollisionOption.replaceExisting).done(function (newFile) {
-                recordedFile = newFile;
-                var encodingProfile = null;
-                switch (newFile.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, newFile).done(win, lose);
-            }, lose);
-        }, lose);
-    },
-
-    // Stop recording audio
-    stopRecordingAudio:function(win, lose, args) {
-        var id = args[0];
-        var thisM = Media.get(id);
-
-        var normalizedSrc = thisM.src.replace(/\//g, '\\');
-        var destPath = normalizedSrc.substr(0, normalizedSrc.lastIndexOf('\\'));
-        var destFileName = normalizedSrc.replace(destPath + '\\', '');
-
-        thisM.mediaCaptureMgr.stopRecordAsync().done(function () {
-            if (destPath) {
-                Windows.Storage.StorageFolder.getFolderFromPathAsync(destPath).done(function(destFolder) {
-                    recordedFile.copyAsync(destFolder, destFileName, Windows.Storage.CreationCollisionOption.replaceExisting).done(win, lose);
-                }, lose);
-            } else {
-                // if path is not defined, we leave recorded file in temporary folder (similar to iOS)
-                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;
-    }
-};
-
-require("cordova/exec/proxy").add("Media",module.exports);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org