src/windows/MediaProxy.js
function(win, lose, args) {
        var id = args[0];
        var srcUri = processUri(args[1]);

        var dest = parseUriToPathAndFilename(srcUri);
        var destFileName = dest.fileName;

        var success = function () {
            Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_RUNNING);
        };

        var error = function (reason) {
            Media.onStatus(id, Media.MEDIA_ERROR, reason);
        };

        // 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", error);

        thisM.mediaCaptureMgr.initializeAsync(captureInitSettings).done(function (result) {
            thisM.mediaCaptureMgr.addEventListener("recordlimitationexceeded", error);
            thisM.mediaCaptureMgr.addEventListener("failed", error);

            // 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:
                        error("Invalid file type for record");
                        break;
                }
                thisM.mediaCaptureMgr.startRecordToStorageFileAsync(encodingProfile, newFile).done(success, error);
            }, error);
        }, error);
    }
function(win, lose, args) {
        var id = args[0];
        var srcUri = processUri(args[1]);

        var dest = parseUriToPathAndFilename(srcUri);
        var destFileName = dest.fileName;

        var success = function () {
            Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_RUNNING);
        };

        var error = function (reason) {
            Media.onStatus(id, Media.MEDIA_ERROR, reason);
        };

        // 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", error);

        thisM.mediaCaptureMgr.initializeAsync(captureInitSettings).done(function (result) {
            thisM.mediaCaptureMgr.addEventListener("recordlimitationexceeded", error);
            thisM.mediaCaptureMgr.addEventListener("failed", error);

            // 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:
                        error("Invalid file type for record");
                        break;
                }
                thisM.mediaCaptureMgr.startRecordToStorageFileAsync(encodingProfile, newFile).done(success, error);
            }, error);
        }, error);
    }
function ( win , lose , args ) { var id = args [ 0 ] ; var srcUri = processUri ( args [ 1 ] ) ; var dest = parseUriToPathAndFilename ( srcUri ) ; var destFileName = dest . fileName ; var success = function ( ) { Media . onStatus ( id , Media . MEDIA_STATE , Media . MEDIA_RUNNING ) ; } ; var error = function ( reason ) { Media . onStatus ( id , Media . MEDIA_ERROR , reason ) ; } ; // 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" , error ) ; thisM . mediaCaptureMgr . initializeAsync ( captureInitSettings ) . done ( function ( result ) { thisM . mediaCaptureMgr . addEventListener ( "recordlimitationexceeded" , error ) ; thisM . mediaCaptureMgr . addEventListener ( "failed" , error ) ; // 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 : error ( "Invalid file type for record" ) ; break ; } thisM . mediaCaptureMgr . startRecordToStorageFileAsync ( encodingProfile , newFile ) . done ( success , error ) ; } , error ) ; } , error ) ; }
Start recording audio
Start recording audio