Click here to Skip to main content
15,888,316 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am building a program, we can call it a game, and i am trying to incorporate an mp3 audio file in it and trying to make it play endlessly while the program is running.
Posted
Updated 4-Dec-15 6:35am
v2
Comments
Philippe Mori 3-Dec-15 12:08pm    
Once the file has played, play it again.

What is the problem?
Sergey Alexandrovich Kryukov 3-Dec-15 12:12pm    
What does it mean, "already existing"? Do you have source code? You have to modify and rebuild it, because something which does not play audio just does not play it.
—SA
Matt T Heffron 3-Dec-15 12:52pm    
The title of this question does not describe what you seem to be asking. Use the Improve Question and clarify it.
As Philippe said, just play the file again (and again....). Put it in a loop.
--- Probably in a BackgroundWorker or else it may do nothing except play the file. ---
Edit: Oops! I didn't notice the C++ tag, so you don't have BackgroundWorker. You may need to spin up a new thread yourself.
phil.o 3-Dec-15 15:38pm    
I'm also disturbed by the mutually-exclusive statements 'already existing program' and 'I am trying to write'.
Are you in search of a way to implement audio file playing in C++? Or do you have problems with the logic of playing it continuously? Please clarify, and share the code you have so far so that we can have a bigger picture.

1 solution

It is quite easy. Here is some example code from microsoft. You only need to build a loop in a thread with some breakup code for playing.

C++
//a global value, to access the loop 
bool stillRunning = true;
char * szFile  = "";//your dynamic path


while( stillRunning)
{
  hr = pGraph->RenderFile(szFile, NULL);
}
 
Share this answer
 
Comments
Matt T Heffron 4-Dec-15 12:26pm    
The referenced Microsoft article appears to contain enough information to solve the problem.
However...
If you're going to quote code from some other source, you need to include enough to correctly demonstrate the solution to the asked problem.
The RenderFile() method doesn't play the file, the Run() method does.
Also, you have nothing to wait for the file to complete before repeating.
The loop you've shown will run forever and accomplish nothing useful.
[no name] 4-Dec-15 12:50pm    
No Chance for me to upvote your comment :(
Matt T Heffron 4-Dec-15 13:18pm    
Thanks anyway.

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