在开发UWP媒体应用的时候,使用的MediaElement可以支持主流的格式,不过还是有些格式本地编解码器是不支持的,如.flv、.rmvb等,这里讲到的是第三方开源库FFmpeg,可以直接播放更多的格式。

安装Nuget:  FFmpegInterop

App.xmal.cs

using FFmpegInterop;

sealed partial class App : Application, ILogProvider
{
/// <summary>
/// 初始化单一实例应用程序对象。这是执行的创作代码的第一行,
/// 已执行,逻辑上等同于 main() 或 WinMain()。
/// </summary>
public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
FFmpegInteropLogging.SetLogLevel(LogLevel.Info);
FFmpegInteropLogging.SetLogProvider(this);
} public void Log(LogLevel level, string message)
{
System.Diagnostics.Debug.WriteLine("FFmpeg ({0}): {1}", level, message);
}
/// <summary>
/// 在应用程序由最终用户正常启动时进行调用。
/// 将在启动应用程序以打开特定文件等情况下使用。
/// </summary>
/// <param name="e">有关启动请求和过程的详细信息。</param>
}

MainPage.xaml.cs:

using FFmpegInterop;

bool forceDecodeVideo_bool = videoDecode_toggleSwitch.IsOn;//为true时,会强制转换,软解
bool forceDecodeAudio_bool = audoDecode_toggleSwitch.IsOn;,//为false时,硬解 #pragma warning disable CS0618 // 类型或成员已过时
FFmpegInteropMSS FFmpegMss = FFmpegInteropMSS.CreateFFmpegInteropMSSFromStream(video.Video_Stream, forceDecodeAudio_bool, forceDecodeVideo_bool);
#pragma warning restore CS0618 // 类型或成员已过时
var main_mediaSource = FFmpegMss.GetMediaStreamSource();
MediaElement element = new MediaElement();
element.SetMediaStreamSource(main_mediaSource);

Demo:  https://github.com/singhwong/LearnFFmpeg_Old.git

官方源码地址:  https://github.com/Microsoft/FFmpegInterop.git

有很多使用方法,还有不同的Nuget包,这只是其中一种,也是微软官方的实例demo,有些年头了。

最新文章

  1. SQLServer复制(二)--事务代理作业
  2. JSOI2016R3 瞎BB题解
  3. Java读取mat文件
  4. 办公软件Office PPT 2010视频教程从入门到精通系列教程(22课时)
  5. autowire异常的三个情况
  6. Filter登录验证过滤器(全局)
  7. javascript技巧合集
  8. 洛谷1377 M国王 (SCOI2005互不侵犯King)
  9. matlab 相关性分析
  10. document.all使用
  11. [LaTex]插图
  12. [Swift]LeetCode60. 第k个排列 | Permutation Sequence
  13. 初识Shiro
  14. 深入浅出解读 Java 虚拟机的差别测试技术
  15. 【Spring-Controller 整理研究】@RequestMapping略解
  16. 阿里云服务器ubuntu 配置
  17. 【SqlServer】解析SqlServer中的事务
  18. composer命令详解
  19. spring定时任务的注解实现方式
  20. 解决win7无法打开chm格式文件的问题

热门文章

  1. ES6-21.class基本语法
  2. BigDecimal 3个toString()方法区别
  3. ActiveMQ C#实例
  4. 使用zabbix-proxy
  5. deepin安装下载,部署在虚拟机上
  6. PHP 之验证码类封装
  7. DQL:查询表中数据
  8. ArcGIS超级工具SPTOOLS-线封闭,点集转面
  9. git如何添加子模块以便方便使用别人维护的模块?
  10. kotlin 之内联函数