I'm trying to play a .mp3 file for a direct link from the Internet. Here is the method I use:

public void Play(bool url = false) { string command = String.Format(@"open ""{0}"" type mpegvideo alias MediaFile", (!url ? (directory + "\\" + filename) : (this.url))); mciSendString(command, null, 0, IntPtr.Zero); command = "play MediaFile"; mciSendString(command, null, 0, IntPtr.Zero); } 

The fact is that not all files are played. For example, the track link: https://cs9-2v4.userapi.com/p8/890573dd1e9341.mp3 works fine.

And the link: https://cs9-6v4.userapi.com/p8/728cc80e9ff446.mp3 is not played.

The program simply continues, but there is no sound. Why such selectivity? How to play files on all links? PS I tried to play these files from the computer (url == false) , again the file downloaded from the first link has sound, but from the second sound there is not. So it's in the file itself. Although in Aimp this file runs perfectly.

  • Your links don't work for me - Zergatul
  • @Zergatul, these are links from VC servers, maybe you are from Ukraine and therefore it does not work for you. - Max
  • Through the opera I came in, I wrote 404. - Zergatul
  • @Zergatul, so where are you from? Everything opens in my browser - Max
  • I'm from Ukraine, so I go through an opera with Vpn. - Zergatul

1 answer 1

As a result, they advised this: https://msdn.microsoft.com/ru-ru/library/system.windows.media.mediaplayer(v=vs.110).aspx Everything is reproduced in it as it should.

Simple code example:

 private WindowsMediaPlayer WMP; public void Play(string filename) { WMP = new WindowsMediaPlayer(); WMP.URL = filename;//Указываем путь WMP.controls.play();//Запускаем WMP.settings.volume = 100;//Можем изменить громкость } public void Stop() { WMP.controls.stop();//Останавливаем воспроизведение WMP.close(); } 
  • Can you add more sample code for the benefit of future readers? - VladD