首页 > 解决方案 > C# 媒体播放器(VLC 或 WMP)不播放

问题描述

我正在尝试构建一个简单的媒体播放器。它只有浏览按钮、播放按钮和媒体播放器屏幕。我尝试使用 Windows Media Player 和 VLC Media Player。在下面的两个代码中,Button1用于浏览视频。Button2是用来玩的。浏览工作正常,但如果我单击 Button2,则没有任何反应,并且我尝试查看消息是否存在,但它不会catch

如果我使用 Windows Media Player,我使用此代码;

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 videoplayerdeneme
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog opf = new OpenFileDialog();
            if (opf.ShowDialog() == DialogResult.OK)
            {
                //textBox1.Text = opf.FileName;
                axWindowsMediaPlayer1.URL = opf.FileName;
            }
        }

        private void Button2_Click(object sender, EventArgs e)
        {
            try {
                axWindowsMediaPlayer1.Ctlcontrols.play();
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

        }
    }
}

当我想使用 VLC 媒体播放器时,我使用此代码;

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 videoplayerdeneme
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog opf = new OpenFileDialog();
            if (opf.ShowDialog() == DialogResult.OK)
            {
                //textBox1.Text = opf.FileName;
                axVLCPlugin21.playlist.add(opf.FileName, opf.SafeFileName, null);
            }
        }

        private void Button2_Click(object sender, EventArgs e)
        {
            try {
                axVLCPlugin21.playlist.play();
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

        }
    }
}

在这两种情况下我都缺少什么?请帮我。

编辑 我没有将 64 位 VLC 媒体播放器添加到工具箱,所以我安装了 32 位版本,即使我的电脑有 64 位

标签: c#.netwinformsvlcaxwindowsmediaplayer

解决方案


推荐阅读