1

i just developed a tiny little game in textmode c++, what i actually wanted to do is that when the game starts it should spawn a media player in hidden mode and play the mp3 file, also i want to close the media player when the program closes or when i want it to, i have searched over the internet and found that CreateProcess() (included in shellapi.h) does this job, but i have seen that spawning an app using ShellExecute() is much easier but it does not let me Close it when i want it to, so i would like to have a working example code of the CreateProcess function that does the job, suppose that the media player is "C:\wmplayer.exe" and the mp3 file is "C:\1.mp3"... i have been a little successful in opening the mp3 player but couldnot play the mp3. i hope i'll get helped here. Regards

skaffman
  • 398,947
  • 96
  • 818
  • 769
Mohammad Salman
  • 339
  • 1
  • 3
  • 7

1 Answers1

1

You would be far better of using a programmatic interface linked to your application. For example look at the following questions for some pointers:

Trying to control mp3 player apps in different processes is akin to herding cats.

Community
  • 1
  • 1
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • PLaySound() does the job for me but i would really like to know how to spawn and then terminate child processes – Mohammad Salman Aug 28 '11 at 16:26
  • OK, I could write you an example of how to call CreateProcess, but I don't see how you can terminate it. How do you know that the sound clip has finished playing? – David Heffernan Aug 28 '11 at 16:35
  • by its length, plus i want to stop it when the game returns to menu – Mohammad Salman Aug 28 '11 at 17:35
  • Separate process is impractical for this. You say stop it by its length, but the process might take some indeterminate time to start up before sound starts. – David Heffernan Aug 28 '11 at 17:38
  • umh allrite :) i give up :) but i would still like to get a short snippet on CreateProcess and terminating it. also that i used PlaySound() to play background music, but then i cant play fx sounds (like when an enemy fires) unless i stop the background music, i would like to know how can i play to sounds simultaneously, another question is that how can i link dll files to c++ builder xe? for example if i want to use some fuctions present in the c:\\windows\\system32\\wmp.dll how can i do that in borland compiler? thanks already for the support :) – Mohammad Salman Aug 29 '11 at 05:56
  • link dlls with .h and .lib files – David Heffernan Aug 29 '11 at 07:02
  • u mean i should do like #include ?? – Mohammad Salman Aug 29 '11 at 07:35
  • no, you #include .h files. Which functions do you want to call? – David Heffernan Aug 29 '11 at 07:42
  • actually i found some code on another post on this site here is the code WMPLib.WindowsMediaPlayer wmp = new WMPLib.WindowsMediaPlayerClass(); wmp.URL = "[wav file path]"; //then control the player with : wmp.controls.play(), stop(), ... – Mohammad Salman Aug 29 '11 at 07:54
  • here is the url where i found this http://stackoverflow.com/questions/1438377/play-simultaneously-sound-in-c – Mohammad Salman Aug 29 '11 at 07:55
  • That looks like an ocx control. We are now way beyond the original question. – David Heffernan Aug 29 '11 at 08:01
  • ok now we may leave that coz mciSendstring api fuction does what i need, i just got it working, the only thing i would like to know is that how do i loop a sound file in mciSendstring? and how to link the dlls :) – Mohammad Salman Aug 29 '11 at 08:06
  • that's a different question. You should ask new questions. Comments aren't appropriate for asking new questions. Do you know how to accept and answer? – David Heffernan Aug 29 '11 at 08:08
  • my new question here http://stackoverflow.com/questions/7227742/repeating-sound-with-mcisendstring – Mohammad Salman Aug 29 '11 at 09:51