Question

How can I give the playing song path of any player?

using System;
using System.Windows.Forms;
using WMPLib;

namespace EliteMusic
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            WindowsMediaPlayerClass player=new WindowsMediaPlayerClass();
            MessageBox.Show(player.currentMedia.name);

        }
    }
}

I get this error :

Object reference not set to an instance of an object.

Was it helpful?

Solution

This is because currentMedia is not set (null). You have to specify a path first to play with the WindowsMediaPlayerClass.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top