代码拉取完成,页面将自动刷新
#pragma once
#include <QObject>
#include <QString>
#include <QMutex>
#include <QWidget>
// 避免 ssize_t 引发的错误
#if defined(_MSC_VER)
#include <basetsd.h>
typedef SSIZE_T ssize_t;
#endif
#include <vlc/vlc.h>
class VideoPlayer :public QObject
{
Q_OBJECT
public:
//播放状态
typedef enum state {
Idle,
Opening,
Buffering,
Playing,
Paused,
Stopped,
Ended,
Error
} State;
static VideoPlayer& getInstance();
static void release();
void setVideoWindow(QWidget* window);
VideoPlayer::State state();
friend void handleEvents(const libvlc_event_t* event, void* userData);
QString getTitle() const {
return titlestr;
}
int64_t getDur() const {
return dur;
}
int getSeek();
signals:
void durationChanged(qint64 dur);
void timeChanged(qint64 time);
void positionChanged(float pos);
void stateChanged(VideoPlayer::State state);
void xb_libvlc_wrong(QString msg);
public slots:
void openFile(const QString& file);
void setVolume(int vol);//设置音量
void seek(int pos);//跳播
void play();//播放
void pause();//暂停
void stop();//停止
private:
explicit VideoPlayer(QObject* parent = nullptr);
~VideoPlayer();
VideoPlayer(const VideoPlayer& other) = delete;
VideoPlayer& operator=(const VideoPlayer& other) = delete;
void attachEvents();//订阅事件
public:
QWidget* m_videoWindow = nullptr;
private:
QString titlestr;
int64_t dur;
libvlc_instance_t* m_instance = nullptr;
libvlc_media_player_t* m_player = nullptr;
libvlc_media_t* media = nullptr;
libvlc_event_manager_t* m_eventManager = nullptr;
VideoPlayer::State m_state = VideoPlayer::State::Idle;
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。