0

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.

Nasreddine
  • 36,610
  • 17
  • 75
  • 94
Ayub
  • 2,345
  • 27
  • 29

1 Answers1

1

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

RvdK
  • 19,580
  • 4
  • 64
  • 107
  • thanks but i want get path of current song that playing in windows media player now. what is the solution? – Ayub Aug 26 '12 at 10:30
  • Maybe you should look up some tutorials for this. What you are doing in your code above is creating a media player object to play the songs by yourself rather than getting an active instance from the windows media player. – Thomas B. Aug 26 '12 at 11:35