0

I´m beginner in C# coding. Especially, when it comes to use Wmp in C#. I work in visual studio 2017, on a project called "station information system" for a small, private railway in our country. The whole functionality of program I´ve done correctly, it works, so now I need to come up with an idea, how to make it playing. My program exports exact names of mp3 files into a hidden listbox. To generate patches I use this code:

axWindowsMediaPlayer1.URL = Path.Combine(Environment.CurrentDirectory, @"ZVUK\", listBox2.SelectedItem.ToString());

It works, so I came to the other functionality I need from Wmp. When Wmp plays the full song, I need it to change the index in listbox and go to second song, then third and so on. I used this condition:

if (axWindowsMediaPlayer1.playState() = WMPLib.WMPPlayState.wmppsMediaEnded)

The part "playState()" is underlined and it shows me an error: "Non-invocable member "axWindowsMediaPlayer1.playState" cannot be used like a method." I tried deleting brackets but it just underlined the whole part "axWindowsMediaPlayer1.playState". Can someone help me?

Thank you very much.

  • You could use the example provided in the Microsoft documentation here: https://learn.microsoft.com/en-us/windows/win32/wmp/axwmplib-axwindowsmediaplayer-playstate--vb-and-c – Rik Feb 21 '20 at 12:01
  • and here: https://stackoverflow.com/questions/15025626/playing-a-mp3-file-in-a-winform-application – Luuk Feb 21 '20 at 13:35

1 Answers1

1

You can use the following code to play the file one by one.

  private void button1_Click(object sender, EventArgs e)
        {
            SoundPlayer player = new SoundPlayer(@"2.wav");
            player.PlaySync();
            player = new SoundPlayer(@"\1.wav");
            player.PlaySync();
        }
Jack J Jun
  • 5,633
  • 1
  • 9
  • 27