Пример #1
0
bool YVPlayer::nativeEventFilter(void *message) {
    bps_event_t * const event = static_cast<bps_event_t *>(message);

    unsigned int code = bps_event_get_code(event);

    switch (code) {

    case MMRENDERER_STATUS_UPDATE :
        m_pos = QString(mmrenderer_event_get_position(event)).toInt();
        break;
    case MMRENDERER_STATE_CHANGE :
        if (mmrenderer_event_get_state(event) == MMR_STOPPED) {
            if (m_playing && m_ctxt) {
                m_pos = -1; mmr_stop(m_ctxt); mmr_context_destroy(m_ctxt); m_ctxt = 0;
            }
            m_playing = false;
            emit playingChanged();
        }
        break;
    }

    if (s_previousEventFilter)
        return s_previousEventFilter(message);

    return false;
}
Пример #2
0
void BbMediaPlayerControl::bpsEventHandler(bps_event_t *event)
{
    if (m_videoControl)
        m_videoControl->bpsEventHandler(event);

    if (bps_event_get_domain(event) != mmrenderer_get_domain())
        return;

    if (bps_event_get_code(event) == MMRENDERER_STATE_CHANGE) {
        const mmrenderer_state_t newState = mmrenderer_event_get_state(event);
        if (newState == MMR_STOPPED) {

            // Only react to stop events that happen when the end of the stream is reached and
            // playback is stopped because of this.
            // Ignore other stop event sources, souch as calling mmr_stop() ourselves and
            // mmr_input_attach().
            if (m_stopEventsToIgnore > 0) {
                --m_stopEventsToIgnore;
            } else {
                setMediaStatus(QMediaPlayer::EndOfMedia);
                stopInternal(IgnoreMmRenderer);
            }
            return;
        }
    }

    if (bps_event_get_code(event) == MMRENDERER_STATUS_UPDATE) {

        // Prevent spurious position change events from overriding our own position, for example
        // when setting the position to 0 in stop().
        if (m_state != QMediaPlayer::PlayingState ||
            m_mediaStatus == QMediaPlayer::LoadingMedia ||
            m_mediaStatus == QMediaPlayer::NoMedia ||
            m_mediaStatus == QMediaPlayer::InvalidMedia)
            return;

        const qint64 newPosition = QString::fromAscii(mmrenderer_event_get_position(event)).toLongLong();
        if (newPosition != 0 && newPosition != m_position) {
            m_position = newPosition;
            emit positionChanged(m_position);
        }

        const QString bufferStatus = QString::fromAscii(mmrenderer_event_get_bufferlevel(event));
        const int slashPos = bufferStatus.indexOf('/');
        if (slashPos != -1) {
            const int fill = bufferStatus.left(slashPos).toInt();
            const int capacity = bufferStatus.mid(slashPos + 1).toInt();
            if (capacity != 0) {
                m_bufferStatus = fill / static_cast<float>(capacity) * 100.0f;
                emit bufferStatusChanged(m_bufferStatus);
            }
        }
    }
}