namespace MyOwnPlayer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
MediaPlayer player;
MediaStream.MediaStream ms;
private void button1_Click(object sender, EventArgs e)
{
if (!CheckParameter())
return; //要播放的文件的uri
string uri = this.textBox1.Text;
try
{
ms = new MediaStream.MediaStream(uri, m_ctrlProtocalComb.SelectedItem.ToString(),
m_ctrlIpTxt.Text,
Int32.Parse(m_ctrlPortTxt.Text), 100);
}
catch (Exception exp)
{
MessageBox.Show(exp.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
ms.VideoPid = Int32.Parse(m_ctrlVideoPidTxt.Text);
ms.AudioPid = Int32.Parse(m_ctrlAudioPidTxt.Text);
ms.Start();
return;
//进行播放的控件的句柄
IntPtr hdl = this.panel1.Handle; //播放参数
#region note
//syntax :
//vlc input_stream --sout "#module1{option1=parameter1{parameter-option1},option2=parameter2}:module2{option1=...,option2=...}:..." //循环播放test.ts, 以rtp方式传送到224.1.1.1端口1234, 同时显示视频
//vlc.exe test.ts –loop :sout=#duplicate{dst=std{access=rtp,mux=ts,dst=224.1.1.1:1234},dst=display}
//:sout=#std{access=udp,mux=ts,dst=224.1.1.1:1234}
//string[] argv = new string[] { "-I", "--ignore-config" };
//string[] argv = new String[] {"-I", "--control"};
//example:
//:sout=#transcode{vcodec=h264,vb=800,scale=1,acodec=mp4a,ab=128,channels=2,samplerate=44100}
// :std{access=udp,mux=ts{video-pid=201,audio-pid=202},dst=224.1.1.1:1234}
//:sout=#transcode{vcodec=mp2v,vb=800,scale=1,acodec=mpga,ab=128,channels=2,samplerate=44100}
// :std{access=udp,mux=ts,dst=224.1.1.1:1234} :sout-keep :sout-ts-pid-video=201 :sout-ts-pid-audio=202
// string[] argv = new String[] {"–loop", "--sout=#std{access=udp,mux=ts{video-pid=201,audio-pid=202},dst=224.1.1.1:1234} :sout-ts-pid-video=201 :sout-ts-pid-audio=202"};
// string[] argv = new String[] {"–loop", "--sout=#transcode{vcodec=mp2v,vb=800,scale=1,acodec=mpga,ab=128,channels=2,samplerate=44100}", "--sout=#std{access=udp,mux=ts,dst=224.1.1.1:1234}", "--sout-keep", "--sout-ts-pid-video=201", "--sout-ts-pid-audio=202"};
//C:\F\ts\tsStream\test.ts --sout udp:224.1.1.1:1234
#endregion note
// string[] argv = new String[] {"–loop", "--sout=#std{access=udp,mux=ts,dst=224.1.1.1:1234}", "--sout-ts-pid-video=201", "--sout-ts-pid-audio=202"};
// string param2 = string.Format("--sout-ts-pid-video={0}", m_ctrlVideoPidTxt.Text);
// string param3 = string.Format("--sout-ts-pid-audio={0}", m_ctrlAudioPidTxt.Text);
#region example1
string param1 = string.Format("--sout=#duplicate{{dst=std{{access={0},mux=ts{{pid-video={1},pid-audio={2}}},dst={3}:{4}}},dst=display}}",
m_ctrlProtocalComb.SelectedItem,
m_ctrlVideoPidTxt.Text,
m_ctrlAudioPidTxt.Text,
m_ctrlIpTxt.Text,
m_ctrlPortTxt.Text);
string[] argv = new string[] {"--loop", param1};//, param2, param3};
#endregion example1
//vlc对象的创建
ExceptionStruct ex = new ExceptionStruct();
Core core = new Core(argv, ref ex);
Media media = new Media(core.CoreHandle, uri, ref ex);
player = new MediaPlayer(media.MediaHandle, ref ex); //垃圾回收
GC.Collect(); try {//播放
// player.VedioSetParent(core.CoreHandle, hdl, ref ex);
player.Play(ref ex);
}
catch (Exception exp)
{
MessageBox.Show(exp.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
//继续回收垃圾等相关操作
GC.Collect();
GC.WaitForPendingFinalizers();
}
void Button2Click(object sender, EventArgs e)
{
// ExceptionStruct ex = new ExceptionStruct();
// player.Stop(ref ex);
ms.Stop();
}
void M_ctrlOpenFileBtnClick(object sender, EventArgs e)
{
FileDialog f_dlg = new OpenFileDialog();
if (DialogResult.OK == f_dlg.ShowDialog())
this.textBox1.Text = f_dlg.FileName;
}
void Form1Load(object sender, EventArgs e)
{
m_ctrlProtocalComb.Items.Add("Udp");
m_ctrlProtocalComb.Items.Add("Rtp");
m_ctrlProtocalComb.SelectedIndex = 0;
}
bool CheckParameter()
{
if (this.textBox1.Text.Length <= 0)
{
MessageBox.Show("Please input the file to streamed!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
if (!File.Exists(textBox1.Text))
{
MessageBox.Show("The specified file dose not exist!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
if (!Path.GetExtension(textBox1.Text).Equals(".ts"))
{
MessageBox.Show("The specified file is not supported!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
return true;
}
}
}
这是源代码应该是错在强制转换上 我是要用C#编写一个vlc流媒体播放器 但是在播放TS流文件时候这个错误 是因为解码器的原因还是代码的原因呢? 请高手们解答啊
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
MediaPlayer player;
MediaStream.MediaStream ms;
private void button1_Click(object sender, EventArgs e)
{
if (!CheckParameter())
return; //要播放的文件的uri
string uri = this.textBox1.Text;
try
{
ms = new MediaStream.MediaStream(uri, m_ctrlProtocalComb.SelectedItem.ToString(),
m_ctrlIpTxt.Text,
Int32.Parse(m_ctrlPortTxt.Text), 100);
}
catch (Exception exp)
{
MessageBox.Show(exp.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
ms.VideoPid = Int32.Parse(m_ctrlVideoPidTxt.Text);
ms.AudioPid = Int32.Parse(m_ctrlAudioPidTxt.Text);
ms.Start();
return;
//进行播放的控件的句柄
IntPtr hdl = this.panel1.Handle; //播放参数
#region note
//syntax :
//vlc input_stream --sout "#module1{option1=parameter1{parameter-option1},option2=parameter2}:module2{option1=...,option2=...}:..." //循环播放test.ts, 以rtp方式传送到224.1.1.1端口1234, 同时显示视频
//vlc.exe test.ts –loop :sout=#duplicate{dst=std{access=rtp,mux=ts,dst=224.1.1.1:1234},dst=display}
//:sout=#std{access=udp,mux=ts,dst=224.1.1.1:1234}
//string[] argv = new string[] { "-I", "--ignore-config" };
//string[] argv = new String[] {"-I", "--control"};
//example:
//:sout=#transcode{vcodec=h264,vb=800,scale=1,acodec=mp4a,ab=128,channels=2,samplerate=44100}
// :std{access=udp,mux=ts{video-pid=201,audio-pid=202},dst=224.1.1.1:1234}
//:sout=#transcode{vcodec=mp2v,vb=800,scale=1,acodec=mpga,ab=128,channels=2,samplerate=44100}
// :std{access=udp,mux=ts,dst=224.1.1.1:1234} :sout-keep :sout-ts-pid-video=201 :sout-ts-pid-audio=202
// string[] argv = new String[] {"–loop", "--sout=#std{access=udp,mux=ts{video-pid=201,audio-pid=202},dst=224.1.1.1:1234} :sout-ts-pid-video=201 :sout-ts-pid-audio=202"};
// string[] argv = new String[] {"–loop", "--sout=#transcode{vcodec=mp2v,vb=800,scale=1,acodec=mpga,ab=128,channels=2,samplerate=44100}", "--sout=#std{access=udp,mux=ts,dst=224.1.1.1:1234}", "--sout-keep", "--sout-ts-pid-video=201", "--sout-ts-pid-audio=202"};
//C:\F\ts\tsStream\test.ts --sout udp:224.1.1.1:1234
#endregion note
// string[] argv = new String[] {"–loop", "--sout=#std{access=udp,mux=ts,dst=224.1.1.1:1234}", "--sout-ts-pid-video=201", "--sout-ts-pid-audio=202"};
// string param2 = string.Format("--sout-ts-pid-video={0}", m_ctrlVideoPidTxt.Text);
// string param3 = string.Format("--sout-ts-pid-audio={0}", m_ctrlAudioPidTxt.Text);
#region example1
string param1 = string.Format("--sout=#duplicate{{dst=std{{access={0},mux=ts{{pid-video={1},pid-audio={2}}},dst={3}:{4}}},dst=display}}",
m_ctrlProtocalComb.SelectedItem,
m_ctrlVideoPidTxt.Text,
m_ctrlAudioPidTxt.Text,
m_ctrlIpTxt.Text,
m_ctrlPortTxt.Text);
string[] argv = new string[] {"--loop", param1};//, param2, param3};
#endregion example1
//vlc对象的创建
ExceptionStruct ex = new ExceptionStruct();
Core core = new Core(argv, ref ex);
Media media = new Media(core.CoreHandle, uri, ref ex);
player = new MediaPlayer(media.MediaHandle, ref ex); //垃圾回收
GC.Collect(); try {//播放
// player.VedioSetParent(core.CoreHandle, hdl, ref ex);
player.Play(ref ex);
}
catch (Exception exp)
{
MessageBox.Show(exp.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
//继续回收垃圾等相关操作
GC.Collect();
GC.WaitForPendingFinalizers();
}
void Button2Click(object sender, EventArgs e)
{
// ExceptionStruct ex = new ExceptionStruct();
// player.Stop(ref ex);
ms.Stop();
}
void M_ctrlOpenFileBtnClick(object sender, EventArgs e)
{
FileDialog f_dlg = new OpenFileDialog();
if (DialogResult.OK == f_dlg.ShowDialog())
this.textBox1.Text = f_dlg.FileName;
}
void Form1Load(object sender, EventArgs e)
{
m_ctrlProtocalComb.Items.Add("Udp");
m_ctrlProtocalComb.Items.Add("Rtp");
m_ctrlProtocalComb.SelectedIndex = 0;
}
bool CheckParameter()
{
if (this.textBox1.Text.Length <= 0)
{
MessageBox.Show("Please input the file to streamed!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
if (!File.Exists(textBox1.Text))
{
MessageBox.Show("The specified file dose not exist!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
if (!Path.GetExtension(textBox1.Text).Equals(".ts"))
{
MessageBox.Show("The specified file is not supported!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
return true;
}
}
}
这是源代码应该是错在强制转换上 我是要用C#编写一个vlc流媒体播放器 但是在播放TS流文件时候这个错误 是因为解码器的原因还是代码的原因呢? 请高手们解答啊
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货