帮助我删除空引用在线-(player = new player()),或者你也可以建议你的代码在c#窗口窗体应用程序中使用flyleaflib制作一个RTSP播放器。
using System;
using System.Windows.Forms;
using FlyleafLib;
using FlyleafLib.MediaFramework.MediaPlaylist;
using FlyleafLib.MediaPlayer;
namespace MultiPagesWInForm. {
public partial class Form1: Form {
Player player;
public Form1() {
InitializeComponent();
player = new Player();
}
private void Form1_Load(object sender, EventArgs e) {
}
private void btnPlay_Click(object sender, EventArgs e) {
try {
if (player != null) {
String videoUrl = "http://pendelcam.kip.uni-heidelberg.de/mjpg/video.mjpg";
player.Open(videoUrl);
player.Play();
} else {
MessageBox.Show("The 'player' instance is null. Make sure it's properly initialized.");
}
} catch (Exception ex) {
MessageBox.Show("An exception occurred: " + ex.Message);
}
}
private void btnStop_Click(object sender, EventArgs e) {
if (player != null) {
player.Stop();
}
}
}
}
字符串
我在我的问题中提到了所有的细节.
1条答案
按热度按时间tkclm6bt1#
当
Player
对象第一次声明时,它也需要初始化。如果将Player player;
更改为Player player = new();
并删除player = new Player()
,应该可以解决null异常。记住还要在对象上设置访问修饰符(private、public等)。