| 1 | /* |
|---|
| 2 | * QuteCom, a voice over Internet phone |
|---|
| 3 | * Copyright (C) 2004-2006 Wengo |
|---|
| 4 | * |
|---|
| 5 | * This program is free software; you can redistribute it and/or modify |
|---|
| 6 | * it under the terms of the GNU General Public License as published by |
|---|
| 7 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 8 | * (at your option) any later version. |
|---|
| 9 | * |
|---|
| 10 | * This program is distributed in the hope that it will be useful, |
|---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | * GNU General Public License for more details. |
|---|
| 14 | * |
|---|
| 15 | * You should have received a copy of the GNU General Public License |
|---|
| 16 | * along with this program; if not, write to the Free Software |
|---|
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 18 | */ |
|---|
| 19 | |
|---|
| 20 | #include "SoundThread.h" |
|---|
| 21 | |
|---|
| 22 | #include "playsound/PlaySoundFile.h" |
|---|
| 23 | |
|---|
| 24 | #include <windows.h> |
|---|
| 25 | #include <process.h> |
|---|
| 26 | |
|---|
| 27 | SoundThread::SoundThread(const std::string & filename) { |
|---|
| 28 | _filename = filename; |
|---|
| 29 | _stop = false; |
|---|
| 30 | |
|---|
| 31 | //Plays the sound only one time by default |
|---|
| 32 | _loops = 1; |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | SoundThread::~SoundThread() { |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | bool SoundThread::setWaveOutDevice(const AudioDevice & device) { |
|---|
| 39 | _device = device; |
|---|
| 40 | return true; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | void SoundThread::setLoops(int loops) { |
|---|
| 44 | _loops = loops; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | void SoundThread::play() { |
|---|
| 48 | start(); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | void SoundThread::run() { |
|---|
| 52 | _soundFile.setWaveOutDevice(_device); |
|---|
| 53 | |
|---|
| 54 | int i = 0; |
|---|
| 55 | while ((i < _loops || _loops == -1) && !_stop) { |
|---|
| 56 | if (!_soundFile.play(_filename)) { |
|---|
| 57 | //If the file cannot be played, stop the thread |
|---|
| 58 | _stop = true; |
|---|
| 59 | } |
|---|
| 60 | i++; |
|---|
| 61 | } |
|---|
| 62 | _stop = false; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | void SoundThread::stop() { |
|---|
| 66 | _stop = true; |
|---|
| 67 | _soundFile.stop(); |
|---|
| 68 | } |
|---|