如何在Windows窗体中播放视频 [英] How Do I Play A Video In Windows Forms

查看:348
本文介绍了如何在Windows窗体中播放视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我的视觉工作室中有一个Windows媒体播放器组件,我希望它在表单加载后播放视频。所以我把媒体播放器放在我的表格上,我的资源中有一个视频设置为媒体播放器网址。但是当我尝试它时,它表示无法将byte []转换为字符串.-。

(顺便说一句MediaPlayer1是我的窗体上的Windows媒体播放器)



如果你没有得到它,我的问题是我想将媒体播放器url链接到我的资源中的文件,但它说无法将byte []转换为字符串



继承人我的代码



主要课程:

 使用系统; 
使用 System.Collections.Generic;
使用 System.ComponentModel;
使用 System.Data;
使用 System.Drawing;
使用 System.Linq;
使用 System.Text;
使用 System.Threading.Tasks;
使用 System.Windows.Forms;

命名空间 doit2
{
public partial class Form1:Form
{
public Form1()
{
Song.play();

InitializeComponent();
}
}
}





歌曲课程:

< pre lang =c#> 使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;
使用 System.Threading.Tasks;
使用 System.Media;
使用 System.Reflection;
使用 System.IO;
使用 System.Diagnostics;

命名空间 doit2
{
class 歌曲
{

public static void play()
{
使用(Form1 form = new < /跨度> Form1中())form.MediaPlayer1.URL = Properties.Resources.doitVideo; <跨度类= 代码注释> // <跨度类= 代码注释>所述doitvideo是我的文件在资源方面,它是一个mp4
使用(Form1 form = new Form1( ))form.MediaPlayer1.Ctlcontrols.play();
}

}
}

解决方案

Mediaplayer间接使用Windows Media Player。

因此,如果媒体播放器安装(在此系统上)支持mp4,视频将播放。



如果没有,那么编解码器需要安装pack才能播放此视频。


So i have a windows media player component in my visual studio, and I want it to play a video once the form loads. So i put the media player on my form, and I have a video in my resources to set as the media player url. But when i try it, it says cannot convert byte[] to string .-.
(btw MediaPlayer1 is my windows media player on my form)

If you didnt get it, my problem is i want to link the mediaplayer url to a file in my resources but it says cannot convert byte[] to string

Heres my code

Main class:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace doit2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            Song.play();
            
            InitializeComponent();
        }
    }
}



Song class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Media;
using System.Reflection;
using System.IO;
using System.Diagnostics;

namespace doit2
{
    class Song
    {

        public static void play()
        {
            using (Form1 form = new Form1()) form.MediaPlayer1.URL = Properties.Resources.doitVideo;// the doitvideo is my file in resources, its an mp4
            using (Form1 form = new Form1()) form.MediaPlayer1.Ctlcontrols.play();
        }

    }
}

解决方案

Mediaplayer indirectly uses windows media player.
As a result, video will play if the media player installation (on this system) supports mp4.

If not, then a codec pack needs to be installed to play this video.


这篇关于如何在Windows窗体中播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