原文:Windows Phone 8.1 多媒体(2):视频

Windows Phone 8.1 多媒体(1):相片

Windows Phone 8.1 多媒体(2):视频

Windows Phone 8.1 多媒体(3):音乐


(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;
}
}

(2)编辑视频

视频编辑的 API 在 Windows.Media.Editing 命名空间下,具体可看 MSDN:链接

简单的说就是把某些视频实例化为 MediaClip,然后将这些视频添加到 MediaComposition.Clips 中去,最后将这些视频拼接到一起或添加个 BackgroundAudioTrack 什么的:

MediaClip video = await MediaClip.CreateFromFileAsync(
                await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///thanks.mp4"))); MediaComposition videos = new MediaComposition();
videos.Clips.Add(video); BackgroundAudioTrack bgm = await BackgroundAudioTrack.CreateFromFileAsync(
                    await StorageFile.GetFileFromApplicationUriAsync(new Uri("Above Your Hand.mp3")));
videos.BackgroundAudioTracks.Clear();
videos.BackgroundAudioTracks.Add(bgm); await videos.SaveAsync(await ApplicationData.Current.LocalFolder.CreateFileAsync("video.mp4", CreationCollisionOption.ReplaceExisting));

(3)录制手机屏幕视频

录制手机屏幕视频是 WP8.1 新加的 API,使用方法和拍摄视频差不多,只需将录制对象设为屏幕即可:

var screenCapture = ScreenCapture.GetForCurrentView();

mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings
{
VideoSource = screenCapture.VideoSource,
AudioSource = screenCapture.AudioSource,
}); var file = await KnownFolders.VideosLibrary.CreateFileAsync("screenrecording.mp4", CreationCollisionOption.ReplaceExisting);
await mediaCapture.StartRecordToStorageFileAsync(MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto), file);

停止录制:

if( mediaCapture != null )
{
await mediaCapture.StopRecordAsync();
mediaCapture.Dispose();
mediaCapture = null;
}

最新文章

  1. 解决Visual Studio 2010闪退问题
  2. js复制内容加版权声明代码
  3. 【leetcode】Combination Sum III(middle)
  4. I2C学习
  5. MVC - 10.CodeFrist
  6. [PR &amp; ML 1] [Introduction] Informal Basic Concepts
  7. oepn sync
  8. static 方法.
  9. Nohttp框架在Android Studio中的使用
  10. android延迟执行
  11. Linux 粘着位(sticky bit)
  12. Tomcat启动一闪而过
  13. &lt;经验杂谈&gt;C#使用AES加密解密的简单介绍
  14. kubernetes 一个服务的基本组成
  15. Python MRO_C3
  16. DirectorySearcher.Filter 属性(转)
  17. mvc 下json超过限制,上传excel大小限制
  18. Libssh认证绕过CVE-2018-10933漏洞复现
  19. HDU 2073 叠框
  20. bin log、redo log、undo log和MVVC

热门文章

  1. Can&#39;t connect to local MySQL server through socket &#39;/var/run/mysqld/mysqld.sock’
  2. hadoop得知;block数据块;mapreduce实现样例;UnsupportedClassVersionError变态;该项目的源代码相关联
  3. grep之字符串搜索算法Boyer-Moore由浅入深(比KMP快3-5倍)(转)
  4. BZOJ 1096 ZJOI2007 仓库建设 边坡优化
  5. 创建在SQLServer 和 Oracle的 DBLINK
  6. Golang基于学习总结
  7. ASP.NET文件上传和下载
  8. android 电平信号状态识别View平局
  9. [SignalR]Groups操作
  10. Struts2详细说明