logo

English

이곳의 프로그래밍관련 정보와 소스는 마음대로 활용하셔도 좋습니다. 다만 쓰시기 전에 통보 정도는 해주시는 것이 예의 일것 같습니다. 질문이나 오류 수정은 siseong@gmail.com 으로 주세요. 감사합니다.

LibVLC 미디어 재생기 프로그래밍 방법 C++, QT

by 엉뚱도마뱀 posted Apr 20, 2018
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

비디오 재생기 만들때 참조하세요.

 

#include <QtGlobal>

#include <QtDebug>

#include <cassert>

#include "VLCMediaPlayer.h"

#include "VLCInstance.h"

#include "VLCMedia.h"

 

using namespace LibVLCpp;

 

MediaPlayer::MediaPlayer() : m_media( NULL )

{

    m_internalPtr = libvlc_media_player_new( LibVLCpp::Instance::getInstance()->getInternalPtr() );

    // Initialize the event manager

    p_em = libvlc_media_player_event_manager( m_internalPtr );

    registerEvents();

}

 

MediaPlayer::MediaPlayer( Media* media ) : m_media( media )

{

    m_internalPtr = libvlc_media_player_new_from_media( media->getInternalPtr() );

 

    // Initialize the event manager

    p_em = libvlc_media_player_event_manager( m_internalPtr );

    registerEvents();

}

 

MediaPlayer::~MediaPlayer()

{

    libvlc_event_detach( p_em, libvlc_MediaPlayerSnapshotTaken, callbacks, this );

    libvlc_event_detach( p_em, libvlc_MediaPlayerTimeChanged, callbacks, this );

    libvlc_event_detach( p_em, libvlc_MediaPlayerPlaying, callbacks, this );

    libvlc_event_detach( p_em, libvlc_MediaPlayerPaused, callbacks, this );

    libvlc_event_detach( p_em, libvlc_MediaPlayerStopped, callbacks, this );

    libvlc_event_detach( p_em, libvlc_MediaPlayerEndReached, callbacks, this );

    libvlc_event_detach( p_em, libvlc_MediaPlayerPositionChanged, callbacks, this );

    stop();

    libvlc_media_player_release( m_internalPtr );

}

 

void

MediaPlayer::registerEvents()

{

    // Register the callback

    libvlc_event_attach( p_em, libvlc_MediaPlayerSnapshotTaken,   callbacks, this );

    libvlc_event_attach( p_em, libvlc_MediaPlayerTimeChanged,     callbacks, this );

    libvlc_event_attach( p_em, libvlc_MediaPlayerPlaying,         callbacks, this );

    libvlc_event_attach( p_em, libvlc_MediaPlayerPaused,          callbacks, this );

    libvlc_event_attach( p_em, libvlc_MediaPlayerStopped,         callbacks, this );

    libvlc_event_attach( p_em, libvlc_MediaPlayerEndReached,      callbacks, this );

    libvlc_event_attach( p_em, libvlc_MediaPlayerPositionChanged, callbacks, this );

    libvlc_event_attach( p_em, libvlc_MediaPlayerLengthChanged,   callbacks, this );

    libvlc_event_attach( p_em, libvlc_MediaPlayerEncounteredError,callbacks, this );

    libvlc_event_attach( p_em, libvlc_MediaPlayerPausableChanged, callbacks, this );

    libvlc_event_attach( p_em, libvlc_MediaPlayerSeekableChanged, callbacks, this );

}

 

/**

 * Event dispatcher.

 */

void

MediaPlayer::callbacks( const libvlc_event_t* event, void* ptr )

