void VlcVideoWidget::Stop() 
{
    if (vlcPlayer_)
    {
        libvlc_state_t state = GetMediaState();
        if (state == libvlc_Playing || state == libvlc_Paused || state == libvlc_Ended)
        {
            /** @bug @todo These should not be here and is not actually doing anything. 
                Take a fresh look at the threading in this object and remove these hacks. */
            if (onScreenPixmapMutex_.tryLock(50))
                onScreenPixmapMutex_.unlock();
            if (renderPixmapMutex_.tryLock(50))
                renderPixmapMutex_.unlock();
            if (statusAccess.tryLock(50))
                statusAccess.unlock();

            libvlc_media_player_stop(vlcPlayer_);
        }
        update();
        ForceUpdateImage();
    }
}
Beispiel #2
0
EC_MediaPlayer::EC_MediaPlayer(Scene* scene) :
    IComponent(scene),
    mediaPlayer_(0),
    componentPrepared_(false),
    pendingMediaDownload_(false),
    sourceRef(this, "Media Source", AssetReference("", "")),
    renderSubmeshIndex(this, "Render Submesh", 0),
    interactive(this, "Interactive", false),
    illuminating(this, "Illuminating", true),
    streamingAllowed(this, "Streaming Allowed", true),
    enabled(this, "Enabled", true)
{
    if (!ViewEnabled() || GetFramework()->IsHeadless())
        return;

    // Set metadata min/max/step
    static AttributeMetadata submeshMetaData;
    static bool metadataInitialized = false;
    if (!metadataInitialized)
    {
        submeshMetaData.minimum = "0";
        submeshMetaData.step = "1";
        metadataInitialized = true;
    }
    renderSubmeshIndex.SetMetadata(&submeshMetaData);

    // Init our internal media player
    mediaPlayer_ = new VlcMediaPlayer();
    connect(mediaPlayer_, SIGNAL(FrameUpdate(QImage)), SLOT(OnFrameUpdate(QImage)), Qt::UniqueConnection);

    // Connect signals from IComponent
    connect(this, SIGNAL(ParentEntitySet()), SLOT(PrepareComponent()), Qt::UniqueConnection);

    // Connect window size changes to update rendering as the ogre textures go black.
    if (GetFramework()->Ui()->MainWindow())
        connect(GetFramework()->Ui()->MainWindow(), SIGNAL(WindowResizeEvent(int,int)), SLOT(RenderWindowResized()), Qt::UniqueConnection);

    resizeRenderTimer_ = new QTimer(this);
    resizeRenderTimer_->setSingleShot(true);
    connect(resizeRenderTimer_, SIGNAL(timeout()), mediaPlayer_, SLOT(ForceUpdateImage()), Qt::UniqueConnection);

    // Prepare scene interactions
    SceneInteract *sceneInteract = GetFramework()->GetModule<SceneInteract>();
    if (sceneInteract)
    {
        connect(sceneInteract, SIGNAL(EntityClicked(Entity*, Qt::MouseButton, RaycastResult*)), 
                SLOT(EntityClicked(Entity*, Qt::MouseButton, RaycastResult*)));
    }

    // Prepare media downloader
    mediaDownloader_ = new AssetRefListener();
    connect(mediaDownloader_, SIGNAL(Loaded(AssetPtr)), SLOT(OnMediaLoaded(AssetPtr)));
    connect(mediaDownloader_, SIGNAL(TransferFailed(IAssetTransfer*, QString)), SLOT(OnMediaFailed(IAssetTransfer*, QString)));

    // Construct loading image
    downloadingLogo_ = QImage(500, 300, QImage::Format_ARGB32);
    downloadingLogo_.fill(Qt::black);
    QPixmap bufferingIcon(":/images/buffering.png");
    QPoint centerPos = downloadingLogo_.rect().center();
    QRect target(centerPos.x() - (bufferingIcon.width()/2), centerPos.y() - (bufferingIcon.height()/2), bufferingIcon.width(), bufferingIcon.height());
    QPainter p(&downloadingLogo_);
    p.setPen(Qt::white);
    p.drawPixmap(target, bufferingIcon, bufferingIcon.rect());
    p.drawText(5, 12, "Downloading media...");
    p.end();
}
void VlcMediaPlayer::OnStatusUpdate(const PlayerStatus &status)
{
    switch (status.change)
    {
        case PlayerStatus::MediaState:
        {
            if (status.stopped)
            {
                ui_.timeSlider->setValue(0);
                ui_.timeSlider->setEnabled(false);
                ui_.playButton->setVisible(true);
                ui_.pauseButton->setVisible(false);
            }
            if (status.playing)
            {
                ui_.timeSlider->setEnabled(true);
                ui_.playButton->setVisible(!status.playing);
                ui_.pauseButton->setVisible(status.playing);
            }
            if (status.paused)
            {
                ui_.timeSlider->setEnabled(false);
                ui_.playButton->setVisible(status.paused);
                ui_.pauseButton->setVisible(!status.paused);
            }
            ForceUpdateImage();
            break;
        }
        case PlayerStatus::MediaTime:
        {
            if (!ui_.timeSlider->isSliderDown())
                ui_.timeSlider->setValue(status.time);
            if (ui_.timeSlider->maximum() != status.lenght)
            {
                QTime tTotal;
                tTotal = tTotal.addMSecs(status.lenght);
                totalTime_ =  " / " + tTotal.toString((tTotal.hour() > 0 ? "H:m:ss" : "m:ss"));
                ui_.timeSlider->setRange(0, status.lenght);
            }
            QTime tNow;
            tNow = tNow.addMSecs(status.time);
            nowTime_ = tNow.toString((tNow.hour() > 0 ? "H:m:ss" : "m:ss"));
            ui_.timeLabel->setText(nowTime_ + totalTime_);
            break;
        }
        case PlayerStatus::MediaSource:
        {
            currentSource_ = status.source;
            setWindowTitle(status.source);
            ui_.playButton->setVisible(true);
            ui_.pauseButton->setVisible(false);
            break;
        }
        case PlayerStatus::PlayerError:
        {
            LogError(status.error);
            break;
        }
        case PlayerStatus::MediaSize:
            break;
        case PlayerStatus::MediaProperty:
            break;
        case PlayerStatus::NoChange:
            break;
    }
}