Windows Phone 8.1 多媒體(2):視頻

來源:互聯網
上載者:User

標籤:style   class   blog   code   http   tar   

原文: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;}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.