Exemplo n.º 1
0
//libvlc events arrives from separate thread
void QmlVlcPlayerProxy::media_player_event( const libvlc_event_t* e )
{
    //LogEvent( e );

    switch ( e->type ) {
    case libvlc_MediaPlayerMediaChanged:
        Q_EMIT mediaPlayerMediaChanged();
        break;
    case libvlc_MediaPlayerNothingSpecial:
        Q_EMIT mediaPlayerNothingSpecial();
        break;
    case libvlc_MediaPlayerOpening:
        Q_EMIT mediaPlayerOpening();
        break;
    case libvlc_MediaPlayerBuffering:
        Q_EMIT mediaPlayerBuffering( e->u.media_player_buffering.new_cache );
        break;
    case libvlc_MediaPlayerPlaying:
        Q_EMIT mediaPlayerPlaying();
        break;
    case libvlc_MediaPlayerPaused:
        Q_EMIT mediaPlayerPaused();
        break;
    case libvlc_MediaPlayerStopped:
        Q_EMIT mediaPlayerStopped();
        break;
    case libvlc_MediaPlayerForward:
        Q_EMIT mediaPlayerForward();
        break;
    case libvlc_MediaPlayerBackward:
        Q_EMIT mediaPlayerBackward();
        break;
    case libvlc_MediaPlayerEndReached:
        Q_EMIT mediaPlayerEndReached();
        break;
    case libvlc_MediaPlayerEncounteredError:
        Q_EMIT mediaPlayerEncounteredError();
        break;
    case libvlc_MediaPlayerTimeChanged: {
        double new_time = static_cast<double>( e->u.media_player_time_changed.new_time );
        Q_EMIT mediaPlayerTimeChanged( new_time );
        break;
    }
    case libvlc_MediaPlayerPositionChanged:
        Q_EMIT mediaPlayerPositionChanged( e->u.media_player_position_changed.new_position );
        break;
    case libvlc_MediaPlayerSeekableChanged:
        Q_EMIT mediaPlayerSeekableChanged( e->u.media_player_seekable_changed.new_seekable != 0 );
        break;
    case libvlc_MediaPlayerPausableChanged:
        Q_EMIT mediaPlayerPausableChanged( e->u.media_player_pausable_changed.new_pausable != 0 );
        break;
    case libvlc_MediaPlayerTitleChanged:
        Q_EMIT mediaPlayerTitleChanged();
        break;
    case libvlc_MediaPlayerLengthChanged: {
            double new_length =
                static_cast<double>( e->u.media_player_length_changed.new_length );
            Q_EMIT mediaPlayerLengthChanged( new_length );
        }
        break;
    };
}
Exemplo n.º 2
0
QmlVlcPlayerProxy::QmlVlcPlayerProxy( const std::shared_ptr<vlc::player>& player,
                                      QObject* parent /*= 0*/ )
    : QObject( parent ), m_player( player ), m_audio( *player ), m_input( *player ),
      m_playlist( this ), m_subtitle( *player ), m_video( *player ),
      m_currentMediaDesc( this )
{
    qRegisterMetaType<QmlVlcPlayerProxy::State>("QmlVlcPlayerProxy::State");

    m_errorTimer.setInterval( 1000 );
    m_errorTimer.setSingleShot( true );

    connect( this, SIGNAL( mediaPlayerPlaying() ),
             this, SIGNAL( playingChanged() ), Qt::QueuedConnection );
    connect( this, SIGNAL( mediaPlayerPaused() ),
             this, SIGNAL( playingChanged() ), Qt::QueuedConnection );
    connect( this, SIGNAL( mediaPlayerEncounteredError() ),
             this, SIGNAL( playingChanged() ), Qt::QueuedConnection );
    connect( this, SIGNAL( mediaPlayerEndReached() ),
             this, SIGNAL( playingChanged() ), Qt::QueuedConnection );
    connect( this, SIGNAL( mediaPlayerStopped() ),
             this, SIGNAL( playingChanged() ), Qt::QueuedConnection );

    connect( this, &QmlVlcPlayerProxy::mediaPlayerNothingSpecial,
        [this] () {
            Q_EMIT stateChanged( NothingSpecial );
        } );

    connect( this, &QmlVlcPlayerProxy::mediaPlayerOpening,
        [this] () {
            Q_EMIT stateChanged( Opening );
        } );

    connect( this, &QmlVlcPlayerProxy::mediaPlayerBuffering,
        [this] ( float ) {
            Q_EMIT stateChanged( Buffering );
        } );

    connect( this, &QmlVlcPlayerProxy::mediaPlayerPlaying,
        [this] () {
            Q_EMIT stateChanged( Playing );
        } );

    connect( this, &QmlVlcPlayerProxy::mediaPlayerPaused,
        [this] () {
            Q_EMIT stateChanged( Paused );
        } );

    connect( this, &QmlVlcPlayerProxy::mediaPlayerEncounteredError,
        [this] () {
            Q_EMIT stateChanged( Error );
        } );

    connect( this, &QmlVlcPlayerProxy::mediaPlayerEndReached,
        [this] () {
            Q_EMIT stateChanged( Ended );
        } );

    connect( this, &QmlVlcPlayerProxy::mediaPlayerStopped,
        [this] () {
            Q_EMIT stateChanged( Stopped );
        } );


    connect( this, SIGNAL( mediaPlayerEncounteredError() ),
             &m_errorTimer, SLOT( start() ) );
    connect( &m_errorTimer, SIGNAL( timeout() ),
             this, SLOT( currentItemEndReached() ) );

    connect( this, SIGNAL( mediaPlayerEndReached() ),
             &m_errorTimer, SLOT( stop() ) );
    connect( this, SIGNAL( mediaPlayerEndReached() ),
             this, SLOT( currentItemEndReached() ) );

    connect( this, SIGNAL( mediaPlayerMediaChanged() ),
             &m_errorTimer, SLOT( stop() ) );
    connect( this, SIGNAL( mediaPlayerMediaChanged() ),
             &m_playlist, SIGNAL( currentItemChanged() ), Qt::QueuedConnection );
    connect( this, &QmlVlcPlayerProxy::mediaPlayerMediaChanged,
             get_subtitle(), &QmlVlcSubtitle::eraseLoaded );

    connect( this, SIGNAL( mediaPlayerTitleChanged() ),
             &m_currentMediaDesc, SIGNAL( titleChanged() ), Qt::QueuedConnection );

    connect( get_audio(), SIGNAL( volumeChanged() ),
             this, SIGNAL( volumeChanged() ), Qt::QueuedConnection );
}
Exemplo n.º 3
0
void QmlVlcPlayerProxy::handleLibvlcEvent( const LibvlcEvent& event )
{
    //it's highly possible libvlc_event_t will have wrong pointers inside at this point
    const libvlc_event_t* e = &event._libvlcEvent;

    //LogEvent( e );

    switch ( e->type ) {
    case libvlc_MediaPlayerMediaChanged:
        Q_EMIT mediaPlayerMediaChanged();
        Q_EMIT m_playlist.currentItemChanged();
        break;
    case libvlc_MediaPlayerNothingSpecial:
        Q_EMIT mediaPlayerNothingSpecial();
        Q_EMIT stateChanged( NothingSpecial );
        break;
    case libvlc_MediaPlayerOpening:
        Q_EMIT mediaPlayerOpening();
        Q_EMIT stateChanged( Opening );
        break;
    case libvlc_MediaPlayerBuffering:
        Q_EMIT mediaPlayerBuffering( e->u.media_player_buffering.new_cache );
        Q_EMIT stateChanged( Buffering );
        break;
    case libvlc_MediaPlayerPlaying:
        Q_EMIT mediaPlayerPlaying();
        Q_EMIT stateChanged( Playing );
        Q_EMIT playingChanged();
        break;
    case libvlc_MediaPlayerPaused:
        Q_EMIT mediaPlayerPaused();
        Q_EMIT stateChanged( Paused );
        Q_EMIT playingChanged();
        break;
    case libvlc_MediaPlayerStopped:
        Q_EMIT mediaPlayerStopped();
        Q_EMIT stateChanged( Stopped );
        Q_EMIT playingChanged();
        break;
    case libvlc_MediaPlayerForward:
        Q_EMIT mediaPlayerForward();
        break;
    case libvlc_MediaPlayerBackward:
        Q_EMIT mediaPlayerBackward();
        break;
    case libvlc_MediaPlayerEndReached:
        Q_EMIT mediaPlayerEndReached();
        Q_EMIT stateChanged( Ended );
        Q_EMIT playingChanged();
        break;
    case libvlc_MediaPlayerEncounteredError:
        Q_EMIT mediaPlayerEncounteredError();
        Q_EMIT stateChanged( Error );
        Q_EMIT playingChanged();
        break;
    case libvlc_MediaPlayerTimeChanged: {
        double new_time = static_cast<double>( e->u.media_player_time_changed.new_time );
        Q_EMIT mediaPlayerTimeChanged( new_time );
        break;
    }
    case libvlc_MediaPlayerPositionChanged:
        Q_EMIT mediaPlayerPositionChanged( e->u.media_player_position_changed.new_position );
        break;
    case libvlc_MediaPlayerSeekableChanged:
        Q_EMIT mediaPlayerSeekableChanged( e->u.media_player_seekable_changed.new_seekable != 0 );
        break;
    case libvlc_MediaPlayerPausableChanged:
        Q_EMIT mediaPlayerPausableChanged( e->u.media_player_pausable_changed.new_pausable != 0 );
        break;
    case libvlc_MediaPlayerTitleChanged:
        Q_EMIT mediaPlayerTitleChanged();
        Q_EMIT m_currentMediaDesc.titleChanged();
        break;
    case libvlc_MediaPlayerLengthChanged: {
            double new_length =
                static_cast<double>( e->u.media_player_length_changed.new_length );
            Q_EMIT mediaPlayerLengthChanged( new_length );
        }
        break;
    };
}