gpt4 book ai didi

c# - C# 中的 nVlc 包装器

转载 作者:太空宇宙 更新时间:2023-11-03 10:43:32 25 4
gpt4 key购买 nike

我在 C# 中使用 nVLC 包装器。我只是想知道我在哪里可以提到从 UDP 多播中选择特定程序流的论点。参数如:--program=1

using System;
using System.ComponentModel;
using System.Windows.Forms;
using Declarations;
using Declarations.Events;
using Declarations.Media;
using Declarations.Players;
using Implementation;
using System.Linq;

namespace nVLC_Demo_WinForms
{
public partial class Form1 : Form
{
IMediaPlayerFactory m_factory;
IDiskPlayer m_player;
IMedia m_media;

string output =
@":sout=#transcode:file{dst=C:\\Users\\Abdul\\Desktop\\test\\lakha.mp4}";


public Form1()
{
InitializeComponent();

m_factory = new MediaPlayerFactory(true);
m_player = m_factory.CreatePlayer<IDiskPlayer>();

m_player.Events.PlayerPositionChanged += new EventHandler<MediaPlayerPositionChanged>(Events_PlayerPositionChanged);
m_player.Events.TimeChanged += new EventHandler<MediaPlayerTimeChanged>(Events_TimeChanged);
m_player.Events.MediaEnded += new EventHandler(Events_MediaEnded);
m_player.Events.PlayerStopped += new EventHandler(Events_PlayerStopped);

m_player.WindowHandle = panel1.Handle;
trackBar2.Value = m_player.Volume > 0 ? m_player.Volume : 0;

UISync.Init(this);
}

void Events_PlayerStopped(object sender, EventArgs e)
{
UISync.Execute(() => InitControls());
}

void Events_MediaEnded(object sender, EventArgs e)
{
UISync.Execute(() => InitControls());
}

private void InitControls()
{
trackBar1.Value = 0;
lblTime.Text = "00:00:00";
lblDuration.Text = "00:00:00";
}

void Events_TimeChanged(object sender, MediaPlayerTimeChanged e)
{
UISync.Execute(() => lblTime.Text = TimeSpan.FromMilliseconds(e.NewTime).ToString().Substring(0, 8));
}

void Events_PlayerPositionChanged(object sender, MediaPlayerPositionChanged e)
{
UISync.Execute(() => trackBar1.Value = (int)(e.NewPosition * 100));
}

private void LoadMedia()
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
textBox1.Text = ofd.FileName;
}
}

void Events_StateChanged(object sender, MediaStateChange e)
{
UISync.Execute(() => label1.Text = e.NewState.ToString());
}

void Events_DurationChanged(object sender, MediaDurationChange e)
{
UISync.Execute(() => lblDuration.Text = TimeSpan.FromMilliseconds(e.NewDuration).ToString().Substring(0, 8));
}

private void button5_Click(object sender, EventArgs e)
{
LoadMedia();
}

private void button3_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(textBox1.Text))
{
m_media = m_factory.CreateMedia<IMedia>(textBox1.Text, output);
m_media.Events.DurationChanged += new EventHandler<MediaDurationChange>(Events_DurationChanged);
m_media.Events.StateChanged += new EventHandler<MediaStateChange>(Events_StateChanged);
m_media.Events.ParsedChanged += new EventHandler<MediaParseChange>(Events_ParsedChanged);

m_player.Open(m_media);
m_media.Parse(true);

m_player.Play();
}
else
{
//errorProvider1.SetError(textBox1, "Please select media path first !");
}
}

void Events_ParsedChanged(object sender, MediaParseChange e)
{
Console.WriteLine(e.Parsed);
}

private void trackBar2_Scroll(object sender, EventArgs e)
{
m_player.Volume = trackBar2.Value;
}

private void trackBar1_Scroll(object sender, EventArgs e)
{
m_player.Position = (float)trackBar1.Value / 100;
}

private void button4_Click(object sender, EventArgs e)
{
m_player.Stop();
}

private void button2_Click(object sender, EventArgs e)
{
m_player.Pause();
}

private void button1_Click(object sender, EventArgs e)
{
m_player.ToggleMute();

button1.Text = m_player.Mute ? "Unmute" : "Mute";
}

private void textBox1_TextChanged(object sender, EventArgs e)
{
errorProvider1.Clear();
}

private class UISync
{
private static ISynchronizeInvoke Sync;

public static void Init(ISynchronizeInvoke sync)
{
Sync = sync;
}

public static void Execute(Action action)
{
Sync.BeginInvoke(action, null);
}
}

private void lblDuration_Click(object sender, EventArgs e)
{

}

}
}

最佳答案

阿卜杜勒,我知道回复有点晚了,但我也遇到了同样的问题。答案是,可以在 MediaPlayerFactory 构造函数中传递 VLC 的参数。有一个覆盖接受参数的字符串列表。

关于c# - C# 中的 nVlc 包装器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24340881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com