延迟 axWindowsMediaPlayer 播放列表中的下一个项目,直到当前项目完成播放
Delay next item in the axWindowsMediaPlayer playlist until the current item has completed playing
我使用以下代码在我的播放列表中创建和循环播放我的视频:
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 事件中捕获它,但我无法在 Media Ended 或 [=21] 中捕获它=]停止或最后状态
要完美地循环播放您的视频,请使用以下内容:
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();
}
}
}
}
我使用以下代码在我的播放列表中创建和循环播放我的视频:
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 事件中捕获它,但我无法在 Media Ended 或 [=21] 中捕获它=]停止或最后状态
要完美地循环播放您的视频,请使用以下内容:
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();
}
}
}
}