[UWP]写入视频文件然后播放。 [英] [UWP]Writing to a video file and then playing it.

查看:86
本文介绍了[UWP]写入视频文件然后播放。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想在UWP应用中创建一个视频文件,然后播放该文件。 我使用Windows.Storage.Pickers.FileSavePicker()来创建目标文件。 我使用Picker的原因是我希望用户能够写入他们想要的文件夹,
而不仅仅是应用程序的数据文件夹。

Hello, I want to create a video file in a UWP app, and then play the file.  I use Windows.Storage.Pickers.FileSavePicker() to create the destination file.  The reason I use Picker is that I want users to be able to write to the folders they want, not just the application's data folder.

     ;        var picker = new Windows.Storage.Pickers.FileSavePicker();

            picker.FileTypeChoices.Add(QUOT; MP4文件" ;,新列表与LT;字符串>(){"的.mp4"});

             destVideoFile = await picker.PickSaveFileAsync();

            var picker = new Windows.Storage.Pickers.FileSavePicker();
            picker.FileTypeChoices.Add("MP4 files", new List<string>() { ".mp4" });
            destVideoFile = await picker.PickSaveFileAsync();

我使用以下内容将视频播放器放入XAML页面:

I use the following to put a video player in an XAML page:

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; < MediaPlayerElement x:Name =" MediaPlayer"自动播放= QUOT假QUOT; AreTransportControlsEnabled = QUOT;真" />

        <MediaPlayerElement x:Name="MediaPlayer" AutoPlay="False" AreTransportControlsEnabled="True" />

然后我使用以下内容设置文件

Then I use the following to set the file

     &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; MediaPlayer.Source = MediaSource.CreateFromStorageFile(destVideoFile);

            MediaPlayer.Source = MediaSource.CreateFromStorageFile(destVideoFile);

我保存与该文件:

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; VAR saveOperation = composition.RenderToFileAsync(destVideoFile,MediaTrimmingPreference.Precise);

                var saveOperation = composition.RenderToFileAsync(destVideoFile, MediaTrimmingPreference.Precise);

请注意,我没有实际微调,所以微调参数是的伪像我复制的一些代码。

Note that I'm not actually trimming, so the trimming param is an artifact of some code I copied.

一切正常,有点像。 我可以在一次写入后播放目标视频,但在多次写入时,它会显示"错误:视频无法解码。" 该文件没有被锁定或任何东西,因为我可以从命令行播放它。

Everything works, sort of.  I can play the dest video usually after a single write, but on multiple writes it says "Error: Video could not be decoded."  The file isn't being locked or anything, because I can play it from a command line.

是否有某个UWP示例显示视频创建&然后在同一个应用程序中玩? 我也看到了这个,但只播放声音和没有视频。 有没有办法从UWP应用程序中弹出视频播放器?  !谢谢

Is there a UWP Sample somewhere that shows video creation & then playing in the same app?  I also saw this, but that only plays sound & no video.  Is there a way to pop a video player from a UWP app?  Thanks!

的MediaPlayer mediaPlayer1 =新的MediaPlayer();

mediaPlayer1.Source = MediaSource.CreateFromStorageFile(destVideoFile) ; $
mediaPlayer1.Play();

MediaPlayer mediaPlayer1 = new MediaPlayer();
mediaPlayer1.Source = MediaSource.CreateFromStorageFile(destVideoFile);
mediaPlayer1.Play();

推荐答案

我想我想出来了。 在播放器表单中,执行此操作以设置视频StorageFile:

I think I figured this out.  In the Player form, do this to set the video StorageFile:

        public void setVideo(StorageFile baseVideoFile)

        {

            if(baseVideoFile == null)

               返回;
$


            if(mediaSource!= null)

                mediaSource.Dispose();
$


            MEDIASOURCE = MediaSource.CreateFromStorageFile(baseVideoFile);



&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; MediaPlayer.Source = mediaSource;

        }

        public void setVideo(StorageFile baseVideoFile)
        {
            if (baseVideoFile == null)
                return;

            if (mediaSource != null)
                mediaSource.Dispose();

            mediaSource = MediaSource.CreateFromStorageFile(baseVideoFile);

            MediaPlayer.Source = mediaSource;
        }


这篇关于[UWP]写入视频文件然后播放。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