private void cmdPlayStop_Click(object sender, EventArgs e)
        {
            String useext = txtFileType.Text;
            //If currently playing; stop. Otherwise, play the sound data in LoadedSoundData.
            if (playingsound == null && LoadedSoundData !=null)
            {

                usedriver = BCBlockGameState.Soundman.Driver;
                mTempFilename = BCBlockGameState.GetTempFile(useext);
                //write the sounddata to that file.
                FileStream writesound = new FileStream(mTempFilename, FileMode.Create);
                writesound.Write(LoadedSoundData, 0, LoadedSoundData.Length);
                writesound.Close();
                //load a sound object from the current Driver...
                usedriver.OnSoundStop += new OnSoundStopDelegate(usedriver_OnSoundStop);

                playingsound = usedriver.LoadSound(mTempFilename);

                playedsound = playingsound.Play(false);

                cmdPlayStop.Text = "&Stop";
                //start the PositionUpdate Timer.
                PositionUpdateTimer = new Timer((w) => BeginInvoke((MethodInvoker)(() => { UpdateSoundPos(); })),null,0,250);

            }
            else
            {
                PositionUpdateTimer.Dispose();
                PositionUpdateTimer = null;
                playedsound.Stop();
                // usedriver_OnSoundStop(playedsound);
                cmdPlayStop.Text = "&Play";
                SetStopState();
            }
        }
 private void SetStopState()
 {
     playedsound.Stop();
     cmdPlayStop.Invoke((MethodInvoker)(() => { cmdPlayStop.Text = "&Play"; }));
     if (PositionUpdateTimer != null)
     {
         PositionUpdateTimer.Dispose();
         PositionUpdateTimer = null;
     }
     playedsound = null;
     playingsound = null;
     //File.Delete(mTempFilename);
     BCBlockGameState.QueueDelete(mTempFilename);
     mTempFilename = "";
 }
        public iActiveSoundObject PlayMusic(String key,float volume,bool loop)
        {
            iSoundSourceObject getsource = GetSoundRnd(key);
            if (mPlayingMusic != null)
            {
                if (getsource == mPlayingMusicSource && mPlayingMusic.Paused)
                    mPlayingMusic.UnPause();
                else
                    mPlayingMusic.Stop();
            }

            iActiveSoundObject soundobj = getsource.Play(loop,volume);
            mPlayingMusicSource = getsource;
            mPlayingMusic = soundobj;
            return soundobj;
        }