SVN_SILENT made messages (.desktop file)
[kdegames.git] / kbattleship / src / audioplayer.cpp
blobf890115fba3250687ecd2abceb295384c6e51bcd
1 /*
2 Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 */
10 #include "audioplayer.h"
12 #include <Phonon/MediaObject>
13 #include <KStandardDirs>
15 AudioPlayer::AudioPlayer(QObject* parent)
16 : QObject(parent)
17 , m_media(0)
19 m_dir = KStandardDirs::locate("appdata", "sounds/");
22 void AudioPlayer::play(Sea::Player player, const HitInfo& info)
24 if (m_media) {
25 QString sound;
26 if (info.type == HitInfo::HIT) {
27 if (info.shipDestroyed) {
28 sound = "ship-sink.ogg";
30 else {
31 sound = player == Sea::PLAYER_A ?
32 "ship-player1-shoot.ogg" :
33 "ship-player2-shoot.ogg";
36 else {
37 sound = "ship-player-shoot-water.ogg";
40 if (!sound.isEmpty()) {
41 kDebug() << "****** playing" << m_dir.filePath(sound);
42 m_media->setCurrentSource(m_dir.filePath(sound));
43 m_media->play();
48 void AudioPlayer::setActive(bool value)
50 if (value) {
51 if (!m_media) {
52 m_media = Phonon::createPlayer(Phonon::GameCategory);
55 else {
56 delete m_media;
57 m_media = 0;
62 #include "audioplayer.moc"