Ejemplo n.º 1
0
bool KNotify::notifyBySound(const QString &sound, const QString &appname, int eventId)
{
    if(sound.isEmpty())
    {
        soundFinished(eventId, NoSoundFile);
        return false;
    }

    bool external = d->useExternal && !d->externalPlayer.isEmpty();
    // get file name
    QString soundFile(sound);
    if(QFileInfo(sound).isRelative())
    {
        QString search = QString("%1/sounds/%2").arg(appname).arg(sound);
        soundFile = KGlobal::instance()->dirs()->findResource("data", search);
        if(soundFile.isEmpty())
            soundFile = locate("sound", sound);
    }
    if(soundFile.isEmpty())
    {
        soundFinished(eventId, NoSoundFile);
        return false;
    }

    // kdDebug() << "KNotify::notifyBySound - trying to play file " << soundFile << endl;

    if(!external)
    {
#ifdef WITH_PULSEAUDIO
        d->pulsePlayer.play(soundFile.utf8());
        return true;
#else
        soundFinished(eventId, NoSoundSupport);
        return false;
#endif
    }
    else if(!d->externalPlayer.isEmpty())
    {
        // use an external player to play the sound
        KProcess *proc = d->externalPlayerProc;
        if(!proc)
        {
            proc = d->externalPlayerProc = new KProcess;
            connect(proc, SIGNAL(processExited(KProcess *)), SLOT(slotPlayerProcessExited(KProcess *)));
        }
        if(proc->isRunning())
        {
            soundFinished(eventId, PlayerBusy);
            return false; // Skip
        }
        proc->clearArguments();
        (*proc) << d->externalPlayer << QFile::encodeName(soundFile);
        d->externalPlayerEventId = eventId;
        proc->start(KProcess::NotifyOnExit);
        return true;
    }

    soundFinished(eventId, Unknown);
    return false;
}
Ejemplo n.º 2
0
void SoundSource::Update(float timeStep)
{
    if (!audio_ || !IsEnabledEffective())
        return;

    // If there is no actual audio output, perform fake mixing into a nonexistent buffer to check stopping/looping
    if (!audio_->IsInitialized())
        MixNull(timeStep);

    // Free the stream if playback has stopped
    if (soundStream_ && !position_)
        StopLockless();
    bool playing = IsPlaying();

    if (!playing && sendFinishedEvent_)
    {
        sendFinishedEvent_ = false;

        // Make a weak pointer to self to check for destruction during event handling
        WeakPtr<SoundSource> self(this);

        soundFinished(node_,this,sound_);
        //TODO: verify same semantics as original : node_->SendEvent(E_SOUNDFINISHED, eventData);

        if (self.Expired())
            return;
        DoAutoRemove(autoRemove_);
    }
}
Ejemplo n.º 3
0
void KNotify::slotPlayerProcessExited(KProcess *proc)
{
    soundFinished(d->externalPlayerEventId, (proc->normalExit() && proc->exitStatus() == 0) ? PlayedOK : Unknown);
}