Search In
• More options...
Find results that contain...
Find results in...

(C++) Playing External Sound

Recommended Posts

Does anyone happen to know how to play external sounds in C++, assuming I have a .wav or .mp3 file? I'm looking to just play a short 3 second sound from a file that I have but can't seem to find any way to do it with C++.

For instance, per the website at http://gtaxscripting.blogspot.com/2013/03/tut-playing-native-sounds-and-external.html, one could use:

Private exSound As System.Media.SoundPlayerexSound = New System.Media.SoundPlayerexSound.SoundLocation = ".\path\to\sound.wav"exSound.Load()

and simply call a method that implements the above snippet to play the sound. However, that is either .NET or C# and the project I'm working on is in C++.

I've tried looking for something similar for C++ and found this: https://msdn.microsoft.com/en-us/library/system.media.soundplayer(v=vs.110).aspx?cs-save-lang=1&cs-lang=cpp#code-snippet-2but have no idea what files need to be included, etc.

Edited by ClareXoBearrx3

Share on other sites

Skorpo mentioned here. How to play music with Windows Sound Player

Anyone know how I can get/set the current music volume setting through code? I'm finishing up the new Ambiance script and I'm sure players would like the volume to be controllable in a native-feeling way.

Hi,

for MP3 you can try s.t. like this (C++):

#include <windows.h>#include <MMSystem.h>#pragma comment(lib, "winmm.lib"). . . .mciSendString(TEXT("open Test.mp3"),NULL,0,0);mciSendString(TEXT("play Test.mp3 repeat"),NULL,0,0);mciSendString(TEXT("setaudio Test.mp3 output volume to 500"),NULL,0,0); // Volume = 500 (0 - 1000)

or in SCO (I never checked this! Maybe the value is NOT the volume!?!)

SET_VARIABLE_ON_SOUND(uint sound, char *varname, float value);

Best wishes,

Paul.

Edited by leftas

Share on other sites

Beautiful - didn't see that. Thanks!

Share on other sites

Beautiful - didn't see that. Thanks!

LOL why you 'like' leftas for his hint but NOT skorpro for his "beautiful" code???

just wondering

Share on other sites

Beautiful - didn't see that. Thanks!

LOL why you 'like' leftas for his hint but NOT skorpro for his "beautiful" code???

just wondering

She never named anyone.

Share on other sites

Beautiful - didn't see that. Thanks!

LOL why you 'like' leftas for his hint but NOT skorpro for his "beautiful" code???

just wondering

What does 'like' changes ? I think you sitting too much in Facebook, dude. And I'm not sure why 'c++ noob' complaining about likes. Like LetsPlayerOrDy mentioned, she never named anyone, she just said that this code beautiful, and thanked me for linking to that comment.

And I want to say that everyone who's programming - first help should be Google, not forums. I just did a search on google, and I found numerous way how to play sound and who reads in msdn a lot, also knows that

And GRAX,

If I wouldn't linked Skorpo comment, just Skorpo after some time(I don't know when you be on forums) would post the same. And okay, if don't like that I linking the comments, I will post a code by myself.

P.S. I'm not about that like, but how YOU, GRAX, complaining about the things, which aren't including YOU.

Best wishes,

Paul.

Share on other sites

@letsplayordy

i never said "she" named anyone!

just wondering why "she" liked someone for a HINT but not the programmer for his SOURCE CODE (check out the link).

@leftas

im sitting too much in FB? are you a joker? but its ok when YOU liked letsplayordys comment?? LOL really funny

yes im a c++ noob. im sure you were born as a c++ PRO right?

dont be sulk! i never said that linking is a bad thing!

btw just because of a pic of a 14yr old girl doesnt mean the user is a GIRLS

Share on other sites

You said that he/she liked leftas for his post but not Skorpro for his code. He/She was just saying thank you to leftas for linking the code. When did he/she ever say that he/she didn't appreciate Skorpro for his code?

Oh and the reason I said "she" is because I did not look into his/her profile and see the gender was male and the age was 20+. So the only thing I had to go off of was his/her picture.

Edited by LetsPlayOrDy

Share on other sites

@letsplayordy

i never said "she" named anyone!

just wondering why "she" liked someone for a HINT but not the programmer for his SOURCE CODE (check out the link).

@leftas

im sitting too much in FB? are you a joker? but its ok when YOU liked letsplayordys comment?? LOL really funny

yes im a c++ noob. im sure you were born as a c++ PRO right?

dont be sulk! i never said that linking is a bad thing!

btw just because of a pic of a 14yr old girl doesnt mean the user is a GIRLS

Yes. Because it seems that "like" button here, works the same like in facebook for you, this is not social network. Nope, sorry, I'm not joker I never said like button is a bad thing, but You complaining about, whatever she or he liking the comments. When I see a good post, I click on like button.

Sorry I was angry at that time, but if you will read in msdn or look for tutorials in network then You will improve your skills. But please, then don't complain about things which aren't including You.

Best regards,

Paul.

Edited by leftas

Share on other sites

Hi LetsPlayOrDy, leftas, ClareXoBearrx3, GRAX and everyone,

please relax, this forum is pure fun and/or hobby for all of us!

...but You complaining about, whatever she or he liking the comments. ...

just wondering

I think he didn't mean it. Due to " ;)"

If I wouldn't linked Skorpo comment, just Skorpo after some time(I don't know when you be on forums) would post the same.

Good idea -> Added to How to use Aru's C++ ScriptHook SDK Joke aside, I have forgotten this code, thanx for the link

btw just because of a pic of a 14yr old girl doesnt mean the user is a GIRLS

So the only thing I had to go off of was his/her picture.

Haha, I also thought he is a 'girl'

My comment:

If someone 'like' my work it's nice and if not it's truly uninteresting for me! I don't make this for "fame", it's just for fun and to help other modders/coders
...And yes, sometimes I write a note like "please make a small credit..." under my sources, I do this because of fairness and because I was a member of some scene groups in the good old AMIGA days (during the 90's. Yes, I'm a 'old geezer' ) and we all wrote credits ('greetings' & 'thanx') in our intros/demos...
> once learned - never forget < ... you know what I mean

Anyway, there is no reason anymore to talk about it -> Peace and let's have fun

Skorpro

Share on other sites

Haha, didn't see all of this until now.

Anyhow, I thank everyone for their help

As for the name, real name is Christopher ... but the whole female thing is a long story.

Share on other sites

As for the name, real name is Christopher ... but the whole female thing is a long story.

Well then sorry about calling you a girl lol

Share on other sites

Haha, didn't see all of this until now.

Anyhow, I thank everyone for their help

As for the name, real name is Christopher ... but the whole female thing is a long story.

Nothing wrong with transitioning, if that's what the long story is about

Share on other sites

Hahaha, nope - didn't transition

Mainly just some humorous stuff

And @Dirty: No prob lol

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

• 1 User Currently Viewing 0 members, 0 Anonymous, 1 Guest

×
×
• Create New...