0
0

my program plays an mp3 until it finishes, then plays another. Or, that is the idea. But it isn’t working. My app is a calculator which plays mp3’s if wanted, just for your information.

My code:

void InitCode ()
{
//at init this code is used
G.NumberofSongs = 2; //int
FSOUND_Init (44100, 32, 0);
G.stream = FSOUND_Stream_OpenFile (“song1.mp3”,FSOUND_LOOP_OFF, 0); //stream
G.CurrentLength = FSOUND_Stream_GetLengthMs (G.stream); //int

if (G.stream) FSOUND_Stream_Play (0+1, G.stream);
G.CurrentSong = 1;
}

void SortMusic ()
{
//this is called every frame
int plith;

plith = FSOUND_Stream_GetTime (G.stream);

if (plith >= G.CurrentTrackLength - 1000)
{
    //then we need to load the next song, or end altogether

    FSOUND_Stream_Stop (G.stream);
    FSOUND_Stream_Close (G.stream);

    if (G.CurrentSong < G.NumberofSongs) 
    {
         open the next song
        if (G.CurrentSong == 1) 
            G.stream = FSOUND_Stream_OpenFile ("song2.mp3",FSOUND_LOOP_OFF, 0);


        else if (G.CurrentSong == 2) 
            G.stream = FSOUND_Stream_OpenFile ("song3.mp3",FSOUND_LOOP_OFF, 0);

        G.CurrentSong++;
    }

    else 
    {
        G.stream = FSOUND_Stream_OpenFile ("song1.mp3",FSOUND_LOOP_OFF, 0);
        G.CurrentSong = 1;
    }

    if (G.stream) 
    {
        FSOUND_Stream_Play (0+1, G.stream);         
        G.CurrentLength = FSOUND_Stream_GetLengthMs (G.stream);
    }

}

}

END OF CODE

I may be getting this all wrong, but I think this should stop the 1st track with some seconds remaining, and start the new track. But it isn’t. The first track runs till it’s end, and the new track never starts.

Any guidance and help is appreciated.

<font size=-1>[ This Message was edited by: leggyguy on 2002-03-24 15:04 ]</font>

  • You must to post comments
0
0

I think it is because you forget to divid FSOUND_Stream_GetTime by 1000 :

plith = FSOUND_Stream_GetTime (G.stream) / 1000;

FSOUND_Stream_GetTime return elapsed time in millisecond so dividing by 1000, “convert” the time in second. Hope it works now :smile:

Another solution is to get the length in byte ( FSOUND_Stream_GetLength ) and compare with FSOUND_Stream_GetPosition, if it equal, we reached the end of the song.

<font size=-1>[ This Message was edited by: KarLKoX on 2002-03-24 17:48 ]</font>

  • You must to post comments
0
0

I want to thank you KK for replying. I always find it great that people are happy to help.

As for the problem, I don’t think that we need to divide the result of calling GetTime by 1000, because the return given by both GetLengthMs and GetTime both work using millisecs, so you should be able to compare them without any division.

Anyway, I did the other thing you suggested, and replaced GetLengthMs and GetTime with the GetLength and GetPosition functions, and everything is now working great.

So thanks again for your advice.

  • You must to post comments
0
0

You may also use FSOUND_Stream_SetEndCallback for highest precision! fmod will call this callback when the stream ends, so you can start another stream when the previous one has finished!

  • You must to post comments
0
0

for the problem, i reguested that u have to divide FSOUND_GetLengthMs with 1000, and divide FSOUND_GetTime with 1000 too. example :
LengthMs := FSOUND_GetLengthMs(F_Stream)/1000;
Ms := FSOUND_GetTime(F_Steam)/1000;
and then u must check it. if Ms bigger than LengthMs so u can load next file.

note : sorry for my bad english :smile:

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.