VLC学习 第一篇安装环境

来源:互联网 发布:折800官网9.9包邮淘宝 编辑:程序博客网 时间:2024/06/04 18:25
一.从官网下载VLC
二.将里面的SDK 放到qt工程目录下
1.VLC_QT配置 
一.从官网下载VLC
二.将里面的SDK 放到qt工程目录下
三.将plugins libvlc.dl, libvlccore.dll放到debug

四.在qt.pro中添加库
LIBS += E:\qt\intel_cup\testVLC\testVLC\lib\libvlc.lib
LIBS += E:\qt\intel_cup\testVLC\testVLC\lib\libvlccore.lib
INCLUDEPATH += E:\qt\intel_cup\testVLC\testVLC\include
五.
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->m_vlcMedia =NULL;
    this->m_vlcMplay = NULL;
    currentWId = ui->widget->winId();
    const char*vlc_args[] ={"-I","dummy","--ignore-config","--extraintf=logger","--verbose=2",};
     m_vlcInst = libvlc_new( sizeof(vlc_args)/sizeof(vlc_args[0]),vlc_args );
    // m_vlcInst = libvlc_new(sizeof(m_vlcArgs)/sizeof(m_vlcArgs[0]),m_vlcArgs);
}
MainWindow::~MainWindow()
{
    delete ui;
    
}
void MainWindow::on_startButton_clicked()
{
 // const char*vlc_args[] ={"-I","dummy","--ignore-config","--extraintf=logger","--verbose=2",};
 //  m_vlcInst = libvlc_new( sizeof(vlc_args)/sizeof(vlc_args[0]),vlc_args );
    m_vlcMedia = libvlc_media_new_location(m_vlcInst,ui->UrlEdit->text().toLatin1());
    m_vlcMplay = libvlc_media_player_new_from_media(m_vlcMedia);
   // libvlc_media_player_set_drawable(m_vlcMplay, (libvlc_drawable_t)currentWId);
    libvlc_media_player_set_hwnd(m_vlcMplay,(void*)&currentWId);
    //播放
    libvlc_media_player_play(m_vlcMplay);
}
void MainWindow::on_closeButton_clicked()
{
    if(!m_vlcInst)
    {
        libvlc_release(m_vlcInst);
    }
    if(!m_vlcMedia)
    {
        libvlc_media_release(m_vlcMedia);
    }
    if(!m_vlcMplay)
    {
        libvlc_media_player_stop(m_vlcMplay);
    }
}
void MainWindow::on_pushButton_clicked()
{
    QString fileOpen = QFileDialog::getOpenFileName(this,tr("Load a file"), "~");
    fileOpen.replace("/", "\\"); //因为getOpenFileName得到的文件名是类//似于C:/Hello/test.avi,与windows下的路径名不匹配,所以需要这一步转换
        /* Stop if something is playing */
    //if(&& libvlc_media_player_is_playing(vlcPlayer) )
    //  stop();
        /* New Media */
        m_vlcMedia = libvlc_media_new_path(m_vlcInst,fileOpen.toLatin1());
        if( !m_vlcMedia )
            return;
        m_vlcMplay = libvlc_media_player_new_from_media(m_vlcMedia);
        libvlc_media_release(m_vlcMedia);
        /* Integrate the video in the interface */
    #if defined(Q_OS_MAC)
        libvlc_media_player_set_nsobject(vlcPlayer, videoWidget->winId());
    #elif defined(Q_OS_UNIX)
        libvlc_media_player_set_xwindow(vlcPlayer, videoWidget->winId());
    #elif defined(Q_OS_WIN)
        libvlc_media_player_set_hwnd(m_vlcMplay,(void*)&currentWId);
    #endif
        //int windid = videoWidget->winId();
        //libvlc_media_player_set_xwindow (vlcPlayer, windid );
          libvlc_media_player_set_xwindow();
        /* And play */
        libvlc_media_player_play(m_vlcMplay);
        //Set vars and text correctly
        //playBut->setText("Pause");
}
成功,既能访问本地,又能访问rtsp





三.将plugins libvlc.dl, libvlccore.dll放到debug

