mirror of
https://github.com/SFML/SFML.git
synced 2024-11-24 20:31:05 +08:00
Fixed multi-threading issues with sf::Music
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1033 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
3664d275cb
commit
f842ee3518
@ -51,6 +51,9 @@ mySamples (BufferSize)
|
||||
////////////////////////////////////////////////////////////
|
||||
Music::~Music()
|
||||
{
|
||||
// We must stop before destroying the file :)
|
||||
Stop();
|
||||
|
||||
delete myFile;
|
||||
}
|
||||
|
||||
@ -60,6 +63,9 @@ Music::~Music()
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Music::OpenFromFile(const std::string& Filename)
|
||||
{
|
||||
// First stop the music if it was already running
|
||||
Stop();
|
||||
|
||||
// Create the sound file implementation, and open it in read mode
|
||||
delete myFile;
|
||||
myFile = priv::SoundFile::CreateRead(Filename);
|
||||
@ -84,6 +90,9 @@ bool Music::OpenFromFile(const std::string& Filename)
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Music::OpenFromMemory(const char* Data, std::size_t SizeInBytes)
|
||||
{
|
||||
// First stop the music if it was already running
|
||||
Stop();
|
||||
|
||||
// Create the sound file implementation, and open it in read mode
|
||||
delete myFile;
|
||||
myFile = priv::SoundFile::CreateRead(Data, SizeInBytes);
|
||||
@ -108,7 +117,7 @@ bool Music::OpenFromMemory(const char* Data, std::size_t SizeInBytes)
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Music::OnStart()
|
||||
{
|
||||
return myFile->Restart();
|
||||
return myFile && myFile->Restart();
|
||||
}
|
||||
|
||||
|
||||
@ -117,12 +126,19 @@ bool Music::OnStart()
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Music::OnGetData(SoundStream::Chunk& Data)
|
||||
{
|
||||
// Fill the chunk parameters
|
||||
Data.Samples = &mySamples[0];
|
||||
Data.NbSamples = myFile->Read(&mySamples[0], mySamples.size());
|
||||
if (myFile)
|
||||
{
|
||||
// Fill the chunk parameters
|
||||
Data.Samples = &mySamples[0];
|
||||
Data.NbSamples = myFile->Read(&mySamples[0], mySamples.size());
|
||||
|
||||
// Check if we have reached the end of the audio file
|
||||
return Data.NbSamples == mySamples.size();
|
||||
// Check if we have reached the end of the audio file
|
||||
return Data.NbSamples == mySamples.size();
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user