/* libVLC and Qt sample code
* Copyright © 2009 Alexander Maringer <maringer@maringer-it.de>
*/
#include "vlc_on_qt.h"
//#include <QX11EmbedContainer>
#include <QVBoxLayout>
#include <QPushButton>
#include <QSlider>
#include <QTimer>
#include <QFrame>
Player::Player()
: QWidget()
{
//preparation of the vlc command
const char * const vlc_args[] = {
"-I", "dummy", /* Don't use any interface */
"--ignore-config", /* Don't use VLC's config */
"--extraintf=logger", //log anything
"--verbose=2", //be much more verbose then normal for debugging purpose
"--plugin-path=C:\\vlc-0.9.9-win32\\plugins\\" };
#ifdef Q_WS_X11
_videoWidget=new QX11EmbedContainer(this);
#else
_videoWidget=new QFrame(this);
#endif
_volumeSlider=new QSlider(Qt::Horizontal,this);
_volumeSlider->setMaximum(100); //the volume is between 0 and 100
_volumeSlider->setToolTip("Audio slider");
// Note: if you use streaming, there is no ability to use the position slider
_positionSlider=new QSlider(Qt::Horizontal,this);
_positionSlider->setMaximum(POSITION_RESOLUTION);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(_videoWidget);
layout->addWidget(_positionSlider);
layout->addWidget(_volumeSlider);
setLayout(layout);
_isPlaying=false;
poller=new QTimer(this);
//Initialize an instance of vlc
//a structure for the exception is neede for this initalization
libvlc_exception_init(&_vlcexcep);
//create a new libvlc instance
_vlcinstance=libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args,&_vlcexcep); //tricky calculation of the char space used
raise (&_vlcexcep);
// Create a media player playing environement
_mp = libvlc_media_player_new (_vlcinstance, &_vlcexcep);
raise (&_vlcexcep);
//connect the two sliders to the corresponding slots (uses Qt's signal / slots technology)
connect(poller, SIGNAL(timeout()), this, SLOT(updateInterface()));
connect(_positionSlider, SIGNAL(sliderMoved(int)), this, SLOT(changePosition(int)));
connect(_volumeSlider, SIGNAL(sliderMoved(int)), this, SLOT(changeVolume(int)));
poller->start(100); //start timer to trigger every 100 ms the updateInterface slot
}
//desctructor
Player::~Player()
{
/* Stop playing */
libvlc_media_player_stop (_mp, &_vlcexcep);
/* Free the media_player */
libvlc_media_player_release (_mp);
libvlc_release (_vlcinstance);
raise (&_vlcexcep);
}
void Player::playFile(QString file)
{
//the file has to be in one of the following formats /perhaps a little bit outdated)
/*
[file://]filename Plain media file
http://ip:port/file HTTP URL
ftp://ip:port/file FTP URL
mms://ip:port/file MMS URL
screen:// Screen capture
[dvd://][device][@raw_device] DVD device
[vcd://][device] VCD device
[cdda://][device] Audio CD device
udp:[[<source address>]@[<bind address>][:<bind port>]]
*/
/* Create a new LibVLC media descriptor */
QByteArray ba = file.toLatin1();
const char *c_str2 = ba.data();
_m = libvlc_media_new (_vlcinstance,c_str2, &_vlcexcep);
raise(&_vlcexcep);
libvlc_media_player_set_media (_mp, _m, &_vlcexcep);
raise(&_vlcexcep);
// /!\ Please note /!\
//
// passing the widget to the lib shows vlc at which position it should show up
// vlc automatically resizes the video to the ´given size of the widget
// and it even resizes it, if the size changes at the playing
/* Get our media instance to use our window */
#if defined(Q_OS_WIN)
libvlc_media_player_set_drawable(_mp, reinterpret_cast<unsigned int>(_videoWidget->winId()), &_vlcexcep );
//libvlc_media_player_set_hwnd(_mp, _videoWidget->winId(), &_vlcexcep ); // for vlc 1.0
#elif defined(Q_OS_MAC)
libvlc_media_player_set_drawable(_mp, _videoWidget->winId(), &_vlcexcep );
//libvlc_media_player_set_agl (_mp, _videoWidget->winId(), &_vlcexcep); // for vlc 1.0
#else //Linux
//[20101201 Ondrej Spilka] obsolete call on libVLC >=1.1.5
//libvlc_media_player_set_drawable(_mp, _videoWidget->winId(), &_vlcexcep );
//libvlc_media_player_set_xwindow(_mp, _videoWidget->winId(), &_vlcexcep ); // for vlc 1.0
/* again note X11 handle on Linux is needed
winID() returns X11 handle when QX11EmbedContainer us used */
int windid = _videoWidget->winId();
libvlc_media_player_set_xwindow (mp, windid );
#endif
raise(&_vlcexcep);
/* Play */
libvlc_media_player_play (_mp, &_vlcexcep );
raise(&_vlcexcep);
_isPlaying=true;
}
void Player::changeVolume(int newVolume)
{
libvlc_exception_clear(&_vlcexcep);
libvlc_audio_set_volume (_vlcinstance,newVolume , &_vlcexcep);
raise(&_vlcexcep);
}
void Player::changePosition(int newPosition)
{
libvlc_exception_clear(&_vlcexcep);
// It's possible that the vlc doesn't play anything
// so check before
libvlc_media_t *curMedia = libvlc_media_player_get_media (_mp, &_vlcexcep);
libvlc_exception_clear(&_vlcexcep);
if (curMedia == NULL)
return;
float pos=(float)(newPosition)/(float)POSITION_RESOLUTION;
libvlc_media_player_set_position (_mp, pos, &_vlcexcep);
raise(&_vlcexcep);
}
void Player::updateInterface()
{
if(!_isPlaying)
return;
// It's possible that the vlc doesn't play anything
// so check before
libvlc_media_t *curMedia = libvlc_media_player_get_media (_mp, &_vlcexcep);
libvlc_exception_clear(&_vlcexcep);
if (curMedia == NULL)
return;
float pos=libvlc_media_player_get_position (_mp, &_vlcexcep);
int siderPos=(int)(pos*(float)(POSITION_RESOLUTION));
_positionSlider->setValue(siderPos);
int volume=libvlc_audio_get_volume (_vlcinstance,&_vlcexcep);
_volumeSlider->setValue(volume);
}
void Player::raise(libvlc_exception_t * ex)
{
if (libvlc_exception_raised (ex))
{
fprintf (stderr, "error: %s\n", libvlc_exception_get_message(ex));
exit (-1);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
QT5调用VLC编程完美了 (333个子文件)
libvlccore.dll.a 329KB
libvlc.dll.a 158KB
vlc_on_qt.cpp 6KB
main.cpp 345B
mainwindow.cpp 277B
libqt4_plugin.dll 8.81MB
libavformat_plugin.dll 5.19MB
libavcodec_plugin.dll 4.66MB
libfreetype_plugin.dll 2.75MB
liblibass_plugin.dll 2.74MB
libskins2_plugin.dll 2.32MB
libvlccore.dll 1.96MB
libmkv_plugin.dll 1.23MB
libxml_plugin.dll 1.13MB
libvorbis_plugin.dll 1.11MB
liblive555_plugin.dll 1.01MB
libtaglib_plugin.dll 998KB
libgnutls_plugin.dll 869KB
libx264_plugin.dll 743KB
libschroedinger_plugin.dll 685KB
libcaca_plugin.dll 599KB
libswscale_plugin.dll 384KB
libzvbi_plugin.dll 382KB
libstream_out_rtp_plugin.dll 378KB
libaccess_output_shout_plugin.dll 365KB
libremoteosd_plugin.dll 350KB
librtp_plugin.dll 344KB
libfaad_plugin.dll 297KB
libsdl_image_plugin.dll 277KB
libtheora_plugin.dll 276KB
libmod_plugin.dll 257KB
liblua_plugin.dll 249KB
libflac_plugin.dll 244KB
libdvdnav_plugin.dll 208KB
libpng_plugin.dll 197KB
libgoom_plugin.dll 195KB
libmp4_plugin.dll 189KB
libpostproc_plugin.dll 167KB
libdshow_plugin.dll 155KB
libdtstofloat32_plugin.dll 149KB
libbda_plugin.dll 146KB
liblibmpeg2_plugin.dll 123KB
libdvdread_plugin.dll 122KB
libdvbsub_plugin.dll 119KB
libatmo_plugin.dll 118KB
libtwolame_plugin.dll 117KB
libi420_rgb_sse2_plugin.dll 114KB
libid3tag_plugin.dll 113KB
libmpgatofixed32_plugin.dll 105KB
libvlc.dll 102KB
libts_plugin.dll 101KB
libhttp_plugin.dll 101KB
libmux_ts_plugin.dll 100KB
libkate_plugin.dll 93KB
libspeex_plugin.dll 92KB
libplaylist_plugin.dll 85KB
libaccess_http_plugin.dll 84KB
libsap_plugin.dll 75KB
libasf_plugin.dll 74KB
libspatializer_plugin.dll 73KB
libaccess_mms_plugin.dll 69KB
libavi_plugin.dll 64KB
libmux_ps_plugin.dll 63KB
libportaudio_plugin.dll 62KB
libmux_mp4_plugin.dll 61KB
libogg_plugin.dll 56KB
libvod_rtsp_plugin.dll 53KB
libi420_rgb_mmx_plugin.dll 52KB
libmpc_plugin.dll 50KB
libpanoramix_plugin.dll 48KB
libflacsys_plugin.dll 46KB
libequalizer_plugin.dll 44KB
libcmml_plugin.dll 43KB
libpacketizer_mpeg4audio_plugin.dll 42KB
libaccess_rtmp_plugin.dll 41KB
libaccess_realrtsp_plugin.dll 41KB
liba52tofloat32_plugin.dll 41KB
librc_plugin.dll 41KB
libaccess_output_rtmp_plugin.dll 40KB
libmux_asf_plugin.dll 40KB
libdeinterlace_plugin.dll 39KB
libcdda_plugin.dll 38KB
libvout_directx_plugin.dll 38KB
libpacketizer_h264_plugin.dll 37KB
libstream_out_transcode_plugin.dll 36KB
libvisual_plugin.dll 35KB
libty_plugin.dll 35KB
libaudioscrobbler_plugin.dll 35KB
libblend_plugin.dll 35KB
libaudio_format_plugin.dll 34KB
libvobsub_plugin.dll 34KB
libaccess_ftp_plugin.dll 34KB
libstream_out_standard_plugin.dll 32KB
libdirect3d_plugin.dll 32KB
libi420_rgb_plugin.dll 30KB
libaccess_filter_timeshift_plugin.dll 29KB
libaccess_smb_plugin.dll 28KB
librealaudio_plugin.dll 28KB
libaccess_filter_record_plugin.dll 27KB
libps_plugin.dll 27KB
共 333 条
- 1
- 2
- 3
- 4
走随心
- 粉丝: 1
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页