You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2014/09/17 23:53:28 UTC

[1/2] git commit: CB-7547 Fixes audio recording on windows platform

Repository: cordova-plugin-media
Updated Branches:
  refs/heads/master 192daad65 -> 513a5cb88


CB-7547 Fixes audio recording on windows platform


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

Branch: refs/heads/master
Commit: bd6aa6d92c0dedf35704af1bd3d9f1885d13b073
Parents: 22068ff
Author: Vladimir Kotikov <v-...@microsoft.com>
Authored: Mon Sep 15 14:11:27 2014 +0400
Committer: Vladimir Kotikov <v-...@microsoft.com>
Committed: Mon Sep 15 15:39:06 2014 +0400

----------------------------------------------------------------------
 doc/index.md               |  6 ++++++
 src/windows8/MediaProxy.js | 29 +++++++++++++++++++++++++----
 tests/tests.js             | 23 ++++++++++++++++++++---
 3 files changed, 51 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/bd6aa6d9/doc/index.md
----------------------------------------------------------------------
diff --git a/doc/index.md b/doc/index.md
index 4eb6fe6..f7325ac 100644
--- a/doc/index.md
+++ b/doc/index.md
@@ -390,6 +390,12 @@ Starts recording an audio file.
 
         var myMedia = new Media("documents://beer.mp3")
 
+### Windows 8 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.
+
+- Any subdirectory specified at record time must already exist.
+
 ### Tizen Quirks
 
 - Not supported on Tizen devices.

http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/bd6aa6d9/src/windows8/MediaProxy.js
----------------------------------------------------------------------
diff --git a/src/windows8/MediaProxy.js b/src/windows8/MediaProxy.js
index e7b6595..6ee34ae 100644
--- a/src/windows8/MediaProxy.js
+++ b/src/windows8/MediaProxy.js
@@ -26,6 +26,8 @@ var cordova = require('cordova'),
 
 var MediaError = require('org.apache.cordova.media.MediaError');
 
+var recordedFile;
+
 module.exports = {
     mediaCaptureMrg:null,
 
@@ -120,6 +122,11 @@ module.exports = {
     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));
@@ -133,8 +140,8 @@ module.exports = {
             thisM.mediaCaptureMgr.addEventListener("failed", lose);
             
             // Start recording
-            Windows.Storage.KnownFolders.musicLibrary.createFileAsync(src, Windows.Storage.CreationCollisionOption.replaceExisting).done(function (newFile) {
-                var storageFile = newFile;
+            Windows.Storage.ApplicationData.current.temporaryFolder.createFileAsync(destFileName, Windows.Storage.CreationCollisionOption.replaceExisting).done(function (newFile) {
+                recordedFile = newFile;
                 var encodingProfile = null;
                 switch (newFile.fileType) {
                     case '.m4a':
@@ -150,7 +157,7 @@ module.exports = {
                         lose("Invalid file type for record");
                         break;
                 }
-                thisM.mediaCaptureMgr.startRecordToStorageFileAsync(encodingProfile, storageFile).done(win, lose);
+                thisM.mediaCaptureMgr.startRecordToStorageFileAsync(encodingProfile, newFile).done(win, lose);
             }, lose);
         }, lose);
     },
@@ -159,7 +166,21 @@ module.exports = {
     stopRecordingAudio:function(win, lose, args) {
         var id = args[0];
         var thisM = Media.get(id);
-        thisM.mediaCaptureMgr.stopRecordAsync().done(win, lose);
+
+        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

http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/bd6aa6d9/tests/tests.js
----------------------------------------------------------------------
diff --git a/tests/tests.js b/tests/tests.js
index 7a1e3f8..ef8d7a8 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -524,6 +524,22 @@ exports.defineManualTests = function (contentEl, createActionButton) {
         window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, gotFS, fsFail);
     }
 
+    //Function to create a file for Windows recording
+    function getRecordSrcWin() {
+        var fsFail = function (error) {
+            console.log("error creating file for Win recording");
+        };
+        var gotFile = function (file) {
+            recordSrc = file.fullPath.replace(/\//g, '\\');
+        };
+        var gotFS = function (fileSystem) {
+            fileSystem.root.getFile("WinRecording.m4a", {
+                create: true
+            }, gotFile, fsFail);
+        };
+        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fsFail);
+    }
+
 //Generate Dynamic Table
     function generateTable(tableId, rows, cells, elements) {
         var table = document.createElement('table');
@@ -738,9 +754,10 @@ exports.defineManualTests = function (contentEl, createActionButton) {
     //get Special path to record if iOS || Blackberry
     if (cordova.platformId === 'ios')
         getRecordSrc();
-    else
-        if (cordova.platformId === 'blackberry')
-            getRecordSrcBB();
+    else if (cordova.platformId === 'blackberry')
+        getRecordSrcBB();
+    else if (cordova.platformId === 'windows' || cordova.platformId === 'windows8')
+        getRecordSrcWin();
 
     //testing process and details
     function addItemToList(_list, _text)


[2/2] git commit: Merge branch 'CB-7547' of https://github.com/MSOpenTech/cordova-plugin-media

Posted by pu...@apache.org.
Merge branch 'CB-7547' of https://github.com/MSOpenTech/cordova-plugin-media


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

Branch: refs/heads/master
Commit: 513a5cb887880c6f3e44029ff33d94a1fda66fe7
Parents: 192daad bd6aa6d
Author: purplecabbage <pu...@gmail.com>
Authored: Wed Sep 17 14:53:10 2014 -0700
Committer: purplecabbage <pu...@gmail.com>
Committed: Wed Sep 17 14:53:10 2014 -0700

----------------------------------------------------------------------
 doc/index.md               |  6 ++++++
 src/windows8/MediaProxy.js | 29 +++++++++++++++++++++++++----
 tests/tests.js             | 23 ++++++++++++++++++++---
 3 files changed, 51 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/513a5cb8/src/windows8/MediaProxy.js
----------------------------------------------------------------------