1 #include "frmContactEditor.h"
2 #include "frmContactEditorSound.h"
3 #include "../common/base64.h"
4 #include <SFML/Audio.hpp>
7 void frmContactEditor::AddSound( wxCommandEvent& event )
11 frmContactEditorSound *frameCESound = new frmContactEditorSound ( this );
12 frameCESound->SetEditorMode(FALSE);
13 intResult = GetLastInt(&SoundsList);
14 frameCESound->SetupPointers(&SoundsList,
19 &SoundsListAudioEncType,
25 frameCESound->ShowModal();
30 void frmContactEditor::ModifySound( wxCommandEvent& event )
32 long longSelected = -1;
33 int intSelectedData = 0;
35 if (!GetSelectedItem(lboSounds,
41 frmContactEditorSound *frameCESound = new frmContactEditorSound ( this );
42 frameCESound->SetupPointers(&SoundsList,
47 &SoundsListAudioEncType,
53 frameCESound->SetEditorMode(TRUE);
54 frameCESound->ShowModal();
59 void frmContactEditor::DeleteSound( wxCommandEvent& event )
61 long longSelected = -1;
62 int intSelectedData = 0;
64 if (!GetSelectedItem(lboSounds,
70 lboSounds->DeleteItem(longSelected);
72 DeleteMapData(intSelectedData, &SoundsList, &SoundsListAltID,
73 &SoundsListPID, &SoundsListType, &SoundsListAudioType,
74 &SoundsListAudioEncType, &SoundsListTokens, &SoundsListMediatype,
79 void frmContactEditor::PlaySoundDetach()
82 if (!AudioStreamPlayback.openFromMemory(base64dec.c_str(), base64declen)){
84 // Can't load file. We must flee...
85 // Also show an error message too.
87 wxMessageBox(_("This file is in an audio format that is unsupported or is not an audio file."), _("Error opening audio file"), wxICON_ERROR);
95 //AudioStreamPlayback.setbuffer(AudioBuffer);
96 AudioStreamPlayback.play();
101 n1.tv_nsec = 100000000L;*/
103 //while (TimeA != TimeB){
104 while (AudioStreamPlayback.getStatus() == sf::SoundSource::Playing){
106 // We poll this every 100ms in order to conserve CPU usage.
116 void frmContactEditor::PlaySound( wxCommandEvent& event )
119 //sf::Music *AudioPlayback = new sf::Music;
120 //AudioStream *AudioStreamPlayback = new AudioStream;
121 //sf::SoundBuffer *AudioBuffer = new sf::SoundBuffer;
123 //sf::Sound *AudioPlayback = new sf::Sound;
125 //delete(AudioPlayback);
127 //delete(AudioPlayback);
128 //delete(AudioStreamPlayback);
129 //delete(AudioBuffer);
131 //AudioPlayback = NULL;
132 //AudioStreamPlayback = NULL;
133 //AudioBuffer = NULL;
137 long longSelected = -1;
138 int intSelectedData = 0;
140 // Check if sound is still being played and if it is, stop it.
142 if (AudioStreamPlayback.getStatus() == sf::SoundSource::Playing){
144 AudioStreamPlayback.stop();
148 if (!GetSelectedItem(lboSounds,
154 std::map<int, std::string>::iterator initier;
156 initier = SoundsList.find(intSelectedData);
158 base64dec = base64_decode(initier->second);
159 base64declen = base64dec.size();
161 std::thread AudioPlaybackThread(&frmContactEditor::PlaySoundDetach, this);
162 AudioPlaybackThread.detach();
168 void frmContactEditor::StopSound( wxCommandEvent& event )
171 if (AudioStreamPlayback.getStatus() == sf::SoundSource::Playing){
173 AudioStreamPlayback.stop();