Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I'm trying to make a guitar player with c#. The design is finished, but the only thing that stands in my way for finishing this project is for letting the sound stop at a certain time.
So what i do is actually ask a couple of questions in my program, first the amount of beats per minute, the note and the beat(which is always in default 4/4).
i make a small calculation of how many seconds the note actually has to play:
time = beat*60/bpm;
this amount do i send to my function that plays the note:
C#
private void playtab(int i, int j,long tijd)
{
    //MCI
    long t0 =  System.Environment.TickCount;
    long t1 = t0 + tijd*1000;
    //MCI
    string Playwav = pathname + _tabsnaam[i, j] + dataname;
    //mciSendString(PlaySound, null, 0, IntPtr.Zero);
    //SoundPlayer tabsound = new SoundPlayer(pathname + _tabsnaam[i, j] + dataname);
    Boolean gespeeld = true;
    while (gespeeld == true)
    {
        _tabs[i, j].BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(128)))));
        PlaySound(Playwav, new System.IntPtr(), PlaySoundFlags.SND_SYNC);
        //tabsound.PlaySync();
        if (System.Environment.TickCount >= t1 )
        {
           PlaySound(Playwav,new System.IntPtr(),PlaySoundFlags.SND_NOSTOP);
            _tabs[i, j].UseVisualStyleBackColor = true;
            gespeeld = false;
        }

    }
}

for play sound i use:
C#
[System.Runtime.InteropServices.DllImport("winmm.DLL", EntryPoint = "PlaySound", SetLastError = true,/* CharSet = CharSet.Unicode,*/ ThrowOnUnmappableChar = true)]
        private static extern bool PlaySound(string szSound, System.IntPtr hMod, PlaySoundFlags flags);
        [System.Flags]
        public enum PlaySoundFlags : int
        {
            SND_SYNC = 0x0000,
            SND_ASYNC = 0x0001,
            SND_NODEFAULT = 0x0002,
            SND_LOOP = 0x0008,
            SND_NOSTOP = 0x0010,
            SND_NOWAIT = 0x00002000,
            SND_FILENAME = 0x00020000,
            SND_RESOURCE = 0x00040004
        }


can someone please tell me how i can make this work
thank you.
Posted
Updated 15-Dec-10 7:59am
v2

To stop playing, use:
MIDL
PlaySound(NULL, 0, 0);


By the way, you would have much more control using directsound. Especially to control multiple sounds.
http://blogs.msdn.com/b/coding4fun/archive/2006/11/06/999786.aspx[^]

The ultimate Managed DirectSound 9 Tutorial. Part 1: a full introduction to Playback[^]

Good luck!
 
Share this answer
 
v2
Why not just use the SoundPlayer[^] class?

System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(128)))));


What is this mess? FromArgb takes Int32 parameters, so you have an int being converted to a byte then converted back to an int :omg: :rolleyes:
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900