QVariantMap TrackListDBusHandler::GetMetadata(int position)
{
    QVariantMap ret;
    if (position < 0 || position > m_tracks.size()-1) {
        return ret;
    }

    //FIXME: ugly and slow
    Phonon::MediaObject mediaObject;
    mediaObject.setCurrentSource(m_tracks[position]);

    QMultiMap<QString, QString> stringMap = mediaObject.metaData();
    QMultiMap<QString, QString>::const_iterator i = stringMap.constBegin();

    while (i != stringMap.constEnd()) {
        bool number = false;
        int value = i.value().toInt(&number);

        //tracknumber always string, according to MPRIS spec
        if (number && (i.key().toLower() != "tracknumber")) {
            ret[i.key().toLower()] = value;
        } else {
            ret[i.key().toLower()] = QVariant(i.value());
        }
        ++i;
    }

    ret["time"] = mediaObject.totalTime()/1000;

    ret["location"] = mediaObject.currentSource().url().toString();
    return ret;
}
示例#2
0
void APlayer::setDir(QString path)
{
	old = 0;
	m_media->clear();
	w_folderContents->clear();
	while (QTreeWidgetItem *item = w_folderContents->takeTopLevelItem(0))
	{
		delete item;
	}
	path += "/";
	QDir dir(path);
	QStringList files = dir.entryList(QStringList() << "*.mp3" << "*.ogg" << "*.wav" << "*.wma",
									  QDir::Files | QDir::NoDotAndDotDot,
									  QDir::Name);
	QString f = path + "%2";
	Phonon::MediaObject media;
	foreach (QString file, files)
	{
		QString filepath = f.arg(file);
		media.setCurrentSource(filepath);
		QMap <QString,QString> metaData = media.metaData();
		QStringList metaList;
		metaList << metaData.value("ARTIST")
				 << metaData.value("TITLE")
				 << metaData.value("ALBUM")
				 << metaData.value("DATE");
		qDebug() << metaList;
		if (metaList[0].isEmpty())
			metaList[0] = file;
		QTreeWidgetItem *item = new QTreeWidgetItem(metaList);
		item->setData(0, Qt::UserRole, filepath);
		w_folderContents->addTopLevelItem(item);
	}
int main(int argv, char **args)
{
    QApplication app(argv, args);
    app.setApplicationName("Audio effect tester");

    Phonon::MediaObject *mediaObject = new Phonon::MediaObject;
    mediaObject->setCurrentSource(QString("/home/gvatteka/Music/Lumme-Badloop.ogg"));

    Phonon::AudioOutput *audioOutput =
        new Phonon::AudioOutput(Phonon::MusicCategory);

//! [0]
    QList<Phonon::EffectDescription> effectDescriptions =
            Phonon::BackendCapabilities::availableAudioEffects();
    Phonon::EffectDescription effectDescription = effectDescriptions.at(4);

    Phonon::Path path = Phonon::createPath(mediaObject, audioOutput);

//! [1]
    Phonon::Effect *effect = new Phonon::Effect(effectDescription);
    path.insertEffect(effect);
//! [0]

    Phonon::EffectWidget *effectWidget = new Phonon::EffectWidget(effect);
    effectWidget->show();
//! [1]

    mediaObject->play();

    effectWidget->setWindowTitle("Effect Name: " + effectDescription.name());

    app.exec();
}
void UBGraphicsVideoItemDelegate::updateTicker(qint64 time)
{
    Phonon::MediaObject* media = delegated()->mediaObject();
    mVideoControl->totalTimeChanged(media->totalTime());

    mVideoControl->updateTicker(time);
}
示例#5
0
void AudioOutputPrivate::playInstructions()
{
    setupAudio();
    if ( m_output ) {
        m_output->enqueue( QUrl::fromLocalFile( m_voiceNavigation.instruction() ) );
        m_output->play();
    }
}
void UBGraphicsVideoItemDelegate::updatePlayPauseState()
{
    Phonon::MediaObject* media = delegated()->mediaObject();

    if (media->state() == Phonon::PlayingState)
        mPlayPauseButton->setFileName(":/images/pause.svg");
    else
        mPlayPauseButton->setFileName(":/images/play.svg");
}
示例#7
0
void AudioOutputPrivate::reset()
{
    if ( m_output ) {
        m_output->stop();
        m_output->setCurrentSource( Phonon::MediaSource() );
        m_output->clearQueue();
    }

    m_voiceNavigation.reset();
}
示例#8
0
文件: playermanager.cpp 项目: KDE/juk
void PlayerManager::seekBack()
{
    Phonon::MediaObject *mediaObject = m_media[m_curOutputPath];
    const qint64 total = mediaObject->totalTime();
    const qint64 newtime = mediaObject->currentTime() - total / 100;
    const qint64 seekTo = qMax(qint64(0), newtime);

    stopCrossfade();
    mediaObject->seek(seekTo);
    emit seeked(seekTo);
}
示例#9
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    qDebug() << Phonon::BackendCapabilities::availableMimeTypes();
    Phonon::MediaObject *music = Phonon::createPlayer(Phonon::MusicCategory,
                            Phonon::MediaSource("../myPhonon1/mysong.mp3"));
    music->setParent(this);
    music->play();
}
示例#10
0
 void VideoWidget::stop()
 {
     Phonon::MediaObject* mo = player->media0bject();
     if (mo->state() == Phonon::PausedState)
     {
         mo->seek(0);
         mo->stop();
     }
     else
     {
         mo->stop();
     }
 }
