【问题标题】:Error when running project c# music player运行项目c#音乐播放器时出错
【发布时间】:2021-02-07 15:35:53
【问题描述】:

嗨,这是一个简单的音乐播放器应用程序,我在 YouTube 视频之后使用 c# 开发,它就在最后,现在程序将无法正常运行,即播放选定的音乐,如您所见附图错误为“错误CS0103当前上下文中不存在名称'axWindowsMediaPlayer'”

不知道是不是编译器错误

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

        //Create Global variables of string type array to save the titles or name the of the songs and the path (location) of the songs 
        string[] paths, files;

        private void btnSelectSongs_Click(object sender, EventArgs e)
        {
            // code for selecting songs 
            OpenFileDialog ofd = new OpenFileDialog();

            // code for selecting multiple tracks 
            ofd.Multiselect = true;
            ofd.Filter = "All Supported Audio | *.mp3; *.wma | MP3s | *.mp3 | WMAs | *.wma";

            if (ofd.ShowDialog()==System.Windows.Forms.DialogResult.OK)
            {
                files = ofd.SafeFileNames; // this is to save name of the songs in the files array
                paths = ofd.FileNames; // this is to save the paths/location of the songs in the path array

                // after that we display the music titles in the listbox
                for (int i = 0; i <files.Length; i++)
                {

                    listBoxSongs.Items.Add(files[i]); // this displays the songs in the list box
                }
            }
        }

        private void listBoxSongs_SelectedIndexChanged(object sender, EventArgs e)
        {
            // code for playing the sellected music 
           axWindowsMediaPlayer.URL = paths[listBoxSongs.SelectedIndex];
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            // code for closing the app 
            this.Close();

        }
    }
}

This is how the error looks on visual studio

【问题讨论】:

  • 你的意思是..AxWindowsMediaPlayer?
  • 嗨,我已经尝试了以下
  • AxWindowsMediaPlayer.URL 仍然显示错误
  • 去过那里,据我所知,关键是引用一些 Windows DLL。但是,由于有 NAudio (github.com/naudio/NAudio) ,我建议使用它。我已经成功地用它替换了我的项目 (github.com/suterma/Replayer) 中的 Windows Media Player。如果您需要,您还可以挖掘我的项目历史以找到解决问题的方法。

标签: c# winforms visual-studio-code


【解决方案1】:

点击媒体播放器>属性>名称。检查播放器的名称,然后在您的代码中使用该名称。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多