mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41: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()
|
Music::~Music()
|
||||||
{
|
{
|
||||||
|
// We must stop before destroying the file :)
|
||||||
|
Stop();
|
||||||
|
|
||||||
delete myFile;
|
delete myFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,6 +63,9 @@ Music::~Music()
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool Music::OpenFromFile(const std::string& Filename)
|
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
|
// Create the sound file implementation, and open it in read mode
|
||||||
delete myFile;
|
delete myFile;
|
||||||
myFile = priv::SoundFile::CreateRead(Filename);
|
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)
|
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
|
// Create the sound file implementation, and open it in read mode
|
||||||
delete myFile;
|
delete myFile;
|
||||||
myFile = priv::SoundFile::CreateRead(Data, SizeInBytes);
|
myFile = priv::SoundFile::CreateRead(Data, SizeInBytes);
|
||||||
@ -108,7 +117,7 @@ bool Music::OpenFromMemory(const char* Data, std::size_t SizeInBytes)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool Music::OnStart()
|
bool Music::OnStart()
|
||||||
{
|
{
|
||||||
return myFile->Restart();
|
return myFile && myFile->Restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -117,12 +126,19 @@ bool Music::OnStart()
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool Music::OnGetData(SoundStream::Chunk& Data)
|
bool Music::OnGetData(SoundStream::Chunk& Data)
|
||||||
{
|
{
|
||||||
|
if (myFile)
|
||||||
|
{
|
||||||
// Fill the chunk parameters
|
// Fill the chunk parameters
|
||||||
Data.Samples = &mySamples[0];
|
Data.Samples = &mySamples[0];
|
||||||
Data.NbSamples = myFile->Read(&mySamples[0], mySamples.size());
|
Data.NbSamples = myFile->Read(&mySamples[0], mySamples.size());
|
||||||
|
|
||||||
// Check if we have reached the end of the audio file
|
// Check if we have reached the end of the audio file
|
||||||
return Data.NbSamples == mySamples.size();
|
return Data.NbSamples == mySamples.size();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user