简介:QtMediaPlayer是一款基于Qt框架开发的多媒体播放器插件,支持多种音视频格式,提供灵活、高效的媒体控制功能。
在网上找到了一个旧版本的播放器,并对其进行了一天的修改和完善,现在已经可以运行了。希望与大家分享学习经验;不过遇到了一些问题:1、原本计划支持视频播放功能,但现在只能加载音频文件(mp3),一尝试加载视频就会卡死2. 自定义进度条不起作用,不知道为什么百分比槽连接不成功 connect(wmp, SIGNAL(PositionChange(double, double)),this, SLOT(Slot_onPositionChange(double, double)));3、我使用的是QAxWidget控件,请问这个是否只支持Windows系统呢?或者还有更好的选择?
项目名称:QT播放器 Qt Mediaplayer
工程师:枫儿
完成时间:2009年12月28日
#include playerwindow.h
#include
#include
#include
#include
#include
#include
#include
PlayerWindow::PlayerWindow()
{
setMouseTracking(true);
wmp = new QAxWidget(this); // 创建一个新的 QAxWidget 对象
wmp->setControl({22D6F312-B0F6-11D0-94AB-0080C74C7E95}); // 设置控件为 Windows Media Player 控件
connect(wmp, SIGNAL(PlayStateChange(int, int)),this, SLOT(Slot_onPlayStateChange(int, int)));
connect(wmp, SIGNAL(ReadyStateChange(ReadyStateConstants)),this, SLOT(Slot_onReadyStateChange(ReadyStateConstants)));
// 连接槽函数,处理播放位置变化
connect(wmp, SIGNAL(PositionChange(double, double)),this, SLOT(Slot_onPositionChange(double, double)));
openButton = new QPushButton(tr(&Open));
playPauseButton = new QPushButton(tr(&Play));
stopButton = new QPushButton(tr(&Stop));
// 连接槽函数,处理按钮点击事件
connect(openButton,SIGNAL(clicked()), this,SLOT(Slot_openFile()));
seekSlider = new QSlider(Qt::Horizontal, this);
seekSlider->setEnabled(false);
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addWidget(openButton);
buttonLayout->addWidget(playPauseButton);
buttonLayout->addWidget(stopButton);
QVBoxLayout *mainLayout = new QVBoxLayout(this); // 创建主布局
mainLayout->addWidget(wmp);
mainLayout->addLayout(buttonLayout);
mainLayout->addWidget(seekSlider);
setLayout(mainLayout);
}