Play MP3 with BackgroundWorker using mciSendString

613 Views Asked by At

Hello I am trying to play an MP3 file with BackgroungWorker using a code I saw here.

My playing function is working just fine without the backgroundworker, so why I can't play it like this?

        BackgroundWorker bw = new BackgroundWorker();


        bw.WorkerReportsProgress = true;


        bw.DoWork += new DoWorkEventHandler(
        delegate(object o, DoWorkEventArgs args)
        {
            BackgroundWorker b = o as BackgroundWorker;

            string path = System.IO.Path.GetFullPath(".../.../sounds/") + "C4" + ".mp3";
            string command;
            command = "open \"" + path + "\" type mpegvideo alias fileC4";
            mciSendString(command, null, 0, IntPtr.Zero);
            command = "play all";
            mciSendString(command, null, 0, IntPtr.Zero);
        });


        bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
        delegate(object o, RunWorkerCompletedEventArgs args)
        {
            label1.Text = "HOORAY!";
        });

        bw.RunWorkerAsync();

Thanks ahead!

0

There are 0 best solutions below