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 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";
        }
    }
}