From 507f8b6ca5679c4898b721520dd4011f6b9e5824 Mon Sep 17 00:00:00 2001 From: manuel Date: Fri, 8 Apr 2011 15:18:38 +0200 Subject: make audioplayer useful --- pacman-c++/actor.cpp | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) (limited to 'pacman-c++/actor.cpp') diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp index 7358756..2b65528 100644 --- a/pacman-c++/actor.cpp +++ b/pacman-c++/actor.cpp @@ -1,8 +1,8 @@ #include "actor.h" #include "animationmanager.h" +#include "audioplayer.h" #include #include -#include #include static QVariant myBooleanInterpolator(const bool &start, const bool &end, qreal progress) @@ -47,15 +47,7 @@ Actor::Actor(Color::Color color, bool local, QGraphicsItem *parent) m_eating.append(setupEatingAnimation(Actor::Down)); /* setup player */ - m_player = new Phonon::MediaObject(this); - Phonon::AudioOutput *audio_output = new Phonon::AudioOutput(Phonon::MusicCategory, this); - Phonon::createPath(m_player, audio_output); - connect(m_player, SIGNAL(finished()), this, SLOT(enqueue())); - - /* preload sounds */ - m_sounds.append(new QFile(":/sound/wakawaka")); - m_sounds.append(new QFile(":/sound/die")); - m_sounds.append(new QFile(":/sound/eatingcherry")); + connect(AudioPlayer::self(), SIGNAL(finished()), this, SLOT(enqueue())); /* make the picture showing the current direction visible */ m_images[m_direction]->setVisible(true); @@ -114,11 +106,9 @@ void Actor::move(Actor::Movement direction) if (isMoving()) return; - if (m_local && m_player->state() != Phonon::PlayingState) + if (m_local && AudioPlayer::self()->state() != Phonon::PlayingState) { - m_player->stop(); - m_player->setCurrentSource(m_sounds[0]); - m_player->play(); + AudioPlayer::self()->play(AudioPlayer::WakaWaka); } /* stop current animation */ @@ -184,23 +174,19 @@ bool Actor::isMoving() void Actor::enqueue() { if (isMoving()) - m_player->enqueue(m_sounds[0]); + AudioPlayer::self()->enqueue(AudioPlayer::WakaWaka); } void Actor::die() { if (!m_local) return; - m_player->stop(); - m_player->setCurrentSource(m_sounds[1]); - m_player->play(); + AudioPlayer::self()->play(AudioPlayer::Die); } void Actor::eatingCherry() { if (!m_local) return; - m_player->stop(); - m_player->setCurrentSource(m_sounds[2]); - m_player->play(); + AudioPlayer::self()->play(AudioPlayer::EatingCherry); } -- cgit v1.2.3