VLCMediaPlayer.cpp 1.95 KB
Newer Older
1
#include <QtDebug>
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
2 3 4 5 6
#include <cassert>
#include "VLCMediaPlayer.h"

using namespace LibVLCpp;

7
MediaPlayer::MediaPlayer(Media* media, bool playStop /* = true*/) : /*_evMgr(NULL),`*/ _isReady(false)
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
{
    this->_internalPtr = libvlc_media_player_new_from_media(media->getInternalPtr(), this->_ex);
    this->_ex.checkThrow();
}

void                            MediaPlayer::play()
{
    libvlc_media_player_play(this->_internalPtr, this->_ex);
    this->_ex.checkThrow();
}

void                            MediaPlayer::pause()
{
    libvlc_media_player_pause(this->_internalPtr, this->_ex);
    this->_ex.checkThrow();
}

void                            MediaPlayer::stop()
{
    libvlc_media_player_stop(this->_internalPtr, this->_ex);
28
    this->_ex.checkThrow();
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
29 30 31 32 33 34 35 36 37 38 39
}

qint64                          MediaPlayer::getTime()
{
    qint64 t = libvlc_media_player_get_time(this->_internalPtr, this->_ex);
    this->_ex.checkThrow();
    return t;
}

void                            MediaPlayer::setTime(qint64 time)
{
40
//    qDebug() << "Setting media time to " << time;
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
41 42 43 44 45 46 47 48
    libvlc_media_player_set_time(this->_internalPtr, time, this->_ex);
    this->_ex.checkThrow();
}

qint64                          MediaPlayer::getLength()
{
    qint64 length = libvlc_media_player_get_length(this->_internalPtr, this->_ex);
    this->_ex.checkThrow();
49
//    qDebug() << "Media length: " << length;
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
50 51
    return length;
}
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
52

53
void                            MediaPlayer::takeSnapshot(char* outputFile, unsigned int width, unsigned int heigth)
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
54
{
55
    libvlc_video_take_snapshot(*this, outputFile, width, heigth, this->_ex);
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
56 57
    this->_ex.checkThrow();
}
58 59 60 61 62 63 64 65 66 67 68 69 70 71

int                             MediaPlayer::isPlaying()
{
    int res = libvlc_media_player_is_playing(this->_internalPtr, this->_ex);
    this->_ex.checkThrow();
    return res;
}

int                             MediaPlayer::isSeekable()
{
    int res = libvlc_media_player_is_seekable(this->_internalPtr, this->_ex);
    this->_ex.checkThrow();
    return res;
}