我使用以下代码在播放列表中创建和循环播放视频:
private void Form1_Load(object sender, EventArgs e)
{
var pl = axWindowsMediaPlayer1.playlistCollection.newPlaylist("plList");
pl.appendItem(axWindowsMediaPlayer1.newMedia(@"C:\ABC\abc.mp4"));
pl.appendItem(axWindowsMediaPlayer1.newMedia(@"C:\XYZ\xyz.mp4"));
axWindowsMediaPlayer1.currentPlaylist = pl;
//axWindowsMediaPlayer1.settings.setMode("loop", true);
axWindowsMediaPlayer1.Ctlcontrols.play();
}
但是,我发现播放列表中的下一个项目在播放列表中当前项目结束之前播放了2秒钟。然后,新项目再次播放(即,项目的前2秒播放两次,一次在当前项目结束之前,一次在下一项目开始时)。
如何确保在当前项目完成播放后才加载下一个项目?
要求2:如何检测播放列表的结尾(即播放所有视频后)
我尝试在 PlayStateChange 事件中捕获它,但我无法在媒体结束或停止或上次状态
答案 0 :(得分:1)
要完美循环播放视频,请使用以下内容:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
[DllImport("user32.dll")]
public static extern Boolean GetLastInputInfo(ref tagLASTINPUTINFO plii);
public struct tagLASTINPUTINFO
{
public uint cbSize;
public Int32 dwTime;
}
public Form1()
{
InitializeComponent();
timer1.Start();
}
private void Form1_Load(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Ctlenabled = true;
var pl = axWindowsMediaPlayer1.playlistCollection.newPlaylist("XYZ");
p1.appendItem(axWindowsMediaPlayer1.newMedia(@"C:\Folder\file1.mp4"));
pl.appendItem(axWindowsMediaPlayer1.newMedia(@"C:\Folder\file2.mp4"));
axWindowsMediaPlayer1.currentPlaylist = pl;
axWindowsMediaPlayer1.Ctlcontrols.play();
}
private void timer1_Tick(object sender, EventArgs e)
{
tagLASTINPUTINFO LastInput = new tagLASTINPUTINFO();
Int32 IdleTime;
LastInput.cbSize = (uint)Marshal.SizeOf(LastInput);
LastInput.dwTime = 0;
if (GetLastInputInfo(ref LastInput))
{
IdleTime = System.Environment.TickCount - LastInput.dwTime;
if (IdleTime > 10000)
{
axWindowsMediaPlayer1.Ctlcontrols.pause();
timer1.Stop();
MessageBox.Show("Do you wish to continue?");
}
timer1.Start();
axWindowsMediaPlayer1.Ctlcontrols.play();
}
}
}
}