帮助我删除排队的空引用 - (player = new player()) 或者您也可以建议您使用 Flyleaflib 在 C# 窗口表单应用程序中制作 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();
}
}
}
}
我在问题中提到了所有细节...请教我如何做到这一点,或者您可以提供另一种方法来做到这一点,但仅使用 Flyleaflib...
当
Player
对象第一次被声明时,它也需要被初始化。如果您将 Player player;
更改为 Player player = new();
并删除 player = new Player()
,这应该可以解决您的空异常。
记住还要在对象上设置访问修饰符(私有、公共等)。