c# 使用 Microsoft.DirectX.AudioVideoPlayback 如何在一个视频播放完毕后播放下一个视频
我可以将视频放入我的 Windows 窗体中。
我的问题是当视频播放完毕并开始播放另一个视频时如何制作?意思就像一个序列。完成后,播放另一个视频。
到目前为止,我已经设法播放视频,它只是循环播放视频。
有什么想法吗?
到目前为止,这是我的代码:
public partial class Form1 : Form
{
Video video;
public Form1()
{
InitializeComponent();
Initializevid1();
}
public void Initializevid1()
{
// store the original size of the panel
int width = viewport.Width;
int height = viewport.Height;
// load the selected video file
video = new Video("C:\\Users\\Dave\\Desktop\\WaterDay1.wmv");
// set the panel as the video object’s owner
video.Owner = viewport;
// stop the video
video.Play();
video.Ending +=new EventHandler(BackLoop);
// resize the video to the size original size of the panel
viewport.Size = new Size(width, height);
}
private void BackLoop(object sender, EventArgs e)
{
//video.CurrentPosition = 0;
}
i am able to put a video in my windows form.
my question is how do i make it when it finishes playing the video,it starts to play another video? meaning like in a sequence. after it finishes, play another video.
so far i have manage to play a video and it just loops the video.
any ideas?
this is my code so far:
public partial class Form1 : Form
{
Video video;
public Form1()
{
InitializeComponent();
Initializevid1();
}
public void Initializevid1()
{
// store the original size of the panel
int width = viewport.Width;
int height = viewport.Height;
// load the selected video file
video = new Video("C:\\Users\\Dave\\Desktop\\WaterDay1.wmv");
// set the panel as the video object’s owner
video.Owner = viewport;
// stop the video
video.Play();
video.Ending +=new EventHandler(BackLoop);
// resize the video to the size original size of the panel
viewport.Size = new Size(width, height);
}
private void BackLoop(object sender, EventArgs e)
{
//video.CurrentPosition = 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 AudioVideoPlayback 中播放视频序列时:
创建要显示的视频列表(使用文件路径),最好在列表框中。
使用整数从 listbox.items 索引获取文件路径。
确保在加载下一个视频之前处理视频。
每次播放视频时递增整数。
使用 if 语句查看是否是序列的结尾。
作为个人偏好(不确定它会产生多大的差异),我会在播放之前调整视频大小
因此从您的代码中: (还没有测试过,但理论上,我认为它应该有效)
When playing video sequences in AudioVideoPlayback:
Create a list of videos to be displayed (using file paths), preferably in a listbox.
Use an integer to get file path from the listbox.items index.
Ensure video is disposed before loading next video.
Increment integer every time a video is played.
Use an if statement to see if it is the end of the sequence.
As a personal preference (not sure how much difference it makes) I would resize video before playing
So from your code: (haven't tested this, but in theory, I think it should work)
您可以使用之前创建的同一视频对象在
BackLoop()
函数中打开第二个视频文件。因此,代码应该如下所示:
You can use the same video object created earlier to open the second video file in the
BackLoop()
function.So, the code should look like something this:
我使用这篇文章来适应我的需求,这是我的解决方案:
I used this post to adapt it to my needs and this was my solution: