More complete error checking in new DSound player, shouldn't crash/die on errors now.

Originally committed to SVN as r2496.
This commit is contained in:
Niels Martin Hansen 2008-11-27 20:39:36 +00:00
parent a6c169a4b2
commit 735ce2385e
1 changed files with 124 additions and 26 deletions

View File

@ -623,7 +623,16 @@ DirectSoundPlayer2::~DirectSoundPlayer2()
void DirectSoundPlayer2::OpenStream()
{
if (thread) return;
try
{
thread = new DirectSoundPlayer2Thread(GetProvider());
}
catch (const wxChar *msg)
{
wxLogError(msg);
thread = 0;
}
}
@ -631,13 +640,22 @@ void DirectSoundPlayer2::CloseStream()
{
if (!thread) return;
try
{
delete thread;
}
catch (const wxChar *msg)
{
wxLogError(msg);
}
thread = 0;
}
void DirectSoundPlayer2::SetProvider(AudioProvider *provider)
{
try
{
if (thread && provider != GetProvider())
{
delete thread;
@ -645,78 +663,158 @@ void DirectSoundPlayer2::SetProvider(AudioProvider *provider)
}
AudioPlayer::SetProvider(provider);
}
catch (const wxChar *msg)
{
wxLogError(msg);
}
}
void DirectSoundPlayer2::Play(int64_t start,int64_t count)
{
try
{
OpenStream();
thread->Play(start, count);
if (displayTimer && !displayTimer->IsRunning()) displayTimer->Start(15);
}
catch (const wxChar *msg)
{
wxLogError(msg);
}
}
void DirectSoundPlayer2::Stop(bool timerToo)
{
try
{
if (thread) thread->Stop();
if (timerToo && displayTimer) {
displayTimer->Stop();
}
}
catch (const wxChar *msg)
{
wxLogError(msg);
}
}
bool DirectSoundPlayer2::IsPlaying()
{
try
{
if (!thread) return false;
return thread->IsPlaying();
}
catch (const wxChar *msg)
{
wxLogError(msg);
return false;
}
}
int64_t DirectSoundPlayer2::GetStartPosition()
{
try
{
if (!thread) return 0;
return thread->GetStartFrame();
}
catch (const wxChar *msg)
{
wxLogError(msg);
return 0;
}
}
int64_t DirectSoundPlayer2::GetEndPosition()
{
try
{
if (!thread) return 0;
return thread->GetEndFrame();
}
catch (const wxChar *msg)
{
wxLogError(msg);
return 0;
}
}
int64_t DirectSoundPlayer2::GetCurrentPosition()
{
try
{
if (!thread) return 0;
return thread->GetCurrentFrame();
}
catch (const wxChar *msg)
{
wxLogError(msg);
return 0;
}
}
void DirectSoundPlayer2::SetEndPosition(int64_t pos)
{
try
{
if (thread) thread->SetEndFrame(pos);
}
catch (const wxChar *msg)
{
wxLogError(msg);
}
}
void DirectSoundPlayer2::SetCurrentPosition(int64_t pos)
{
try
{
if (thread) thread->Play(pos, thread->GetEndFrame()-pos);
}
catch (const wxChar *msg)
{
wxLogError(msg);
}
}
void DirectSoundPlayer2::SetVolume(double vol)
{
try
{
if (thread) thread->SetVolume(vol);
}
catch (const wxChar *msg)
{
wxLogError(msg);
}
}
double DirectSoundPlayer2::GetVolume()
{
try
{
if (!thread) return 0;
return thread->GetVolume();
}
catch (const wxChar *msg)
{
wxLogError(msg);
return 0;
}
}