0
0

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….

void mp3playerdialog::OnPlay()
{
//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?

  • You must to post comments
0
0

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

  • You must to post comments
0
0

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)

  • You must to post comments
0
0

Set it up like this:

[code:1cam0rjk]

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)
{
//Whatever here
}
[/code:1cam0rjk]

Note: userdata – is anything you want to pass to the callback function – can be zero

  • You must to post comments
0
0

ah, that kinda makes sense, it calls the function that i tell it to call when it is done… thanks a ton, thats exactly what i needed =)

  • You must to post comments
0
0

bah, im having trouble getting it to work =/

[code:kejq7qsj]
void cfmod::PlaySong()
{
if (loaded)
{
SoundChannel=FSOUND_Stream_Play(FSOUND_FREE,Sound);
FSOUND_Stream_SetEndCallback(Sound,PlayNextSong,NULL);
playing=true;
}
}

void cfmod::PlayNextSong(FSOUND_STREAM *stream, void *buff, int len, int param)
{
//stuff
}
[/code:kejq7qsj]

bah?!

i get the following error

[code:kejq7qsj]

——————–Configuration: mp3player – Win32 Debug——————–
Compiling...
StdAfx.cpp
Compiling...
cfmod.cpp
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
mp3playerdialog.cpp
Generating Code...
Skipping... (no relevant changes detected)
mp3player.cpp
open.cpp
Error executing cl.exe.

mp3player.exe – 1 error(s), 0 warning(s)
[/code:kejq7qsj][/code]

  • You must to post comments
0
0

see i thought that at first, but i tried that and it didnt seem to work

[code:1qu1ayr6]
signed char cfmod::PlayNextSong(FSOUND_STREAM *stream, void *buff, int len, int param)
{
return 1;
//stuff
}
[/code:1qu1ayr6]

[code:1qu1ayr6]
void cfmod::PlaySong()
{
if (loaded)
{
SoundChannel=FSOUND_Stream_Play(FSOUND_FREE,Sound);
FSOUND_Stream_SetEndCallback(Sound,PlayNextSong,0);
playing=true;
}
}
[/code:1qu1ayr6]

  • You must to post comments
0
0

doh… so i can make it a static function and itll work? ill try that =P

  • You must to post comments
0
0

Yes. In your class definition:

[code:r1zux86i]
class cfmod {
public:
//blah blah blah
private:
static signed char PlayNextSong (FSOUND_STREAM,void,int,int);
//blah blah blah
};
[/code:r1zux86i]

  • You must to post comments
0
0

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.

  • You must to post comments
Showing 9 results
Your Answer

Please first to submit.