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

简介: 原文:Windows Phone 8.1 多媒体(2):视频Windows Phone 8.1 多媒体(1):相片 Windows Phone 8.1 多媒体(2):视频 Windows Phone 8.
原文: 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;
}

 

目录
相关文章
|
7月前
|
Go Windows
windows安装scoop/annie下载B站等视频
windows安装scoop/annie下载B站等视频
134 0
|
6月前
|
Web App开发 数据可视化 JavaScript
动画墙纸:将视频、网页、游戏、模拟器变成windows墙纸——Lively Wallpaper
动画墙纸:将视频、网页、游戏、模拟器变成windows墙纸——Lively Wallpaper
95 0
|
编解码 搜索推荐 虚拟化
Windows平台安装MacOS虚拟机 - VMware(结尾附视频)(下)
Windows平台安装MacOS虚拟机 - VMware(结尾附视频)
339 0
|
7月前
|
Windows
Windows【工具 01】视频下载工具BBDown.exe详细使用说明(https://github.com/nilaoda/BBDown)mp4格式无法识别问题处理(最新版本1.6.1网盘分享)
Windows【工具 01】视频下载工具BBDown.exe详细使用说明(https://github.com/nilaoda/BBDown)mp4格式无法识别问题处理(最新版本1.6.1网盘分享)
595 0
|
存储 虚拟化 iOS开发
Windows平台安装MacOS虚拟机 - VMware(结尾附视频)(上)
Windows平台安装MacOS虚拟机 - VMware(结尾附视频)
425 0
|
Oracle 关系型数据库 MySQL
MySQL 5.7 界面安装 - Windows(结尾附视频)(下)
MySQL 5.7 界面安装 - Windows(结尾附视频)(下)
132 0
|
SQL Oracle 数据可视化
MySQL 5.7 界面安装 - Windows(结尾附视频)(上)
MySQL 5.7 界面安装 - Windows(结尾附视频)
146 0
|
Java 应用服务中间件 编译器
Tomcat的解压安装 - Windows(结尾附视频)
Tomcat的解压安装 - Windows(结尾附视频)
104 0
|
Linux 虚拟化 图形学
VMware Workstation 15.x 安装 - Windows(结尾附视频)
VMware Workstation 15.x 安装 - Windows(结尾附视频)
261 0
|
SQL Oracle 数据可视化
MySQL 5.6 界面安装 - Windows(结尾附视频)(上)
MySQL 5.6 界面安装 - Windows(结尾附视频)(上)
87 0