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; }
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; }
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 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); }
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 AudioOutputPrivate::reset() { if ( m_output ) { m_output->stop(); m_output->setCurrentSource( Phonon::MediaSource() ); m_output->clearQueue(); } m_voiceNavigation.reset(); }
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] } }
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(); }
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(); }
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 }
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; }
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(); }
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); 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(); }
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; } }
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(); }
void AudioOutputPrivate::audioOutputFinished() { m_output->setCurrentSource( Phonon::MediaSource() ); m_output->clearQueue(); }