From: Steve Brokenshire Date: Sun, 12 Feb 2017 23:19:57 +0000 (+0000) Subject: frmContactEditor: Audio device closes on window close X-Git-Tag: release-0.18~29 X-Git-Url: http://Server1/repobrowser/?a=commitdiff_plain;h=202a753a3225784909977a63022e0f64672e97e6;p=xestiaab%2F.git frmContactEditor: Audio device closes on window close Audio device is closed when frmContactEditor is closed. --- diff --git a/source/contacteditor/frmContactEditor-Sound.cpp b/source/contacteditor/frmContactEditor-Sound.cpp index ba1a0c9..7d9fcde 100644 --- a/source/contacteditor/frmContactEditor-Sound.cpp +++ b/source/contacteditor/frmContactEditor-Sound.cpp @@ -17,10 +17,6 @@ // with Xestia Address Book. If not, see #include "frmContactEditor.h" -#include "frmContactEditorSound.h" -#include "../common/base64.h" -#include -#include void frmContactEditor::AddSound( wxCommandEvent& event ) { @@ -107,7 +103,7 @@ void frmContactEditor::PlaySoundDetach() // Play the sound and detach. - if (!AudioStreamPlayback.openFromMemory(base64dec.c_str(), base64declen)){ + if (!AudioStreamPlaybackPointer->openFromMemory(base64dec.c_str(), base64declen)){ // Can't load file. We must flee... // Also show an error message too. @@ -120,17 +116,18 @@ void frmContactEditor::PlaySoundDetach() btnStop->Enable(); - AudioStreamPlayback.play(); + AudioStreamPlaybackPointer->play(); - while (AudioStreamPlayback.getStatus() == sf::SoundSource::Playing){ + while (AudioStreamPlaybackPointer->getStatus() == sf::SoundSource::Playing){ // We poll this every 100ms in order to conserve CPU usage. - SleepFor(100000000); + SleepFor(10000000); } - + btnStop->Disable(); + btnPlay->Enable(); } @@ -142,11 +139,17 @@ void frmContactEditor::PlaySound( wxCommandEvent& event ) long longSelected = -1; int intSelectedData = 0; + if (AudioStreamPlaybackPointer == nullptr){ + + AudioStreamPlaybackPointer = new AudioStream; + + } + // Check if sound is still being played and if it is, stop it. - if (AudioStreamPlayback.getStatus() == sf::SoundSource::Playing){ + if (AudioStreamPlaybackPointer->getStatus() == sf::SoundSource::Playing){ - AudioStreamPlayback.stop(); + AudioStreamPlaybackPointer->stop(); } @@ -155,7 +158,9 @@ void frmContactEditor::PlaySound( wxCommandEvent& event ) &intSelectedData)){ return; } - + + btnPlay->Disable(); + std::map::iterator initier; initier = ContactEditorData.SoundsList.find(intSelectedData); @@ -174,14 +179,15 @@ void frmContactEditor::StopSound( wxCommandEvent& event ) { // Stop the sound. - - if (AudioStreamPlayback.getStatus() == sf::SoundSource::Playing){ - - AudioStreamPlayback.stop(); + + if (AudioStreamPlaybackPointer != nullptr && AudioStreamPlaybackPointer->getStatus() == sf::SoundSource::Playing){ + AudioStreamPlaybackPointer->stop(); + } btnStop->Disable(); + btnPlay->Enable(); return; diff --git a/source/contacteditor/frmContactEditor.cpp b/source/contacteditor/frmContactEditor.cpp index b5ef96e..444b748 100644 --- a/source/contacteditor/frmContactEditor.cpp +++ b/source/contacteditor/frmContactEditor.cpp @@ -105,6 +105,19 @@ frmContactEditorADT( parent ) } +frmContactEditor::~frmContactEditor() +{ + + if (AudioStreamPlaybackPointer != nullptr) + { + + delete AudioStreamPlaybackPointer; + AudioStreamPlaybackPointer = nullptr; + + } + +} + void frmContactEditor::CloseContact( wxCommandEvent& event ) { diff --git a/source/contacteditor/frmContactEditor.h b/source/contacteditor/frmContactEditor.h index fabe5cb..49dd826 100644 --- a/source/contacteditor/frmContactEditor.h +++ b/source/contacteditor/frmContactEditor.h @@ -39,6 +39,7 @@ Subclass of frmContactEditorADT, which is generated by wxFormBuilder. #include "../actmgr/frmActivityMgr.h" #include "../frmMain.h" +#include "frmContactEditorSound.h" #include "cdo/ContactDataObject.h" @@ -311,6 +312,7 @@ class frmContactEditor : public frmContactEditorADT public: /** Constructor */ frmContactEditor( wxWindow* parent ); + ~frmContactEditor(); void SetupHeaders(); void SetupContact(wxString AccountName); void SetupAccountData(bool UnsupportedAccount); @@ -751,9 +753,7 @@ class frmContactEditor : public frmContactEditorADT size_t base64declen; std::string base64dec; - sf::Music AudioPlayback; - AudioStream AudioStreamPlayback; - sf::SoundBuffer AudioBuffer; + AudioStream *AudioStreamPlaybackPointer = nullptr; wxBitmap PictureImage; wxBitmap LogoImage;