Opening Media in opened instance

Viewed 48

Hi I'm using windows forms application C#... I'm building a media player for that I need to open a file locally. I got the string array in program.cs send it to my Form1.cs now I can play the local media in my media player. But, the problem is that if I select more than 1 media and try to open them they open in different Instances of the player. I want to do that:- If my media player is already running it will send the path of file to that opened instance of media player and then it will add the media to the current playlist I'm using axWindowsMediaPlayer in my form. How can I do it?

Thanks In Advance!

1 Answers

If your media player is already running and you want to send the path of file to that opened instance of media player and then add the media to the current playlist. You can refer to the following code:

private void btnBrowse_Click(object sender, EventArgs e)
    {
        OpenFileDialog openFileDialog = new OpenFileDialog();
        openFileDialog.Multiselect = true;
        openFileDialog.Filter = "Mp3 File|*.mp3|Wav File|*.wav|Wma File|*.wma|Wmv File|*.wmv|All|*.*";
        if (openFileDialog.ShowDialog() == DialogResult.OK)
        {
            foreach (string fn in openFileDialog.FileNames)
            {
                axWindowsMediaPlayer1.currentPlaylist.appendItem(axWindowsMediaPlayer1.newMedia(fn));
            }
        }
        axWindowsMediaPlayer1.Ctlcontrols.play();
    }
Related