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 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 UBGraphicsVideoItemDelegate::updatePlayPauseState()
{
    Phonon::MediaObject* media = delegated()->mediaObject();

    if (media->state() == Phonon::PlayingState)
        mPlayPauseButton->setFileName(":/images/pause.svg");
    else
        mPlayPauseButton->setFileName(":/images/play.svg");
}
 bool isPlaying() const
 {
     switch (mMediaObject->state()) {
     case Phonon::StoppedState:
     case Phonon::PausedState:
         return false;
     default:
         return true;
     }
 }
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";
        }
    }
}
Exemple #6
0
 void VideoWidget::stop()
 {
     Phonon::MediaObject* mo = player->media0bject();
     if (mo->state() == Phonon::PausedState)
     {
         mo->seek(0);
         mo->stop();
     }
     else
     {
         mo->stop();
     }
 }
Exemple #7
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();
                    }
                }
            }
        }
    }
}