Commit bd6aa6d9 authored by Vladimir Kotikov's avatar Vladimir Kotikov
Browse files

CB-7547 Fixes audio recording on windows platform

parent 22068ff5
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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.
+25 −4
Original line number Diff line number Diff line
@@ -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
+20 −3
Original line number Diff line number Diff line
@@ -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')
    else if (cordova.platformId === 'blackberry')
        getRecordSrcBB();
    else if (cordova.platformId === 'windows' || cordova.platformId === 'windows8')
        getRecordSrcWin();

    //testing process and details
    function addItemToList(_list, _text)