locked
Stop video capture automatically after max duration

    Question

  • Hi All,

    I want to stop the camera recording automatically after 15 seconds.Currently the cam records more than 15 secs then trims out 15 secs from the video.I want the camera turned off/stop recording after 15secs automatically.I have the following code:

    function captureVideo() {
            WinJS.log && WinJS.log("", "sample", "status");

            // Using Windows.Media.Capture.CameraCaptureUI API to capture a video
            var dialog = new Windows.Media.Capture.CameraCaptureUI();

            dialog.videoSettings.allowTrimming = true;
            dialog.videoSettings.format = Windows.Media.Capture.CameraCaptureUIVideoFormat.mp4;
            dialog.videoSettings.maxDurationInSeconds = document.getElementById("txtDuration").value;
            dialog.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.video).done(function (file) {
                
                if (file) {
                    
                    var videoBlobUrl = URL.createObjectURL(file, {oneTimeOnly: true});
                    document.getElementById("capturedVideo").src = videoBlobUrl;
                    localSettings.values[videoKey] = file.path;
                    
                } else {
                    WinJS.log && WinJS.log("No video captured.", "sample", "status");
                }
            }, function (err) {
                WinJS.log && WinJS.log(err, "sample", "error");
            });

           
            
        }

    Saturday, June 15, 2013 6:44 AM

Answers

  • Hi,

    I think you set "dialog.videoSettings.maxDurationInSeconds " property is 15.

    you can try your code,I think it is right.

    At the same time ,you can use this method:

    function startRecording() {
        document.getElementById("capture-status").innerText = "Recording.  Tap screen to stop."
        videos.createFileAsync("video.mp4", Windows.Storage.CreationCollisionOption.generateUniqueName)
          .then(function (file) {
            var profile = 
               Windows.Media.MediaProperties.MediaEncodingProfile
                      .createMp4(Windows.Media.MediaProperties.VideoEncodingQuality.auto);
    
            mediaCapture.startRecordToStorageFileAsync(profile, file).then(function () {
                recordedFile = file;
            });
        });
    }
    
    function stopRecording() {
        mediaCapture.stopRecordAsync().then(function () {
            document.getElementById("capture-status").innerText = "Tap screen to capture media";
            console.log("Video saved on disk");
        });
    }

    And you can set the time out,I think you can achive your need to.

    And more detail,you can see this Tutorial Series

    Hope this helps!

    Friday, June 21, 2013 9:58 AM
    Moderator