API and code changes to allowing stopping playback

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25464 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2004-02-02 00:49:39 +00:00
parent 98840d95db
commit 83f7f12df2
3 changed files with 245 additions and 69 deletions

View File

@@ -82,9 +82,12 @@ public:
int GetPriority() const { return 9; }
bool IsAvailable() const;
bool HasNativeAsyncPlayback() const { return true; }
bool Play(wxSoundData *data, unsigned flags);
bool Play(wxSoundData *data, unsigned flags,
volatile wxSoundPlaybackStatus *status);
void FillAudioBuffer(Uint8 *stream, int len);
void FinishedPlayback();
void Stop();
bool IsPlaying() const { return m_playing; }
@@ -113,7 +116,7 @@ private:
{
wxLogTrace(_T("sound"),
_T("received playback status change notification"));
m_backend->Stop();
m_backend->FinishedPlayback();
}
wxSoundBackendSDL *m_backend;
@@ -191,6 +194,12 @@ void wxSoundBackendSDL::FillAudioBuffer(Uint8 *stream, int len)
}
}
void wxSoundBackendSDL::FinishedPlayback()
{
if (!m_playing)
Stop();
}
bool wxSoundBackendSDL::OpenAudio()
{
if (!m_audioOpen)
@@ -236,7 +245,8 @@ void wxSoundBackendSDL::CloseAudio()
}
}
bool wxSoundBackendSDL::Play(wxSoundData *data, unsigned flags)
bool wxSoundBackendSDL::Play(wxSoundData *data, unsigned flags,
volatile wxSoundPlaybackStatus *WXUNUSED(status))
{
Stop();
@@ -273,6 +283,7 @@ bool wxSoundBackendSDL::Play(wxSoundData *data, unsigned flags)
}
SDL_LockAudio();
wxLogTrace(_T("sound"), _T("playing new sound"));
m_playing = true;
m_pos = 0;
m_loop = (flags & wxSOUND_LOOP);
@@ -286,7 +297,7 @@ bool wxSoundBackendSDL::Play(wxSoundData *data, unsigned flags)
if (!(flags & wxSOUND_ASYNC))
{
wxLogTrace(_T("sound"), _T("waiting for sample to finish"));
while (m_playing)
while (m_playing && m_data == data)
{
#if wxUSE_THREADS
// give the playback thread a chance to add event to pending