1

我使用以下代码在我的播放列表中创建和循环播放我的视频:

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 EndedStoppedLast状态中捕获它

4

1 回答 1

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();
            }
        }
    }
}
于 2016-02-07T11:05:26.117 回答