在UPW中使用VLC解码媒体
VLC支持的格式很全,学会如何使用后,完全可以自己给自己写一个简单的万能播放器了。
源码来自github:https://github.com/kakone/VLC.MediaElement.git(想详细了解就clone自己研究下,这里只简单了解下)
安装NuGet包 libVLCX

安装NuGet包 VLC.MediaElement,并在XAML里添加引用 xmlns:vlc="using:VLC"

后台代码,选取文件并打开,选取格式为"*",表示包含所有格式后缀
先定义字符串常量
private const string FILE_TOKEN = "{1BBC4B94-BE33-4D79-A0CB-E5C6CDB9D107}";
private const string SUBTITLE_FILE_TOKEN = "{16BA03D6-BCA8-403E-B1E8-166B0020B4A7}";
private async void OpenFileAsync()
{
var file = await PickSingleFileAsync("*", FILE_TOKEN);
if (file != null)
{
media_element.MediaSource = VLC.MediaSource.CreateFromUri($"winrt://{FILE_TOKEN}");
}
}
private async Task<StorageFile> PickSingleFileAsync(string fileTypeFilter, string token)
{
var fileOpenPicker = new FileOpenPicker()
{
SuggestedStartLocation = PickerLocationId.VideosLibrary
};
fileOpenPicker.FileTypeFilter.Add(fileTypeFilter);
var file = await fileOpenPicker.PickSingleFileAsync();
if (file != null)
{
StorageApplicationPermissions.FutureAccessList.AddOrReplace(token, file);
}
return file;
}
添加外部字幕文件,格式为(.srt)
private async void OpenSubtitleFileAsync()
{
var source = media_element.MediaSource;
if (source == null)
{
return;
}
var file = await PickSingleFileAsync(".srt", SUBTITLE_FILE_TOKEN);
if (file != null)
{
media_element.MediaSource.ExternalTimedTextSources.Add(TimedTextSource.CreateFromUri($"winrt://{SUBTITLE_FILE_TOKEN}"));
}
}
完整代码
<Page
x:Class="VLCDemo.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:VLCDemo"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:vlc="using:VLC"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<vlc:MediaElement x:Name="media_element" Grid.Row="1" AreTransportControlsEnabled="True" HardwareAcceleration="True">
</vlc:MediaElement>
<Button x:Name="openFile_bt" Content="OpenFile" Style="{ThemeResource ButtonRevealStyle}" HorizontalAlignment="Left" CornerRadius="10" BorderThickness="1" Tapped="openFile_bt_Tapped"/>
<Button x:Name="addSubTitle_bt" Content="AddSubTitle" Style="{ThemeResource ButtonRevealStyle}" HorizontalAlignment="Left" Margin="100,0,0,0" CornerRadius="10" BorderThickness="1" Tapped="addSubTitle_bt_Tapped"/>
</Grid>
</Page>
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using VLC;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.Storage.AccessCache;
using Windows.Storage.Pickers;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x804 上介绍了“空白页”项模板
namespace VLCDemo
{
/// <summary>
/// 可用于自身或导航至 Frame 内部的空白页。
/// </summary>
public sealed partial class MainPage : Page
{
private const string FILE_TOKEN = "{1BBC4B94-BE33-4D79-A0CB-E5C6CDB9D107}";
private const string SUBTITLE_FILE_TOKEN = "{16BA03D6-BCA8-403E-B1E8-166B0020B4A7}";
public MainPage()
{
this.InitializeComponent();
}
private void openFile_bt_Tapped(object sender, TappedRoutedEventArgs e)
{
OpenFileAsync();
}
private async void OpenFileAsync()
{
var file = await PickSingleFileAsync("*", FILE_TOKEN);
if (file != null)
{
media_element.MediaSource = VLC.MediaSource.CreateFromUri($"winrt://{FILE_TOKEN}");
}
}
private async Task<StorageFile> PickSingleFileAsync(string fileTypeFilter, string token)
{
var fileOpenPicker = new FileOpenPicker()
{
SuggestedStartLocation = PickerLocationId.VideosLibrary
};
fileOpenPicker.FileTypeFilter.Add(fileTypeFilter);
var file = await fileOpenPicker.PickSingleFileAsync();
if (file != null)
{
StorageApplicationPermissions.FutureAccessList.AddOrReplace(token, file);
}
return file;
}
private void addSubTitle_bt_Tapped(object sender, TappedRoutedEventArgs e)
{
OpenSubtitleFileAsync();
}
private async void OpenSubtitleFileAsync()
{
var source = media_element.MediaSource;
if (source == null)
{
return;
}
var file = await PickSingleFileAsync(".srt", SUBTITLE_FILE_TOKEN);
if (file != null)
{
media_element.MediaSource.ExternalTimedTextSources.Add(TimedTextSource.CreateFromUri($"winrt://{SUBTITLE_FILE_TOKEN}"));
}
}
}
}
demo地址:https://github.com/singhwong/uwp-vlc-demo.git
在UPW中使用VLC解码媒体的更多相关文章
- web网页中使用vlc插件播放相机rtsp流视频
可参考: 使用vlc播放器做rtsp服务器 使用vlc播放器播放rtsp视频 使用vlc进行二次开发做自己的播放器 vlc功能还是很强大的,有很多的现成的二次开发接口,不需配置太多即可轻松做客户端播放 ...
- JavaScript中URL的解码和编码
这些URI方法encodeURI.encodeURIComponent().decodeURI().decodeURIComponent()代替了BOM的escape()和unescape()方法. ...
- Android中解决图像解码导致的OOM问题
Android中解决图像解码导致的OOM问题 原文链接:http://blog.csdn.net/zjl5211314/article/details/7042017
- Java 字符编码(二)Java 中的编解码
Java 字符编码(二)Java 中的编解码 java.nio.charset 包中提供了一套处理字符编码的工具类,主要有 Charset.CharsetDecoder.CharsetEncoder. ...
- Java 字符编码(三)Reader 中的编解码
Java 字符编码(三)Reader 中的编解码 我们知道 BufferedReader 可以将字节流转化为字符流,那它是如何编解码的呢? try (BufferedReader reader = n ...
- python3中的编解码
#一个知识点是:python3中有两种字符串数据类型:str类型和 bytes类型:sty类型存储unicode数据,bytes类型存储bytes数据 #当我们在word上编辑文件的时候,数据保存之前 ...
- Javascript中Base64编码解码的使用实例
Javascript为我们提供了一个简单的方法来实现字符串的Base64编码和解码,分别是window.btoa()函数和window.atob()函数. 1 var encodedStr = win ...
- python3中编码与解码的问题
python3中编码与解码的问题 ASCII .Unicode.UTF-8 ASCII 我们知道,在计算机内部,所有的信息最终都表示为一个二进制的字符串.每一个二进制位(bit)有0和1两种状态,因此 ...
- JS高级面试题思路(装箱和拆箱、栈和堆、js中sort()方法、.js中Date对象中的getMounth() 需要注意的、开发中编码和解码使用场景有哪些)
1.装箱和拆箱: 装箱:把基本数据类型转化为对应的引用数据类型的操作: var num = 123 // num var objNum = new Num(123) // object console ...
随机推荐
- [HNOI2015]开店 简要题解
主席树. 推下式子,发现点的深度和好算,lca深度和不好算. lca深度之和有个套路:先给a到根路径+1,再算b到根的和. 如果可以离线,即LNOI的LCA.本题强制在线,可持久化. 由于区间修改,使 ...
- 017_STM32程序移植之_AS608指纹模块
STM32程序移植之AS608指纹模块 BUG说明: 硬件接线图如图所示 STM32引脚 指纹模块引脚 功能 3.3V 3.3V PA3 Tx PA2 Rx GND GND PA1 WAK 3.3V ...
- mac 安装docker
下载地址: https://download.docker.com/mac/stable/Docker.dmg 从应用中找到 Docker 图标并点击运行.可能会询问 macOS 的登陆密码,输入即可 ...
- 下载 nasm for win64
下载nasm https://www.nasm.us/pub/nasm/releasebuilds/?C=M;O=D 以管理员身份运行安装.
- 下载安装 binary editor
http://www.eecanalyzer.net/downloads
- 动态拼接tr,th
var dltable=''; // <c:forEach items="data" var="data" ></c:forEach> ...
- 如何构建自己的docker镜像
需求情况:springboot项目想要部署到docker里面,如何部署? 步骤如下: 1.将jar包上传linux服务器 /usr/local/dockerapp 目录,在jar包所在目录创建名为 D ...
- java客户端验证https连接(忽略证书验证和证书验证两种方式)
首先根据如下操作生成证书,配置springboot https,生成一个简单的https web服务 https://www.cnblogs.com/qq931399960/p/11889349.ht ...
- 【SpringBoot】转载 springboot使用thymeleaf完成数据的页面展示
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/weixin_36380516/artic ...
- jQuery源码解读----part 2
分离构造器 通过new操作符构建一个对象,一般经过四步: A.创建一个新对象 B.将构造函数的作用域赋给新对象(所以this就指向了这个新对象) C.执行构造函数中的代码 D.返回这个新对象 最后一点 ...