四.在qt.pro中添加库
LIBS += E:\qt\intel_cup\testVLC\testVLC\lib\libvlc.lib
LIBS += E:\qt\intel_cup\testVLC\testVLC\lib\libvlccore.lib
INCLUDEPATH += E:\qt\intel_cup\testVLC\testVLC\include
五.
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->m_vlcMedia =NULL;
    this->m_vlcMplay = NULL;
    currentWId = ui->widget->winId();
    const char*vlc_args[] ={"-I","dummy","--ignore-config","--extraintf=logger","--verbose=2",};
     m_vlcInst = libvlc_new( sizeof(vlc_args)/sizeof(vlc_args[0]),vlc_args );
    // m_vlcInst = libvlc_new(sizeof(m_vlcArgs)/sizeof(m_vlcArgs[0]),m_vlcArgs);
}
MainWindow::~MainWindow()
{
    delete ui;
    
}
void MainWindow::on_startButton_clicked()
{
 // const char*vlc_args[] ={"-I","dummy","--ignore-config","--extraintf=logger","--verbose=2",};
 //  m_vlcInst = libvlc_new( sizeof(vlc_args)/sizeof(vlc_args[0]),vlc_args );
    m_vlcMedia = libvlc_media_new_location(m_vlcInst,ui->UrlEdit->text().toLatin1());
    m_vlcMplay = libvlc_media_player_new_from_media(m_vlcMedia);
   // libvlc_media_player_set_drawable(m_vlcMplay, (libvlc_drawable_t)currentWId);
    libvlc_media_player_set_hwnd(m_vlcMplay,(void*)&currentWId);
    //播放
    libvlc_media_player_play(m_vlcMplay);
}
void MainWindow::on_closeButton_clicked()
{
    if(!m_vlcInst)
    {
        libvlc_release(m_vlcInst);
    }
    if(!m_vlcMedia)
    {
        libvlc_media_release(m_vlcMedia);
    }
    if(!m_vlcMplay)
    {
        libvlc_media_player_stop(m_vlcMplay);
    }
}
void MainWindow::on_pushButton_clicked()
{
    QString fileOpen = QFileDialog::getOpenFileName(this,tr("Load a file"), "~");
    fileOpen.replace("/", "\\"); //因为getOpenFileName得到的文件名是类//似于C:/Hello/test.avi,与windows下的路径名不匹配,所以需要这一步转换
        /* Stop if something is playing */
    //if(&& libvlc_media_player_is_playing(vlcPlayer) )
    //  stop();
        /* New Media */
        m_vlcMedia = libvlc_media_new_path(m_vlcInst,fileOpen.toLatin1());
        if( !m_vlcMedia )
            return;
        m_vlcMplay = libvlc_media_player_new_from_media(m_vlcMedia);
        libvlc_media_release(m_vlcMedia);
        /* Integrate the video in the interface */
    #if defined(Q_OS_MAC)
        libvlc_media_player_set_nsobject(vlcPlayer, videoWidget->winId());
    #elif defined(Q_OS_UNIX)
        libvlc_media_player_set_xwindow(vlcPlayer, videoWidget->winId());
    #elif defined(Q_OS_WIN)
        libvlc_media_player_set_hwnd(m_vlcMplay,(void*)&currentWId);
    #endif
        //int windid = videoWidget->winId();
        //libvlc_media_player_set_xwindow (vlcPlayer, windid );
          libvlc_media_player_set_xwindow();
        /* And play */
        libvlc_media_player_play(m_vlcMplay);
        //Set vars and text correctly
        //playBut->setText("Pause");
}
成功,既能访问本地,又能访问rtsp





三.将plugins libvlc.dl, libvlccore.dll放到debug

四.在qt.pro中添加库
LIBS += E:\qt\intel_cup\testVLC\testVLC\lib\libvlc.lib
LIBS += E:\qt\intel_cup\testVLC\testVLC\lib\libvlccore.lib
INCLUDEPATH += E:\qt\intel_cup\testVLC\testVLC\include
五.
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->m_vlcMedia =NULL;
    this->m_vlcMplay = NULL;
    currentWId = ui->widget->winId();
    const char*vlc_args[] ={"-I","dummy","--ignore-config","--extraintf=logger","--verbose=2",};
     m_vlcInst = libvlc_new( sizeof(vlc_args)/sizeof(vlc_args[0]),vlc_args );
    // m_vlcInst = libvlc_new(sizeof(m_vlcArgs)/sizeof(m_vlcArgs[0]),m_vlcArgs);
}
MainWindow::~MainWindow()
{
    delete ui;
    
}
void MainWindow::on_startButton_clicked()
{
 // const char*vlc_args[] ={"-I","dummy","--ignore-config","--extraintf=logger","--verbose=2",};
 //  m_vlcInst = libvlc_new( sizeof(vlc_args)/sizeof(vlc_args[0]),vlc_args );
    m_vlcMedia = libvlc_media_new_location(m_vlcInst,ui->UrlEdit->text().toLatin1());
    m_vlcMplay = libvlc_media_player_new_from_media(m_vlcMedia);
   // libvlc_media_player_set_drawable(m_vlcMplay, (libvlc_drawable_t)currentWId);
    libvlc_media_player_set_hwnd(m_vlcMplay,(void*)&currentWId);
    //播放
    libvlc_media_player_play(m_vlcMplay);
}
void MainWindow::on_closeButton_clicked()
{
    if(!m_vlcInst)
    {
        libvlc_release(m_vlcInst);
    }
    if(!m_vlcMedia)
    {
        libvlc_media_release(m_vlcMedia);
    }
    if(!m_vlcMplay)
    {
        libvlc_media_player_stop(m_vlcMplay);
    }
}
void MainWindow::on_pushButton_clicked()
{
    QString fileOpen = QFileDialog::getOpenFileName(this,tr("Load a file"), "~");
    fileOpen.replace("/", "\\"); //因为getOpenFileName得到的文件名是类//似于C:/Hello/test.avi,与windows下的路径名不匹配,所以需要这一步转换
        /* Stop if something is playing */
    //if(&& libvlc_media_player_is_playing(vlcPlayer) )
    //  stop();
        /* New Media */
        m_vlcMedia = libvlc_media_new_path(m_vlcInst,fileOpen.toLatin1());
        if( !m_vlcMedia )
            return;
        m_vlcMplay = libvlc_media_player_new_from_media(m_vlcMedia);
        libvlc_media_release(m_vlcMedia);
        /* Integrate the video in the interface */
    #if defined(Q_OS_MAC)
        libvlc_media_player_set_nsobject(vlcPlayer, videoWidget->winId());
    #elif defined(Q_OS_UNIX)
        libvlc_media_player_set_xwindow(vlcPlayer, videoWidget->winId());
    #elif defined(Q_OS_WIN)
        libvlc_media_player_set_hwnd(m_vlcMplay,(void*)&currentWId);
    #endif
        //int windid = videoWidget->winId();
        //libvlc_media_player_set_xwindow (vlcPlayer, windid );
          libvlc_media_player_set_xwindow();
        /* And play */
        libvlc_media_player_play(m_vlcMplay);
        //Set vars and text correctly
        //playBut->setText("Pause");
}
成功,既能访问本地,又能访问rtsp




0 0