Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C#] playing 2 wave files at the same time ?!

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Fri Apr 24, 2009 9:44 am    Post subject: [C#] playing 2 wave files at the same time ?! Reply with quote

is it possible?
i mean i have a first file called sound1.wav and second file sound2.wav
now i created thread so both files won't interrupt
it goes that way:
on the form loading i play on loop the first file so the music won't stop
and also i created thread that will have a condition that if it's true so it will play the second file at background
but still the first will be played
but for some reason i don't know why
when i turn on the thread it stops the first file and then play the second one
and after the second file is done it's not returning back to the first file
any suggestions !?
Back to top
View user's profile Send private message
NINTENDO
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Nov 2007
Posts: 1371

PostPosted: Fri Apr 24, 2009 11:15 am    Post subject: Reply with quote

Most media players can only play one stream at a time. I doubt you will be able to do this unless you use several media player components. And when you use a media player component you depend on that your cusomters/users have it installed.
_________________
Intel over amd yes.
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Fri Apr 24, 2009 11:21 am    Post subject: Reply with quote

so how does games can play few wave files at the same time
take counter strike for example
i can throw a grenade and at the same time switch to gun and shoot
and i will hear both explosion and shooting sound
that's what i'm want to do
Back to top
View user's profile Send private message
haha01haha01
Grandmaster Cheater Supreme
Reputation: 0

Joined: 15 Jun 2007
Posts: 1233
Location: http://www.SaviourFagFails.com/

PostPosted: Fri Apr 24, 2009 11:34 am    Post subject: Reply with quote

1qaz wrote:
so how does games can play few wave files at the same time
take counter strike for example
i can throw a grenade and at the same time switch to gun and shoot
and i will hear both explosion and shooting sound
that's what i'm want to do
asynchronous media playing? im pretty sure you will have to develop it by urself. why do you need to play 2 at the same time anyway?
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Fri Apr 24, 2009 11:37 am    Post subject: Reply with quote

PlaySound API with the SND_ASYNC flag.
_________________
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Fri Apr 24, 2009 11:56 am    Post subject: Reply with quote

haha01haha01 wrote:
1qaz wrote:
so how does games can play few wave files at the same time
take counter strike for example
i can throw a grenade and at the same time switch to gun and shoot
and i will hear both explosion and shooting sound
that's what i'm want to do
asynchronous media playing? im pretty sure you will have to develop it by urself. why do you need to play 2 at the same time anyway?

i'm writing some lame game in C# for school
so i thought it'd be nice to have a background music
but when i press on some button it will play the other file but still i'll hear the background music

@lurc
same thing happened, when i play other wave file it stops the background music
Back to top
View user's profile Send private message
haha01haha01
Grandmaster Cheater Supreme
Reputation: 0

Joined: 15 Jun 2007
Posts: 1233
Location: http://www.SaviourFagFails.com/

PostPosted: Fri Apr 24, 2009 12:08 pm    Post subject: Reply with quote

1qaz wrote:
haha01haha01 wrote:
1qaz wrote:
so how does games can play few wave files at the same time
take counter strike for example
i can throw a grenade and at the same time switch to gun and shoot
and i will hear both explosion and shooting sound
that's what i'm want to do
asynchronous media playing? im pretty sure you will have to develop it by urself. why do you need to play 2 at the same time anyway?

i'm writing some lame game in C# for school
so i thought it'd be nice to have a background music
but when i press on some button it will play the other file but still i'll hear the background music

@lurc
same thing happened, when i play other wave file it stops the background music
it must involve async programming. try playing through DirectX maybe?
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Fri Apr 24, 2009 12:19 pm    Post subject: Reply with quote

through DirectX ?! xD heh ?!
never touched that subject b4 so i'm pretty much don't know what you're talking about
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Fri Apr 24, 2009 12:21 pm    Post subject: Reply with quote

Sorry, my bad.
I forgot to tell you to also include the flag SND_NOSTOP.

Without it, it attempts to stop the currently playing sound to play the one currently being requested.

_________________
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Fri Apr 24, 2009 12:35 pm    Post subject: Reply with quote

okay now it's playing and not stopping the music
but it also doesn't play the other file
it's like button press isn't responding
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Fri Apr 24, 2009 12:59 pm    Post subject: Reply with quote

Show me your source code.

And you're including SND_FILENAME right? Since they're .WAV files not located within memory?

Try GetLastError also to see what's up.

_________________
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Fri Apr 24, 2009 1:15 pm    Post subject: Reply with quote

i'm not including since the first parameter is contain the file's path
but never mind that didn't help too
and my code goes like that:
Code:

        System.Threading.Thread Thread1, Thread2;

        private const int SND_ASYNC = 0x0001;
        private const int SND_NOSTOP = 0x0010;
        private const int SND_LOOP = 0x0008;
        private const int SND_FILENAME = 0x00020000;

        private void Form1_Load(object sender, EventArgs e)
        {
            Thread1 = new System.Threading.Thread(func);
            Thread2 = new System.Threading.Thread(func2);
            Thread1.Start();
        }

        private void func()
        {
            System.Threading.Thread.Sleep(100);
            PlaySound(@"xxx.wav path", IntPtr.Zero, SND_ASYNC | SND_NOSTOP | SND_LOOP | SND_FILENAME);
            System.Threading.Thread.Sleep(1);
        }

        private void func2()
        {
            PlaySound(@"xxx2.wav Path", IntPtr.Zero, SND_ASYNC | SND_NOSTOP | SND_FILENAME);
        }

        private void btnSound_Click(object sender, EventArgs e)
        {
            func2();
        }


i included SND_LOOP too so the first wav will play itself over and over
btw ignore the second thread it's useless i'll remove it later
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Fri Apr 24, 2009 1:49 pm    Post subject: Reply with quote

Put this in func2

Code:
if (PlaySound(@"xxx2.wav path", IntPtr.Zero, SND_ASYNC | SND_NOSTOP | SND_FILENAME))
    MessageBox.Show("It returned success...");
else
    MessageBox.Show("Failure");


Btw I haven't worked with C# to much, so what does the "path" do inside the string?

_________________
Back to top
View user's profile Send private message
yoyonerd
Grandmaster Cheater
Reputation: 0

Joined: 26 Apr 2008
Posts: 699
Location: -->formerly yoyonerd<--

PostPosted: Mon May 04, 2009 9:03 am    Post subject: Reply with quote

lurc wrote:
Put this in func2

Code:
if (PlaySound(@"xxx2.wav path", IntPtr.Zero, SND_ASYNC | SND_NOSTOP | SND_FILENAME))
    MessageBox.Show("It returned success...");
else
    MessageBox.Show("Failure");


Btw I haven't worked with C# to much, so what does the "path" do inside the string?


That part throws me off as well.

Would I be correct to assume you are using mciSendString?

_________________
Back to top
View user's profile Send private message AIM Address
jdm
Advanced Cheater
Reputation: 0

Joined: 19 Sep 2008
Posts: 88

PostPosted: Thu May 14, 2009 9:42 pm    Post subject: Reply with quote

Alright I did a little digging around and I found an Audio Library for C#.

Hope this helps.
http://www.ambiera.com/irrklang/
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites