哪个网站可以做信用社的题,石家庄好用的招聘网站,网站经常被攻击,涉县做网站1.简介
LibVLC是一个强大的开源库#xff0c;它构成了VLC媒体播放器的核心部分。
LibVLC提供了一系列的功能接口#xff0c;使得VLC能够处理流媒体的接入、音频和视频输出、插件管理以及线程系统等核心任务。
跨平台性#xff1a;VLC作为一个跨平台的多媒体播放器#x…1.简介
LibVLC是一个强大的开源库它构成了VLC媒体播放器的核心部分。
LibVLC提供了一系列的功能接口使得VLC能够处理流媒体的接入、音频和视频输出、插件管理以及线程系统等核心任务。
跨平台性VLC作为一个跨平台的多媒体播放器可以运行在多种操作系统和计算机体系结构上。协议支持LibVLC不仅支持播放本地视频文件还支持播放基于各种流媒体协议如RTMP、RTSP的视频。API一致性在不同操作系统下如Linux和WindowsLibVLC提供的API基本一致这为开发者跨平台开发提供了便利。扩展性VLC作为一个流媒体服务器和多媒体框架是可扩展的能够通过LibVLC提供的API接口添加新组件和功能。
2.环境搭建
下载地址Index of /pub/videolan/vlc/last/
我这里使用的是64位的库。 下载完成解压文件。
主要需要plugins文件和sdk路径下的lib和include目录。 新建vs工程新建目录3rd将sdk路径下的lib和include目录复制到3rd目录下。 配置包含目录和库目录如下图所示。 至此开发环境已经搭建好了。
3.常用接口
LibVLC提供了一系列接口用于实现多媒体播放和管理功能。以下是一些常用的接口及其作用
libvlc_new - 创建一个新的libVLC实例。libvlc_release - 释放libVLC实例。libvlc_media_player_new - 创建一个新的媒体播放器对象。libvlc_media_player_release - 释放媒体播放器对象。libvlc_media_new_path / libvlc_media_new_location - 从本地文件路径或网络位置创建媒体对象。libvlc_media_release - 释放媒体对象。libvlc_media_player_set_media - 将媒体对象与播放器关联。libvlc_media_player_play - 开始播放媒体。libvlc_media_player_pause - 暂停播放。libvlc_media_player_stop - 停止播放。libvlc_media_player_set_hwnd - 设置视频输出窗口适用于Windows。libvlc_media_player_get_time - 获取当前播放时间。libvlc_media_player_set_time - 设置播放位置时间。libvlc_media_player_get_length - 获取媒体的长度。libvlc_media_player_get_state - 获取当前播放器状态。libvlc_audio_set_volume - 设置音量。libvlc_audio_get_volume - 获取音量。libvlc_media_player_is_playing - 检查媒体是否正在播放。libvlc_media_parse - 解析媒体以获取更多信息如元数据、跟踪信息等。
4.示例 #pragma once#include QtWidgets/QWidget
#include ui_showWidget.h
#include QMenu
#include QActionGroup
#include vlc/vlc.h
#include QDebug
#include QFileDialog
#include QThreadclass showWidget : public QWidget
{Q_OBJECTpublic:showWidget(QWidget *parent nullptr);~showWidget();private slots:void slotOpenFile();void slotPlay();private:static void vlcEvents(const libvlc_event_t *ev, void *param);private:Ui::showWidgetClass ui;private:libvlc_instance_t *vlc_base nullptr;libvlc_media_t *vlc_media nullptr;libvlc_media_player_t *vlc_mediaPlayer nullptr;QActionGroup *m_TimeSpeedGrp nullptr;QMenu m_SpeedMenu;static showWidget *pThis;
};#include showWidget.h
#include QTimer#pragma execution_character_set(utf-8)showWidget* showWidget::pThis nullptr;showWidget::showWidget(QWidget *parent): QWidget(parent)
{ui.setupUi(this);this-setWindowTitle(视频播放器);connect(ui.btnOpen, QPushButton::clicked, this, showWidget::slotOpenFile);connect(ui.btnPlay, QPushButton::clicked, this, showWidget::slotPlay);
}showWidget::~showWidget()
{libvlc_release(vlc_base); //减少libvlc实例的引用计数并销毁
}void showWidget::slotOpenFile()
{/*选择文件*/QString filename QFileDialog::getOpenFileName(this, 选择打开的文件, D:/, tr(*.*));std::replace(filename.begin(), filename.end(), QChar(/), QChar(\\));vlc_base libvlc_new(0, NULL);vlc_media libvlc_media_new_path(vlc_base, filename.toUtf8().data());if (!vlc_media) {return;}vlc_mediaPlayer libvlc_media_player_new_from_media(vlc_media);if (!vlc_mediaPlayer) {return;}libvlc_media_parse(vlc_media);libvlc_event_manager_t *em libvlc_media_player_event_manager(vlc_mediaPlayer);libvlc_event_attach(em, libvlc_MediaPlayerTimeChanged, vlcEvents, this);libvlc_event_attach(em, libvlc_MediaPlayerEndReached, vlcEvents, this);libvlc_event_attach(em, libvlc_MediaPlayerStopped, vlcEvents, this);libvlc_event_attach(em, libvlc_MediaPlayerPlaying, vlcEvents, this);libvlc_event_attach(em, libvlc_MediaPlayerPaused, vlcEvents, this);libvlc_media_player_set_hwnd(vlc_mediaPlayer, (void *)ui.widgetShow-winId());QTimer::singleShot(1000, this, showWidget::slotPlay);
}void showWidget::slotPlay()
{libvlc_media_player_play(vlc_mediaPlayer);
}void showWidget::vlcEvents(const libvlc_event_t *ev, void *param)
{qint64 pos;switch (ev-type) {case libvlc_MediaPlayerTimeChanged:qDebug() VLC媒体播放器时间已更改;break;case libvlc_MediaPlayerEndReached:qDebug() VLC播放完毕.;break;case libvlc_MediaPlayerStopped:qDebug() VLC停止播放;break;case libvlc_MediaPlayerPlaying:qDebug() VLC开始播放;break;case libvlc_MediaPlayerPaused:qDebug() VLC暂停播放;break;}
}编译好的程序需要把plugins目录和动态库拷贝到运行目录才能够运行。