void UBGraphicsAudioItemDelegate::togglePlayPause() { if ( mDelegated && mDelegated->mediaObject() ) { Phonon::MediaObject* media = mDelegated->mediaObject(); if ( media->state() == Phonon::StoppedState ) { media->play(); } else if ( media->state() == Phonon::PlayingState ) { if ( media->remainingTime() <= 0 ) { media->stop(); media->play(); } else { media->pause(); if ( mDelegated->scene() ) mDelegated->scene()->setModified ( true ); } } else if ( media->state() == Phonon::PausedState ) { if ( media->remainingTime() <= 0 ) { media->stop(); } media->play(); } else if ( media->state() == Phonon::LoadingState ) { mDelegated->mediaObject()->setCurrentSource(mDelegated->mediaFileUrl()); media->play(); } else if (media->state() == Phonon::ErrorState){ qDebug() << "Error appeared." << media->errorString(); } } }
void PlayerManager::slotStateChanged(Phonon::State newstate, Phonon::State oldstate) { // Use sender() since either media object may have sent the signal. Phonon::MediaObject *mediaObject = qobject_cast<Phonon::MediaObject *>(sender()); if(!mediaObject) return; // Handle errors for either media object if(newstate == Phonon::ErrorState) { QString errorMessage = i18nc( "%1 will be the /path/to/file, %2 will be some string from Phonon describing the error", "JuK is unable to play the audio file<nl/><filename>%1</filename><nl/>" "for the following reason:<nl/><message>%2</message>", m_file.absFilePath(), mediaObject->errorString() ); switch(mediaObject->errorType()) { case Phonon::NoError: kDebug() << "received a state change to ErrorState but errorType is NoError!?"; break; case Phonon::NormalError: forward(); KMessageBox::information(0, errorMessage); break; case Phonon::FatalError: stop(); KMessageBox::sorry(0, errorMessage); break; } } // Now bail out if we're not dealing with the currently playing media // object. if(mediaObject != m_media[m_curOutputPath]) return; // Handle state changes for the playing media object. if(newstate == Phonon::StoppedState && oldstate != Phonon::LoadingState) { // If this occurs it should be due to a transitory shift (i.e. playing a different // song when one is playing now), since it didn't occur in the error handler. Just // in case we really did abruptly stop, handle that case in a couple of seconds. QTimer::singleShot(2000, this, SLOT(slotUpdateGuiIfStopped())); JuK::JuKInstance()->setWindowTitle(i18n("JuK")); emit signalStop(); } else if(newstate == Phonon::PausedState) { emit signalPause(); } else { // PlayingState or BufferingState action("pause")->setEnabled(true); action("stop")->setEnabled(true); action("forward")->setEnabled(true); if(action<KToggleAction>("albumRandomPlay")->isChecked()) action("forwardAlbum")->setEnabled(true); action("back")->setEnabled(true); JuK::JuKInstance()->setWindowTitle(i18nc( "%1 is the artist and %2 is the title of the currently playing track.", "%1 - %2 :: JuK", m_file.tag()->artist(), m_file.tag()->title())); emit signalPlay(); } }