示例#11
0
void SoundEditWidget::playSound()
{
    if (!mHasSound) {
        return;
    }
    Phonon::MediaObject *player = Phonon::createPlayer(Phonon::NotificationCategory);
    QBuffer *soundData = new QBuffer(player);
    soundData->setData(mSound);
    player->setCurrentSource(soundData);
    player->setParent(this);
    connect(player, &Phonon::MediaObject::finished, player, &Phonon::MediaObject::deleteLater);
    player->play();
}
示例#12
0
void SoundEditWidget::playSound()
{
  if ( !mHasSound ) {
    return;
  }

#ifndef Q_OS_WINCE
  Phonon::MediaObject* player = Phonon::createPlayer( Phonon::NotificationCategory );
  QBuffer* soundData = new QBuffer( player );
  soundData->setData( mSound );
  player->setCurrentSource( soundData );
  player->setParent( this );
  connect( player, SIGNAL(finished()), player, SLOT(deleteLater()) );
  player->play();
#endif
}
示例#13
0
void FindSubtitles::findSubtitles() {
	Phonon::MediaObject * mediaObject = quarkPlayer().currentMediaObject();
	if (mediaObject) {
		Phonon::MediaSource source = mediaObject->currentSource();
		QString fileName(source.fileName());

		static FindSubtitlesWindow * findSubtitlesWindow = NULL;
		if (!findSubtitlesWindow) {
			findSubtitlesWindow = new FindSubtitlesWindow(MainWindowFactory::mainWindow());
			connect(findSubtitlesWindow, SIGNAL(subtitleDownloaded(const QString &)),
				SLOT(loadSubtitle(const QString &)));
		}
		findSubtitlesWindow->setMovieFileName(fileName);
		findSubtitlesWindow->setLanguage(Config::instance().language());
		findSubtitlesWindow->show();
	}
}
void AudioPlayer::playSoundStr(const QString &file) {
	if (aboutToTerminate)
		return;

	for (std::vector<Phonon::MediaObject *>::iterator iter = soundVec.begin();
			iter != soundVec.end(); ++iter) {
		Phonon::MediaObject * prevSoundEffect = (*iter);
		switch (prevSoundEffect->state()) {
		case Phonon::StoppedState:
		case Phonon::PausedState:
			prevSoundEffect->clear();
			prevSoundEffect->setCurrentSource(file);
			prevSoundEffect->play();
			return;
		default:
			break;
		}
	}

	Phonon::MediaObject * soundEffect = Phonon::createPlayer(
			Phonon::MusicCategory, file);
	soundEffect->play();
	soundVec.push_back(soundEffect);
	printDebug(
			"<font color=red><b>Notice: </b></font>AudioPlayer::playSoundStr: creating new MediaObject, current MediaObject count = "
					+ QString::number(static_cast<unsigned>(soundVec.size())));
	return;
}
示例#15
0
void Video::getVideoInformation()
{
    QFileInfo fileInfo(videoPath);
    videoName = fileInfo.fileName();

    Phonon::MediaObject mediaObject;
    mediaObject.setCurrentSource(videoPath);
    // TODO: This doesn't work. Media needs to be loaded
    qint64 totalMs = mediaObject.totalTime();
    qint64 totSeconds = totalMs / 1000;
    qint64 seconds = totSeconds % 60;
    qint64 totMinutes = totSeconds / 60;
    qint64 minutes = totMinutes % 60;
    qint64 hours = totMinutes / 60;

    videoTotalTime = QTime(hours, minutes, seconds);
    qDebug() << videoTotalTime;
}
示例#16
0
game::MainWindow::MainWindow(QWidget *parent) :
    QWidget(parent),
    m_width(1000),
    m_height(800),
    m_status(false),
    m_frame_count(0),
    m_i(0),
    m_j(0),
    m_next_cell(0),
    m_clock_frame_count(0),
    m_anim_end(false),
    m_clock_start(false),
    m_clock_x_cord(0),
    m_animation_state(false)
{    
    QImage image(".\\res\\back_3.png");
    m_game_width = image.width();
    m_game_height = image.height();
    setFixedSize(m_width, m_height);
    m_click_coords.first = 0;
    m_click_coords.second = 0;
    setWindowFlags( Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint);
    m_area_x0_coordinate = (this->width() - image.width())/2;
    m_area_y0_coordinate = (this->height() - image.height())/2;
    m_r = new game::graphic_engine::game_process(m_area_x0_coordinate, m_area_y0_coordinate, image.width()/*+30*/, image.height()/*+30*/, 57);    
    Phonon::MediaObject* mediaobject = new Phonon::MediaObject(this);
    Phonon::AudioOutput *audio = new Phonon::AudioOutput(this);
    assert(mediaobject != 0);  
    QString filename(".//res//music//Casino Ambiance Music.wav");
    mediaobject->setCurrentSource(filename);
    Phonon::createPath(mediaobject,audio);
    mediaobject->play();
    QPixmap pixmap(".\\res\\background.png");
    QPalette palette;    
    palette.setBrush(/*this->backgroundRole()*/QPalette::Background, QBrush(pixmap));
    this->setPalette(palette);
    m_timer = new QTimer(this);
    m_timer_clock = new QTimer(this);
    connect(m_timer, SIGNAL(timeout()), this, SLOT(animate()));
    connect(m_timer_clock, SIGNAL(timeout()), this, SLOT(animate_clock()));
    m_timer->start(5);
    m_timer_clock->start(60);
}
int main(int argv, char **args)
{
    QApplication app(argv, args);

//![0]
    Phonon::MediaObject *moo = new Phonon::MediaObject;;
    Phonon::AudioOutput *device = new Phonon::AudioOutput;
    Phonon::createPath(moo, device);
    moo->setCurrentSource(QString("/home/gvatteka/Music/Lumme-Badloop.ogg"));

    Phonon::SeekSlider *slider = new Phonon::SeekSlider;
    slider->setMediaObject(moo);

    slider->show();
    moo->play();
//![0]

    app.exec();
}
 bool isPlaying() const
 {
     switch (mMediaObject->state()) {
     case Phonon::StoppedState:
     case Phonon::PausedState:
         return false;
     default:
         return true;
     }
 }