{

    MediaPlayer* self = reinterpret_cast<MediaPlayer*>( ptr );

    switch ( event->type )

    {

    case libvlc_MediaPlayerPlaying:

        //qDebug() << "Media player playing";

        self->emit playing();

        break;

    case libvlc_MediaPlayerPaused:

        //qDebug() << "Media player paused";

        self->emit paused();

        break;

    case libvlc_MediaPlayerStopped:

        //qDebug() << "Media player stopped";

        self->emit stopped();

        break;

    case libvlc_MediaPlayerEndReached:

        //qDebug() << "Media player end reached";

        self->emit endReached();

        break;

    case libvlc_MediaPlayerTimeChanged:

        self->emit timeChanged( event->u.media_player_time_changed.new_time );

        break;

    case libvlc_MediaPlayerPositionChanged:

        //qDebug() << self << "position changed : " << event->u.media_player_position_changed.new_position;

        self->emit positionChanged( event->u.media_player_position_changed.new_position );

        break;

    case libvlc_MediaPlayerLengthChanged:

        self->emit lengthChanged( event->u.media_player_length_changed.new_length );

        break;

    case libvlc_MediaPlayerSnapshotTaken:

        self->emit snapshotTaken( event->u.media_player_snapshot_taken.psz_filename );

        break;

    case libvlc_MediaPlayerEncounteredError:

        qDebug() << '[' << (void*)self << "] libvlc_MediaPlayerEncounteredError received."

                << "This is not looking good...";

        self->emit errorEncountered();

        break;

    case libvlc_MediaPlayerSeekableChanged:

        // TODO: Later change it to an event that corresponds volume change, when this thing gets fixed in libvlc

        self->emit volumeChanged();

        break;

    case libvlc_MediaPlayerPausableChanged:

    case libvlc_MediaPlayerTitleChanged:

    case libvlc_MediaPlayerNothingSpecial:

    case libvlc_MediaPlayerOpening:

    case libvlc_MediaPlayerBuffering:

    case libvlc_MediaPlayerForward:

    case libvlc_MediaPlayerBackward:

    default:

//        qDebug() << "Unknown mediaPlayerEvent: " << event->type;

        break;

    }

}

 

void

MediaPlayer::play()

{

    //qDebug() << "Asking for play media player";

    libvlc_media_player_play( m_internalPtr );

}

 

void

MediaPlayer::pause()

{

    libvlc_media_player_pause( m_internalPtr );

}

 

void

MediaPlayer::stop()

{

    //qDebug() << "Asking for stop media player";

    libvlc_media_player_stop( m_internalPtr );

}

 

int

MediaPlayer::getVolume()

{

    int volume = libvlc_audio_get_volume( m_internalPtr );

    return volume;

}

 

int

MediaPlayer::setVolume( int volume )

{

    //Returns 0 if the volume was set, -1 if it was out of range

    return libvlc_audio_set_volume( m_internalPtr, volume );

}

 

qint64

MediaPlayer::getTime()

{

    qint64 t = libvlc_media_player_get_time( m_internalPtr );

    return t;

}

 

void

MediaPlayer::setTime( qint64 time )

{

    libvlc_media_player_set_time( m_internalPtr, time );

}

 

float

MediaPlayer::getPosition()

{

    return libvlc_media_player_get_position( m_internalPtr );

}

 

void

MediaPlayer::setPosition( float pos )

{

    libvlc_media_player_set_position( m_internalPtr, pos );

}

 

qint64

MediaPlayer::getLength()

{

    return libvlc_media_player_get_length( m_internalPtr );

}

 

void

MediaPlayer::takeSnapshot( const char* outputFile, unsigned int width, unsigned int heigth )

{

    libvlc_video_take_snapshot( *this, 0, outputFile, width, heigth );

}

 

bool

MediaPlayer::isPlaying()

{

    return ( libvlc_media_player_is_playing( m_internalPtr ) == 1 );

}

 

bool

MediaPlayer::isSeekable()

{

    return ( libvlc_media_player_is_seekable( m_internalPtr ) == 1 );

}

 

void

MediaPlayer::setDrawable( void* drawable )

{

#if defined ( Q_WS_MAC )

    libvlc_media_player_set_nsobject( m_internalPtr, drawable );

#elif defined ( Q_OS_UNIX )

    libvlc_media_player_set_xwindow( m_internalPtr, reinterpret_cast<intptr_t>( drawable ) );

#elif defined ( Q_OS_WIN )

    libvlc_media_player_set_hwnd( m_internalPtr, drawable );

#endif

}

 

void

MediaPlayer::setMedia( Media* media )

{

    libvlc_media_player_set_media( m_internalPtr, media->getInternalPtr() );

}

 

void

MediaPlayer::getSize( quint32 *outWidth, quint32 *outHeight )

{

    libvlc_video_get_size( m_internalPtr, 0, outWidth, outHeight );

}

 

float

MediaPlayer::getFps()

{

    return libvlc_media_player_get_fps( m_internalPtr );

}

 

void

MediaPlayer::nextFrame()

{

    libvlc_media_player_next_frame( m_internalPtr );

}

 

bool

MediaPlayer::hasVout()

{

    return libvlc_media_player_has_vout( m_internalPtr );

}

 

const QString&

MediaPlayer::getLoadedFileName() const

{

    return m_media->getFileName();

}

 

QString

MediaPlayer::getLoadedMRL()

{

    Media::internalPtr     media = libvlc_media_player_get_media( m_internalPtr );

    char* str = libvlc_media_get_mrl( media );

    return QString( str );

}

 

int

MediaPlayer::getNbAudioTrack()

{

    int res = libvlc_audio_get_track_count( m_internalPtr );

    return res;

}

 

int

MediaPlayer::getNbVideoTrack()

{

    int res = libvlc_video_get_track_count( m_internalPtr );

    return res;

}

 

void

MediaPlayer::setKeyInput( bool enabled )

{

    libvlc_video_set_key_input( m_internalPtr, enabled );

}

TAG •

List of Articles
No. Subject Author Date Views
» LibVLC 미디어 재생기 프로그래밍 방법 C++, QT 엉뚱도마뱀 2018.04.20 26
67 select 와 epoll 엉뚱도마뱀 2017.12.11 140
66 비밀번호 해쉬에 Salt(소금) 첨가하기 file 엉뚱도마뱀 2017.11.23 137
65 Linux /dev/random vs /dev/urandom 삽질 후기 엉뚱도마뱀 2017.11.22 111
64 리눅스 /dev/random을 이용한 랜덤값 생성 엉뚱도마뱀 2017.11.22 104
63 난수발생기 개론 엉뚱도마뱀 2017.11.22 104
62 RSA 암호화 알고리즘 개요 file 엉뚱도마뱀 2017.11.17 73
61 악성코드 종류 구분 digipine 2017.11.13 94
60 대칭키 암호화관련 개념 정리 digipine 2017.11.09 89
59 Ubuntu 16 에 mysql 5.7 설치 및 원격 설정 file digipine 2017.11.08 115
58 Ubuntu 16 에 JAVA 1.7.0 jdk 설치 하기 digipine 2017.11.07 112
57 윈도우 한영 전환 쉬프트 스페이스로 변경 digipine 2017.11.03 35
56 우분투 Nabi 한글 입력기 Tray(트레이) 상단 메뉴바로 옮기기 digipine 2017.11.03 49
55 Ubuntu 12.0.4 LTS에 Nabi 나비 설치하기 digipine 2017.11.03 27
54 Linux init.d 에서 등록하기. 부팅 시 자동실행 설정 digipine 2017.11.03 39
53 초고속망 통신사 DNS 서버 주소 모음 - DNS 설정 digipine 2017.11.03 199
52 git 환경 설정 및 명령어 정리 digipine 2017.11.03 30
51 유닉스/리눅스 명령어 레퍼런스 digipine 2017.11.03 56
50 포렌식을 활용한 정보보호 digipine 2017.11.02 36
49 소프트웨어 테스팅 전문가들을 위한 사이트 digipine 2017.11.02 32
Board Pagination Prev 1 2 3 4 Next
/ 4