sorry if this has been asked before (couldnt find it on the boards). im wondering how one would tell when a mp3 (or any song for that matter) is done playing. im making a simple program (using MFC, bah) all it does is open and play the mp3 or wav when “Play” is pressed and it stops it when “Stop” is pressed (kinda obvious, but i didnt wanna assume that everyone would think it was done that way). if play is pressed while it is playing itll stop the song and start playing again (so that if the same file path/name is left in the text field itll play the same song from the beginning, if it isnt the same thing itll try and play the new song, again obvious, but i just wanna give as much detail as possible). anyways, how would i go about doing something when a song has finished playing? i have all the fmod functions encapsulated in a class so im thinking its all a matter of adding something to that (im prolly wrong though). one thing i should mention tho, using a while loop to tell if it is still playing (i have a bool that tells whether or not it has been loaded and has started playing that, when the song is stopped the bool is set to false) isnt a good idea, it seems to crash the program lol….
//play the song
while (song.loaded) //bool that tells if its loaded
SetDlgItemText(IDC_STATIC1,”The Song Is Playing!”);
SetDlgItemText(IDC_STATIC,"The Song Is No Longer Playing");
thatll crash it good lol… (when anything else is pressed)
basicly how do i make it so the bool that tells if it is playing is set to false when the song is done, or how do i tell whent he song is done?
- BungoMan85 asked 16 years ago
Well I don’t know how you’re loading your mp3, but I’ll assume you’re loading
it as a stream. If so, use a StreamEndCallback.
Look in the documentation for FSOUND_Stream_SetEndCallback
Note that this will get called EVERY time the stream is stopped, whether
it be because it has reached the end, or because Stop was called in code
ah cool, im still not clear on making it so like the moment FSOUND_Stream_SetEndCallback is called that itll send a message to the application? basicly i need this so i can have a queue of songs to play (the moment one song is done then itll start the next)
Set it up like this:
FSOUND_STREAM* stream = FSOUND_Stream_OpenFile( "C:\whatever\song.mp3", FSOUND_NORMAL, 0 )
FSOUND_Stream_SetEndCallback( stream, StreamEndCallback, userdata )
// then the callback looks like
signed char StreamEndCallback(FSOUND_STREAM *stream, void *buff, int len, int param)
Note: userdata – is anything you want to pass to the callback function – can be zero
bah, im having trouble getting it to work =/
void cfmod::PlayNextSong(FSOUND_STREAM *stream, void *buff, int len, int param)
i get the following error
——————–Configuration: mp3player – Win32 Debug——————–
C:\Program Files\Microsoft Visual Studio\My Projects\mp3player\cfmod.cpp(96) : error C2664: ‘FSOUND_Stream_SetEndCallback’ : cannot convert parameter 2 from ‘void (struct FSOUND_STREAM *,void *,int,int)’ to ‘signed char (__cdecl *)(struct FSOUND_STR
EAM *,void *,int,int)’
None of the functions with this name in scope match the target type
Skipping... (no relevant changes detected)
Error executing cl.exe.
mp3player.exe – 1 error(s), 0 warning(s)
see i thought that at first, but i tried that and it didnt seem to work
signed char cfmod::PlayNextSong(FSOUND_STREAM *stream, void *buff, int len, int param)
ok, its been a while since ive messed with any of this. so, since i know a little more about what static means, im wondering, what do i do to make it so that it knows to go to the playnextsong function? im assuming it has to do with a function pointer or something. im sorry if im just asking the same thing, like i said its been a while since i worked on this project. does it work kinda like this?
when the object with fmod function is instantiated the callback function for streams is set to the address of the play next song function. now thats where im getting confused. what do i do to tell it that? im uessing when playnext song is called i can just take the next filename off the of song names and use the regular play song function to play it.
- BungoMan85 answered 15 years ago
Please login first to submit.