实现Windows Phone 8多媒体:视频

(1)拍摄视频
拍摄视频和拍摄相片的方法是基本一致的:
MediaCapture mediaCapture;

MediaEncodingProfile videoEncodingProperties;



protected override async void OnNavigatedTo(NavigationEventArgs e)

{

    HardwareButtons.CameraHalfPressed += HardwareButtons_CameraHalfPressed;

    HardwareButtons.CameraReleased += HardwareButtons_CameraReleased;



    videoCaptrueElement.Source = await Initialize();

    await mediaCapture.StartPreviewAsync();

}



async void HardwareButtons_CameraHalfPressed(object sender, CameraEventArgs e)

{

    if( mediaCapture != null )

    {

        var video = await KnownFolders.VideosLibrary.CreateFileAsync("video.mp4", CreationCollisionOption.GenerateUniqueName);

await mediaCapture.StartRecordToStorageFileAsync(videoEncodingProperties, video);

    }

}



async void HardwareButtons_CameraReleased(object sender, CameraEventArgs e)

{

    if( mediaCapture != null )

    {

        await mediaCapture.StopRecordAsync();

    }

}



private async Task<MediaCapture> Initialize()

{

    mediaCapture = new MediaCapture();

    await mediaCapture.InitializeAsync();



    mediaCapture.VideoDeviceController.PrimaryUse = CaptureUse.Video;



    videoEncodingProperties = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Vga);



    return mediaCapture;

}



protected override void OnNavigatedFrom(NavigationEventArgs e)

{

    if( mediaCapture != null )

    {

        mediaCapture.Dispose();

        mediaCapture = null;

    }

}

详细说明:http://wp.662p.com/thread-8226-1-1.html

你可能感兴趣的:(windows phone)