示例#19
0
void TrackAudioWidget::playClicked(int source_id)
{
    std::cerr<<"TrackAudioWidget::playClicked with source_id : "<<source_id<<std::endl;

#ifdef _HAVE_PHONON_
	Phonon::MediaObject *music =
	Phonon::createPlayer(Phonon::MusicCategory,
						 Phonon::MediaSource(QString("log/source_") + QString::number(source_id) + QString(".wav")));
	music->play();

#else

						 
	QProcess *process = new QProcess(this);
	QString prog;
	QStringList args;						 
						 
 #ifdef WIN32
    prog = QString("sndrec32.exe");
    args += QString("/play");
    args += QString("/close");
    args += QString("log/source_")+QString::number(source_id) + QString(".wav");
 #endif
    
#ifdef linux
    prog = QString("mplayer");
    args += QString("log/source_")+QString::number(source_id) + QString(".wav");
#endif
    
#ifdef __APPLE_CC__
    prog = QString("open");
    args += QString("log/source_")+QString::number(source_id) + QString(".wav");
#endif
    
    if (process)
    {        
        process->start(prog,args);                
    }
						 
#endif
 
}
示例#20
0
/*#
void LayerSound::playSound(int frame) {
	for(int i=0; i < sound.size(); i++) {
		if (frame == framesPosition.at(i)) {
			if (sound.at(i) != NULL && visible) sound[i]->play();
		}
	}
}
#*/
void LayerSound::playSound(int frame,int fps)
{
    //QSettings settings("Pencil","Pencil");
    //int fps = settings.value("fps").toInt();

    for (int i = 0; i < sound.size(); ++i)
    {
        Phonon::MediaObject* media = sound.at(i);
        if (media != NULL && visible)
        {
            int position = framesPosition.at(i);
            if (frame < position)
            {
                media->stop();
            }
            else
            {
                Phonon::AudioOutput* audioOutput = NULL;
                if (outputDevices.size() <= i)
                {
                    audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
                    outputDevices.push_back(audioOutput);
                }
                else
                {
                    audioOutput = outputDevices.at(i);
                }

                int offsetInMs = floor((frame - position) * float(1000) / fps);
                if (media->state() == Phonon::PlayingState)
                {
                    if (fabs((float)media->currentTime() - offsetInMs) > 500.0f)
                        media->seek(offsetInMs);
                }
                else
                {
                    if (frame > position)
                    {
                        media->pause();
                        media->seek(offsetInMs);
                    }
                    if (offsetInMs < soundSize[i])
                    {
                        Phonon::createPath(media, outputDevices.at(i));
                        media->play();
                    }
                }
            }
        }
    }
}
int main(int argv, char **args)
{
    QApplication app(argv, args);
    app.setApplicationName("Volume slider tester");

    Phonon::MediaObject *mediaObject = new Phonon::MediaObject;
    mediaObject->setCurrentSource(QString("/home/gvatteka/Music/Lumme-Badloop.ogg"));

//! [0]
    Phonon::AudioOutput *audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory);
    Phonon::createPath(mediaObject, audioOutput);

    Phonon::VolumeSlider *volumeSlider = new Phonon::VolumeSlider;
    volumeSlider->setAudioOutput(audioOutput);
