locked
how to record both video and audio files

    Question

  • i am developing a metro app which needs to record mp3 and mp4 format files. where is the APIs for it? can i dynamically stop recording in code? appreciate any help.
    Saturday, March 31, 2012 3:30 AM

Answers

  • You should first initialize the MediaCaptureSettings, create and initialize the MediaCapture object, create an encoding profile, and then start recording. You can stop recording programmactially via stopRecordAsync method of MediaCapture object.

    Here is sample code for your reference.

    // Initialize the MediaCaptureInitialzationSettings
    var captureInitSettings = new Windows.Media.Capture.MediaCaptureInitializationSettings();
        captureInitSettings.audioDeviceId = "";
        captureInitSettings.videoDeviceId = "";
        captureInitSettings.streamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.audioAndVideo;
        captureInitSettings.photoCaptureSource = Windows.Media.Capture.PhotoCaptureSource.videoPreview;
        captureInitSettings.realTimeModeEnabled = true;
    
    // Create and initialze the MediaCapture object
    var oMediaCapture = new Windows.Media.Capture.MediaCapture();
    oMediaCapture.initializeAsync(captureInitSettings).then (function (result) {
           createProfile();
        }, errorHandler);    
    
    // Create a profile.
    function createProfile() {
        profile = Windows.Media.MediaProperties.MediaEncodingProfile.createMp4(      Windows.Media.MediaProperties.VideoEncodingQuality.qvga);
    }
    
    // Start the capture.
    function startMediaCaptureSession() {   Windows.Storage.KnownFolders.videosLibrary.createFileAsync("mycapture.mp4", Windows.Storage.CreationCollisionOption.generateUniqueName).then(function (newFile) {
            storageFile = newFile;
            oMediaCapture.startRecordToStorageFileAsync(profile, storageFile).then(function (result) {          
               
            }, errorHandler);
        }  );   
    }
    
    // Stop the capture.
    function stopMediaCaptureSession() {
        oMediaCapture.stopRecordAsync().then(function (result) {}, errorHandler);         
    }
    
    
    

    Please refer to How to record audio or video for more details.


    Best wishes,


    Robin [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Thombas N Sky Tuesday, April 03, 2012 8:55 AM
    Saturday, March 31, 2012 4:04 AM
    Moderator