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; }
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(); } } }
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] } }
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 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::playInstructions() { setupAudio(); if ( m_output ) { m_output->enqueue( QUrl::fromLocalFile( m_voiceNavigation.instruction() ) ); m_output->play(); } }
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"; } } }
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(); }
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(); }
/*# 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(); } } } } } }
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 }
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(); }
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 }
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(); }
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(); }
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 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; } }
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(); } }