這個問題參考了我之前的問題在 .Net Core 中的 WInform 應用程式中嵌入 VLC 播放器。Core.Initialize() 給出例外
我想運行播放器一段時間,在這段時間內視頻應該重復播放。目前代碼看起來像這樣......
Core.Initialize();
var libvlc = new LibVLC();
// Make VideoView control
VideoView vv = new VideoView();
vv.MediaPlayer = new MediaPlayer(libvlc);
vv.Dock = DockStyle.Fill;
// Add it to the form
Controls.Add(vv);
var uri = new Uri(@"C:\vid.3gp");
// Use command line options as Options for media playback (https://wiki.videolan.org/VLC_command-line_help/)
var media = new Media(libvlc, uri, ":input-repeat=65535");
vv.MediaPlayer.Play(media);
//Set fullscreen
this.FormBorderStyle = FormBorderStyle.None;
this.Size = Screen.PrimaryScreen.Bounds.Size;
this.Location = Screen.PrimaryScreen.Bounds.Location;
如何在特定時間后關閉播放器。目前,即使我關閉帶有播放器視頻的表單,也會繼續在后臺播放,直到我關閉整個應用程式。
只是為了通知這個 winform 應用程式是在 .netcore3.1 中創建的。
問候。
uj5u.com熱心網友回復:
創建 MediaPlayer 作為類欄位并在 WinForm 應用程式中呼叫它來啟動/暫停/停止它。
private LibVLC _libVlc;
private MediaPlayer _mediaPlayer;
...
// Call this method in your constructor/initializer
private void StartMediaPlayer(string videoUrl)
{
using var media = new Media(_libVlc, new Uri(videoUrl), ":input-repeat=65535");
_mediaPlayer = new MediaPlayer(_libVlc)
{
Media = media
};
_mediaPlayer.Play();
}
// Method to stop media player
private void button1_Click(object sender, EventArgs e)
{
_mediaPlayer.Stop();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/321420.html
