我想在c#中使用Windows Media Player组件播放m3u8
网址。
为什么这对我不起作用:
WMPlayer.URL = "http://headend1.iranseda.ir:8134/hls-live/livepkgr/_definst_/radio-avaa/radio-avaa-40k.m3u8";
答案 0 :(得分:1)
要播放m3u8文件,您可以使用WPF-MediaKit
public MainWindow()
{
InitializeComponent();
Player = new MediaUriElement();
Player.BeginInit();
Player.EndInit();
Player.Source = new Uri("[YourPath].m3u8");
Player.Play();
}
public MediaUriElement Player { get; set; }
以下是使用Vcl.DotNet
的另一个示例在本例中,我创建了一个控制台应用程序并安装了NuGet包:
从download.videolan.org/pub/videolan/vlc下载win32和win64:
将它放在项目根文件夹中的lib / x86和lib / x64文件夹中。
class Program
{
static void Main(string[] args)
{
var vlcService = new PlayerVLCService();
vlcService.Play(new Uri("[YourPath].m3u8"));
Console.ReadLine();
vlcService.Stop();
}
}
public class PlayerVLCService
{
private VlcMediaPlayer _vlcMediaPlayer;
public PlayerVLCService()
{
var currentAssembly = Assembly.GetEntryAssembly();
var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName;
if (currentDirectory == null)
return;
DirectoryInfo vlcLibDirectory;
if (IntPtr.Size == 4)
vlcLibDirectory = new DirectoryInfo(Path.Combine(currentDirectory, @"..\..\lib\x86\"));
else
vlcLibDirectory = new DirectoryInfo(Path.Combine(currentDirectory, @"..\..\lib\x64\"));
_vlcMediaPlayer = new VlcMediaPlayer(vlcLibDirectory);
}
public void Play(Uri playPathUri)
{
_vlcMediaPlayer.SetMedia(playPathUri, null);
_vlcMediaPlayer.Play();
}
public void Stop()
{
_vlcMediaPlayer.Stop();
}
}