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()
|
||||
{
|
||||
// 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();
|
||||
}
|
||||
|
||||
|
||||
@ -116,6 +125,8 @@ bool Music::OnStart()
|
||||
/// /see SoundStream::OnGetData
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Music::OnGetData(SoundStream::Chunk& Data)
|
||||
{
|
||||
if (myFile)
|
||||
{
|
||||
// Fill the chunk parameters
|
||||
Data.Samples = &mySamples[0];
|
||||
@ -124,6 +135,11 @@ bool Music::OnGetData(SoundStream::Chunk& Data)
|
||||
// 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