This is what I came up with:
#include <SFML/Audio.hpp>
#include <iostream>
#include <string>
void LoopedMusicDelegate( void* ptr );
class LoopedMusic : public sf::Thread {
private:
sf::Music mBeginningMusic;
sf::Music mLoopingMusic;
public:
LoopedMusic( const std::string& beginFilename, const std::string& loopFilename )
: sf::Thread( LoopedMusicDelegate, this )
{
// Ignore errors for now
mBeginningMusic.OpenFromFile( beginFilename );
mLoopingMusic.OpenFromFile( loopFilename );
mLoopingMusic.SetLoop( true );
}
void Play() {
mBeginningMusic.Play();
Launch(); // Run thread
}
// TODO:
// Add Stop() 'n' stuff...
private:
friend void LoopedMusicDelegate( void* );
void Run() {
while ( mBeginningMusic.GetStatus() != sf::Music::Stopped )
;
mLoopingMusic.Play();
}
};
void LoopedMusicDelegate( void* ptr ) {
reinterpret_cast<LoopedMusic*>( ptr )->Run();
}
int main() {
LoopedMusic m( "SampleMusicIntro.wav", "SampleMusicLoop.wav" );
m.Play();
// Wait for user input:
std::cin.get();
}
Basically it waits until the introduction music finishes playing and then plays the looping music. Sometimes the introductions of some of the sample music can be anywhere from one second to six seconds. This works for a handful of the musics I have separated, unfortunately for a few, there's a distinct pause between the end of the intro music and the beginning of the looping music. I have double checked the SampleMusic*.wav files and there are no pauses and they transfer smoothly in a media player.
Any ideas?