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

View file

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