//! [0]

    mediaObject->play();
    
    volumeSlider->show();

    return app.exec();
}
示例#22
0
文件: main.cpp 项目: admiral0/flush
int main(int argc, char** argv)
{
    QCoreApplication app(argc, argv);
    app.setApplicationName("Flush");
    QStringList args=app.arguments();
    args.removeFirst();
    QString appl=args.at(0);
    args.removeFirst();
    QProcess p;
    p.setProcessChannelMode(QProcess::ForwardedChannels);
    p.start(appl,args);
    p.waitForFinished(-1);
    Phonon::MediaObject *mediaObject = new Phonon::MediaObject();
    Phonon::AudioOutput *audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory);
    Phonon::createPath(mediaObject, audioOutput);
    if(p.exitCode()==0)
      mediaObject->setCurrentSource(Phonon::MediaSource(":/flush.ogg"));
    else
      mediaObject->setCurrentSource(Phonon::MediaSource(":/sadtrombone.ogg"));
    mediaObject->play();
    QObject::connect(mediaObject,SIGNAL(finished()),&app,SLOT(quit()));
    return app.exec();
}
示例#23
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    Phonon::MediaObject *mediaObject = new Phonon::MediaObject(this);
    mediaObject->setCurrentSource(Phonon::MediaSource("../myPhonon1/mysong.mp3"));
    Phonon::AudioOutput *audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
    Phonon::Path path = Phonon::createPath(mediaObject, audioOutput);
    mediaObject->play();

    // 获取可用的音频效果的描述
    QList<Phonon::EffectDescription> effectDescriptions =
                Phonon::BackendCapabilities::availableAudioEffects();
    qDebug() << effectDescriptions;
    Phonon::EffectDescription effectDescription = effectDescriptions.at(5);
    // 使用指定的音频效果的描述来创建音频效果
    Phonon::Effect *effect = new Phonon::Effect(effectDescription);
    // 在路径中插入音频效果
    path.insertEffect(effect);
    // 创建效果部件,它可以用来更改效果中的参数
    Phonon::EffectWidget *effectWidget = new Phonon::EffectWidget(effect);
    effectWidget->show();
}
示例#24
0
void LayerSound::loadSoundAtFrame(QString filePathString, int frameNumber)
{
//	if (getIndexAtFrame(frameNumber) == -1) addImageAtFrame(frameNumber);
    int index = getIndexAtFrame(frameNumber);
    if (index == -1)
        addImageAtFrame(frameNumber);
    index = getIndexAtFrame(frameNumber);

    QFileInfo fi(filePathString);
    if (fi.exists())
    {
//		sound[index] = new QSound(filePathString, NULL);
        Phonon::MediaObject* media = new Phonon::MediaObject();
        connect(media, SIGNAL(totalTimeChanged(qint64)), this, SLOT(addTimelineKey(qint64)));
        media->setCurrentSource(filePathString);
        // quick and dirty trick to calculate soundSize
        // totalTime() return a value only after a call to media.play()
        //  ( and when signal totaltimechanged is emitted totalTime() returns the correct value )
        Phonon::AudioOutput* audioOutput;
        audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
        Phonon::createPath(media, audioOutput);
        media->play();
        media->stop();
        soundSize[index] = media->totalTime(); // totalTime() returns 0 now
        sound[index] = media;
        soundFilepath[index] = filePathString;
        framesFilename[index] = fi.fileName();
        framesModified[index] = true;
    }
    else
    {
        sound[index] = NULL;
        soundFilepath[index] = "Wrong file";
        framesFilename[index] = "Wrong file" + filePathString;
    }
}
示例#25
0
Window::Window()
{
    {
//![0]
    Phonon::MediaObject *music =
        Phonon::createPlayer(Phonon::MusicCategory,
                             Phonon::MediaSource("/path/mysong.wav"));
    music->play();
//![0]
    }

    {
    QWidget *parentWidget = new QWidget;
    QUrl url("Myfancymusic");
//![1]
    Phonon::VideoPlayer *player =
        new Phonon::VideoPlayer(Phonon::VideoCategory, parentWidget);
    player->play(url);
//![1]
    }

    {
//![2]
    Phonon::MediaObject *mediaObject = new Phonon::MediaObject(this);
    mediaObject->setCurrentSource(Phonon::MediaSource("/mymusic/barbiegirl.wav"));
    Phonon::AudioOutput *audioOutput =
        new Phonon::AudioOutput(Phonon::MusicCategory, this);
    Phonon::Path path = Phonon::createPath(mediaObject, audioOutput);
//![2]
    
//![3]
    Phonon::Effect *effect =
        new Phonon::Effect(
            Phonon::BackendCapabilities::availableAudioEffects()[0], this);
    path.insertEffect(effect);
//![3]    
    }

    {
//![4]
    Phonon::MediaObject *mediaObject = new Phonon::MediaObject(this);

    Phonon::VideoWidget *videoWidget = new Phonon::VideoWidget(this);
    Phonon::createPath(mediaObject, videoWidget);

    Phonon::AudioOutput *audioOutput =
        new Phonon::AudioOutput(Phonon::VideoCategory, this);
    Phonon::createPath(mediaObject, audioOutput);
//![4]
//![5]
    mediaObject->play();
//![5]
    }
}
示例#26
0
文件: playermanager.cpp 项目: KDE/juk
void PlayerManager::play(const FileHandle &file)
{
    if(!m_setup)
        setup();

    if(!m_media[0] || !m_media[1] || !m_playlistInterface)
        return;

    stopCrossfade();

    // The "currently playing" media object.
    Phonon::MediaObject *mediaObject = m_media[m_curOutputPath];
    
    if(file.isNull()) {
        if(paused())
            mediaObject->play();
        else if(playing()) {
            mediaObject->seek(0);
            emit seeked(0);
        }
        else {
            m_playlistInterface->playNext();
            m_file = m_playlistInterface->currentFile();

            if(!m_file.isNull())
            {
                mediaObject->setCurrentSource(KUrl::fromPath(m_file.absFilePath()));
                mediaObject->play();

                emit signalItemChanged(m_file);
            }
        }
    }
    else {
        mediaObject->setCurrentSource(KUrl::fromPath(file.absFilePath()));
        mediaObject->play();

        if(m_file != file)
            emit signalItemChanged(file);

        m_file = file;
    }

    // Our state changed handler will perform the follow up actions necessary
    // once we actually start playing.
}
void AlarmDialog::eventNotification()
{
  bool beeped = false;
  bool found = false;

  ReminderList list;

  QTreeWidgetItemIterator it( mIncidenceTree );
  while ( *it ) {
    ReminderListItem *item = static_cast<ReminderListItem *>( *it );
    ++it;
    if ( item->isDisabled() || item->mNotified ) {
      //skip suspended reminders or reminders that have been notified
      continue;
    }
    found = true;
    item->mNotified = true;
    Incidence::Ptr incidence = CalendarSupport::incidence( item->mIncidence );
    Alarm::List alarms = incidence->alarms();
    Alarm::List::ConstIterator ait;
    for ( ait = alarms.constBegin(); ait != alarms.constEnd(); ++ait ) {
      Alarm::Ptr alarm = *ait;
      // FIXME: Check whether this should be done for all multiple alarms
      if ( alarm->type() == Alarm::Procedure ) {
        // FIXME: Add a message box asking whether the procedure should really be executed
        kDebug() << "Starting program: '" << alarm->programFile() << "'";

        QString program = alarm->programFile();

        // if the program name contains spaces escape it
        if ( program.contains( ' ' )   &&
             !( program.startsWith( '\"' ) && program.endsWith( '\"' ) ) ) {
          program = '\"' + program + '\"';
        }

        QProcess::startDetached( program + ' ' + alarm->programArguments() );
      } else if ( alarm->type() == Alarm::Audio ) {
        beeped = true;
        Phonon::MediaObject *player =
          Phonon::createPlayer( Phonon::NotificationCategory, alarm->audioFile() );
        player->setParent( this );
        connect( player, SIGNAL(finished()), player, SLOT(deleteLater()) );
        player->play();
      } else if ( alarm->type() == Alarm::Email ) {
        QString from = CalendarSupport::KCalPrefs::instance()->email();
        Identity id = KOCore::self()->identityManager()->identityForAddress( from );
        QString to;
        if ( alarm->mailAddresses().isEmpty() ) {
          to = from;
        } else {
          const Person::List addresses = alarm->mailAddresses();
          QStringList add;
          for ( Person::List::ConstIterator it = addresses.constBegin();
                it != addresses.constEnd(); ++it ) {
            add << (*it)->fullName();
          }
          to = add.join( ", " );
        }

        QString subject;

        Akonadi::Item parentItem = mCalendar->itemForIncidenceUid( alarm->parentUid() );
        Incidence::Ptr parent = CalendarSupport::incidence( parentItem );

        if ( alarm->mailSubject().isEmpty() ) {
          if ( parent->summary().isEmpty() ) {
            subject = i18nc( "@title", "Reminder" );
          } else {
            subject = i18nc( "@title", "Reminder: %1", cleanSummary( parent->summary() ) );
          }
        } else {
          subject = i18nc( "@title", "Reminder: %1", alarm->mailSubject() );
        }

        QString body =
          IncidenceFormatter::mailBodyStr(
            parent.staticCast<IncidenceBase>(), KSystemTimeZones::local() );
        if ( !alarm->mailText().isEmpty() ) {
          body += '\n' + alarm->mailText();
        }
        //TODO: support attachments
        CalendarSupport::MailClient mailer;
        mailer.send( id, from, to, QString(), subject, body, true, false, QString(),
                     MailTransport::TransportManager::self()->defaultTransportName() );
      }
    }
  }

  if ( !beeped && found ) {
    KNotification::beep();
  }
}
示例#28
0
文件: playermanager.cpp 项目: KDE/juk
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();
    }
}
示例#29
0
void AudioOutputPrivate::audioOutputFinished()
{
    m_output->setCurrentSource( Phonon::MediaSource() );
    m_output->clearQueue();
}
void UBGraphicsVideoItemDelegate::togglePlayPause()
{
    if (delegated() && delegated()->mediaObject())
    {
        Phonon::MediaObject* media = delegated()->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(delegated()->scene())
                        delegated()->scene()->setModified(true);
            }
        }
        else if (media->state() == Phonon::PausedState)
        {
            if (media->remainingTime() <= 0)
            {
                media->stop();
            }

            media->play();
        }
		else  if ( media->state() == Phonon::LoadingState ){
            delegated()->mediaObject()->setCurrentSource(delegated()->mediaFileUrl());
            media->play();
        }
        else{
          qDebug() << "Media state "<< media->state() << " not supported";
        }
    }
}