0
0

Hello, just got a little problem for making looping music, there is no problem with stream and sample. but I cannot make it works for music.

Here the class I’m using (It is not complete for now)

[code:1j57c3g1]
class Sound
{
private:

FMUSIC_MODULE *module;
FSOUND_SAMPLE *sample;
FSOUND_STREAM *stream;
int beginTime, minTime, maxTime, randomValue;
int playType; //0 => play once, 1 => loop, 2 => randomized play
int fileType; //1 => SAMPLE, 2 => STREAM, 3 => MUSIC
bool isPlaying;
string fileName;

public:
int findStr(string src,string s)
{
int pos=-1;
pos=src.find(s,0);
if (pos==string::npos)
pos=-1;
return pos;
}
int getExt(string file)
{
int placesep;
string tmp;
placesep=findStr(fileName,".");
tmp=fileName.substr(placesep+1,3);
if (tmp=="mp3")
return 2;
if (tmp=="wav")
return 1;
if (tmp=="mid")
return 2;
if (tmp=="mp2")
return 2;
if (tmp=="raw")
return 2;
if (tmp=="mod")
return 3;
if (tmp=="xm")
return 3;
if (tmp=="it")
return 3;
if (tmp=="s3m")
return 3;
if (tmp=="ogg")
return 2;
return -1;
}
Sound(string file, int miTime, int maTime, int rnd, int readType)
{
fileName = file;
fileType = getExt(file);
playType = readType;

  switch (fileType)
  {
    case 1:
      if(readType == 1)
        sample = FSOUND_Sample_Load(FSOUND_FREE,file.c_str(),FSOUND_LOOP_NORMAL,0,0);
      else
        sample = FSOUND_Sample_Load(FSOUND_FREE,file.c_str(),FSOUND_NORMAL,0,0);
      break;
    case 2:
      if(readType == 1)
        stream = FSOUND_Stream_Open(file.c_str(),FSOUND_LOOP_NORMAL,0,0);
      else
        stream = FSOUND_Stream_Open(file.c_str(),FSOUND_NORMAL,0,0);
      break;
    case 3:        
      module = FMUSIC_LoadSong(file.c_str());
      break;                    
  }
}
~Sound()
{
  switch (fileType)
  {
    case 1:
      FSOUND_Sample_Free(sample);
      break;
    case 2:
      FSOUND_Stream_Close(stream);
      break;
    case 3:
      FMUSIC_FreeSong(module);
      break;                    
  }    
}
void playSound()
{
  switch (fileType)
  {
    case 1:
      FSOUND_PlaySound(FSOUND_FREE, sample);
      break;
    case 2:
      FSOUND_Stream_Play(FSOUND_FREE, stream);
      break;
    case 3:
      FMUSIC_PlaySong(module);
      if(playType == 1)
        FMUSIC_SetLooping(module,TRUE);
      break;                    
  }    
}

};
[/code:1j57c3g1]

thanks for yourr help
I also try to put the setLooping just after the music is laoded, it gave the same result :/

  • You must to post comments
0
0

Why do people have such an aversion to checking for errors? Check the return value of FMUSIC_LoadSong. It may not be loading the song. If it returns NULL, then call FSOUND_GetError() to see why it failed.

  • You must to post comments
0
0

The music is well loaded, I’ve tested it.
And it is palyed, but never looped, It will be played once and then not anymore

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.