Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Play MP3 Files

DZone's Guide to

Play MP3 Files

·
Free Resource

public class Player
{
  private string _command;
  private bool isOpen;
 [DllImport("winmm.dll")]
private static extern long mciSendString(string strCommand,StringBuilder strReturn,int iReturnLength, IntPtr hwndCallback);
  
public Player()
 {
   
 }
public void Close()
 {
  _command = "close MediaFile";
  mciSendString(_command, null, 0, IntPtr.Zero);
       isOpen=false;
 }

public void Open(string sFileName)
 {
  _command = "open \"" + sFileName + "\" type mpegvideo alias MediaFile";
  mciSendString(_command, null, 0, IntPtr.Zero);
  isOpen = true;
 }

public void Play(bool loop)
 {
  if(isOpen)
  {
   _command = "play MediaFile";
   if (loop)
    _command += " REPEAT";
    mciSendString(_command, null, 0, IntPtr.Zero);
   }
 }

}
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}