Qt+MPlayer音乐播放器开发笔记(一):ubuntu上编译MPlayer以及Demo演示
前言
在ubuntu上实现MPlayer播放器播放音乐。
Demo
Mplayer
MPlayer是一款开源多媒体播放器,以GNU通用公共许可证发布。此款软件可在各主流操作系统使用,例如Linux和其他类Unix系统、Windows及Mac OS X系统。
MPlayer基于命令行界面,在各操作系统也可选择安装不同的图形界面。mplayer的另一个大的特色是广泛的输出设备支持。它可以在X11、Xv、DGA、OpenGL、SVGAlib、fbdev、AAlib、DirectFB下工作,且能使用GGI和SDL和一些低级的硬件相关的驱动模式(比如Matrox、3Dfx和Radeon、Mach64、Permedia3)。MPlayer还支持通过硬件MPEG解码卡显示,如DVB 和DXR3与Hollywood+。
MPlayer的开发始于2000年。最初的作者是 Arpad Gereoffy。MPlayer最初的名字叫"MPlayer - The Movie Player for Linux",不过后来开发者们简称其为"MPlayer - The Movie Player",原因是MPlayer已经不仅可以用于Linux而可以在所有平台上运行。
下载
最新源码下载地址: http://mplayerhq.hu/design7/news-archive.html
QQ群:1047134658(点击“文件”搜索“MPlayer”,群内与博文同步更新)
Ubuntu编译
步骤一:下载解压
tar xvf MPlayer-1.4.tar.xz
步骤二:configure
cd MPlayer-1.4/
./configure
./configure --yasm=’’
步骤三:make,需要zlib库支撑,编译zlib库
make
需要编译zlib库,需要先编译,请参照博文《libzip开发笔记(二):libzip库介绍、ubuntu平台编译和工程模板》。
sudo ldconfig
步骤四:继续编译make
make
步骤五:安装sudo make install
sudo make install
步骤六:播放测试
(注意:若是虚拟机,虚拟机的音量和选用主机的声卡需要选择下)
Demo
Widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QMainWindow>
#include <QThread>
#include "MplayerManager.h"
#include <QFileDialog>
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
protected:
void initControls();
protected slots:
void slot_durationChanged(int duration);
void slot_positionChanged(int position);
void slot_finished();
void slot_mediaInfo(MplayerManager::MediaInfo mediaInfo);
private slots:
void on_pushButton_startPlay_clicked();
void on_pushButton_stopPlay_clicked();
void on_pushButton_pausePlay_clicked();
void on_pushButton_resume_clicked();
void on_horizontalSlider_sliderReleased();
void on_horizontalSlider_valueChanged(int value);
void on_pushButton_mute_clicked(bool checked);
void on_horizontalSlider_position_sliderReleased();
void on_horizontalSlider_position_sliderPressed();
void on_pushButton_browserMplayer_clicked();
void on_pushButton_defaultMplayer_clicked();
void on_pushButton_browserMusic_clicked();
private:
Ui::Widget *ui;
QThread *_pMplayerManagerThread;
MplayerManager *_pMplayerManager;
bool _sliderPositionPressed;
};
#endif // WIDGET_H
Widget.cpp
#include "Widget.h"
#include "ui_Widget.h"
#include "MplayerManager.h"
#include <QDebug>
#define LOG qDebug()<<__FILE__<<__LINE__
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget),
_pMplayerManagerThread(0),
_pMplayerManager(0),
_sliderPositionPressed(false)
{
ui->setupUi(this);
QString version = "v1.0.0";
setWindowTitle(QString("mplayer播放器 %1 (长沙红胖子网络科技有限公司 QQ:21497936 微信:yangsir198808 公司网址: hpzwl.blog.csdn.net)").arg(version));
// 初始化modbus线程
_pMplayerManagerThread = new QThread();
_pMplayerManager = new MplayerManager();
_pMplayerManager->moveToThread(_pMplayerManagerThread);
QObject::connect(_pMplayerManagerThread, SIGNAL(started()),
_pMplayerManager, SLOT(slot_start()));
connect(_pMplayerManager, SIGNAL(signal_durationChanged(int)),
this, SLOT(slot_durationChanged(int)));
connect(_pMplayerManager, SIGNAL(signal_positionChanged(int)),
this, SLOT(slot_positionChanged(int)));
connect(_pMplayerManager, SIGNAL(signal_mediaInfo(MplayerManager::MediaInfo)),
this, SLOT(slot_mediaInfo(MplayerManager::MediaInfo)));
connect(_pMplayerManager, SIGNAL(signal_finished()),
this, SLOT(slot_finished()));
_pMplayerManagerThread->start();
initControls();
}
Widget::~Widget()
{
delete ui;
}
void Widget::initControls()
{
ui->horizontalSlider->setMinimum(0);
ui->horizontalSlider->setMaximum(100);
ui->horizontalSlider->setValue(100);
ui->label_volume->setText("100");
}
void Widget::slot_durationChanged(int duration)
{
LOG << duration;
ui->label_duration->setText(QString("%1%2:%3%4")
.arg(duration / 60 / 10)
.arg(duration / 60 % 10)
.arg(duration % 60 / 10)
.arg(duration % 10));
ui->horizontalSlider_position->setMinimum(0);
ui->horizontalSlider_position->setMaximum(duration);
}
void Widget::slot_positionChanged(int position)
{
ui->label_position->setText(QString("%1%2:%3%4")
.arg(position / 60 / 10)
.arg(position / 60 % 10)
.arg(position % 60 / 10)
.arg(position % 10));
if(!_sliderPositionPressed)
{
ui->horizontalSlider_position->setValue(position);
}
}
void Widget::slot_finished()
{
ui->label_position->setText("00:00");
}
void Widget::slot_mediaInfo(MplayerManager::MediaInfo mediaInfo)
{
ui->label_title->setText(mediaInfo.title);
ui->label_album->setText(mediaInfo.album);
ui->label_year->setText(mediaInfo.year);
ui->label_artist->setText(mediaInfo.artist);
ui->label_genre->setText(mediaInfo.genre);
ui->label_comment->setText(mediaInfo.comment);
}
void Widget::on_pushButton_startPlay_clicked()
{
_pMplayerManager->startPlay();
}
void Widget::on_pushButton_stopPlay_clicked()
{
_pMplayerManager->stopPlay();
}
void Widget::on_pushButton_pausePlay_clicked()
{
_pMplayerManager->pausePlay();
}
void Widget::on_pushButton_resume_clicked()
{
_pMplayerManager->resumePlay();
}
void Widget::on_horizontalSlider_sliderReleased()
{
_pMplayerManager->setVolume(ui->horizontalSlider->value());
}
void Widget::on_horizontalSlider_valueChanged(int value)
{
ui->label_volume->setText(QString("%1").arg(value));
}
void Widget::on_pushButton_mute_clicked(bool checked)
{
_pMplayerManager->setMute(checked);
}
void Widget::on_horizontalSlider_position_sliderReleased()
{
_sliderPositionPressed = false;
_pMplayerManager->setPosition(ui->horizontalSlider_position->value());
}
void Widget::on_horizontalSlider_position_sliderPressed()
{
_sliderPositionPressed = true;
}
void Widget::on_pushButton_browserMplayer_clicked()
{
_pMplayerManager->setMplayerPath(ui->lineEdit_mplayer->text());
}
void Widget::on_pushButton_defaultMplayer_clicked()
{
ui->lineEdit_mplayer->setText("mplayer");
}
void Widget::on_pushButton_browserMusic_clicked()
{
QString dir = ui->lineEdit_music->text();
dir = dir.mid(0, dir.lastIndexOf("/"));
QString filePath = QFileDialog::getOpenFileName(0,
"open",
dir,
"AAC(*.aac)"
";;MP3(*.mp3)"
";;WAV(*.wav)"
";;WMA(*.wma)");
if(filePath.isEmpty())
{
return;
}
ui->lineEdit_music->setText(filePath);
_pMplayerManager->setFilePath(filePath);
}
MplayerManager.h
#ifndef MPLAYERMANAGER_H
#define MPLAYERMANAGER_H
/************************************************************\
* 控件名称: mplayer管理类
* 控件描述:
* 使用slave模式控制mplayer播放音乐,基础模块实现单曲播放
* 控件功能:
* 1.音乐播放器播放音乐的基础操作
* 2.可以获取歌曲的相关专辑,作者,年代,评论,流派等信息
* 著作权信息
* 作者:红胖子(AAA红模仿)
* 公司:长沙红胖子网络科技有限公司
* 网址:hpzwl.blog.csdn.net
* 联系方式:QQ(21497936) 微信(yangsir198808) 电话(15173255813)
* 版本信息
* 日期 版本 描述
* 2021年07月12日 v1.0.0 基础模板
\************************************************************/
#include <QObject>
#include <QThread>
#include <QProcess>
#include <QtMath>
#include <QTextCodec>
class MplayerManager : public QObject
{
Q_OBJECT
public:
enum PLAY_STATE { // 播放状态
PLAY_STATE_STOP = 0x00, // 未播放,停止播放
PLAY_STATE_PLAY, // 正在播放
PLAY_STATE_PAUSE // 暂停播放
};
struct MediaInfo { // 多媒体信息
MediaInfo() {}
QString title; // 标题
QString artist; // 艺术家
QString album; // 专辑
QString year; // 年代
QString comment; // 评论
QString genre; // 流派
};
public:
explicit MplayerManager(QObject *parent = 0);
~MplayerManager();
public:
QString getMplayerPath() const; // 获取播放器路径(运行则可调用)
QString getFilePath() const; // 获取当前播放文件路径
bool getMute() const; // 获取是否静音
int getVolume() const; // 获取音量
int getPosition() const; // 获取当前位置
public:
void setMplayerPath(const QString &mplayerPath); // 设置播放器路径
void setFilePath(const QString &filePath); // 设置播放文件
void setMute(bool mute); // 设置静音
void setVolume(int volume); // 设置音量(0~100)
void setPosition(int position); // 设置当前播放位置
signals:
void signal_stateChanged(PLAY_STATE playState); // 播放器播放状态信号
void signal_durationChanged(int duration); // 播放歌曲长度变换信号
void signal_positionChanged(int value); // 播放器歌曲位置比变换,1s一次
void signal_finished(); // 播放完成信号
void signal_mediaInfo(MplayerManager::MediaInfo mediaInfo); // 播放歌曲时,获取的各种元信息
public:
void startPlay(QString filePath); // 播放指定歌曲(调用后,或发送消息给播放线程,
// 以下4个函数同样,本质调用了slo_xxxx
void startPlay(); // 播放歌曲
void pausePlay(); // 暂停播放
void resumePlay(); // 恢复播放
void stopPlay(); // 停止播放
public slots:
void slot_start(); // 线程开启(需要外部管理QThread)
void slot_stop(); // 线程停止
void slot_startPlay(); // 开始播放
void slot_pausePlay(); // 暂停播放
void slot_resumePlay(); // 恢复播放
void slot_stopPlay(); // 停止播放
void slot_setPosition(int position); // 设置位置
void slot_setVolume(int volume); // 设置音量
void slot_setMute(bool mute); // 设置静音
void slot_getCurrentPosition(); // 获取当前位置(调用后,会强制立即抛出当前播放位置信号)
protected slots:
void slot_readyRead();
void slot_finished(int exitCode, QProcess::ExitStatus exitStatus);
protected:
void timerEvent(QTimerEvent *event);
private:
bool _runnig; // 是否运行
QProcess *_pProcess; // 进程控制
QTextCodec *_pTextCodec; // 编码
private:
QString _filePath; // 播放文件路径
QString _mplayerPath; // mplayer执行程序
private:
PLAY_STATE _playState; // 当前播放状态
int _position; // 当前播放位置,单位s
bool _mute; // 是否静音
int _volume; // 当前音量0~100
int _duration; // 当前歌曲的长度,单位s
int _timerId; // 定时器,获取当前播放时间
MediaInfo _mediaInfo; // 播放歌曲时候的媒体信息
};
#endif // MPLAYERMANAGER_H
工程模板
mplayerDemo_基础模板_v1.0.0.rar
若该文为原创文章,转载请注明原文出处
本文章博客地址:https://hpzwl.blog.csdn.net/article/details/118713520
Qt+MPlayer音乐播放器开发笔记(一):ubuntu上编译MPlayer以及Demo演示的更多相关文章
- android音乐播放器开发教程
android音乐播放器开发教程 Android扫描sd卡和系统文件 Android 关于录音文件的编解码 实现米聊 微信一类的录音上传的功能 android操作sdcard中的多媒体文件——音乐列表 ...
- 仿酷狗音乐播放器开发日志十九——CTreeNodeUI的bug修复二(附源码)
转载请说明原出处,谢谢 今天本来打算把仿酷狗播放列表的子控件拖动插入功能做一下,但是仔细使用播放列表控件时发现了几个逻辑错误,由于我的播放 列表控件是基于CTreeViewUI和CTreeNodeUI ...
- 仿酷狗音乐播放器开发日志二十四 选项设置窗体的实现(附328行xml布局源码)
转载请说明原出处,谢谢~~ 花了两天时间把仿酷狗的选项设置窗体做出来了,当然了只是做了外观.现在开学了,写代码的时间减少,所以整个仿酷狗的工程开发速度减慢了.今天把仿酷狗的选项设置窗体的布局代码分享出 ...
- Android音乐播放器开发
今日看书,看到这个播放器,我就写了个例子,感觉还行,这个播放器能播放后缀是.MP3的音乐,这个例子在main.xml设置listView的时候,注意:android:id="@+id/and ...
- Redrain仿酷狗音乐播放器开发完毕,发布测试程序
转载请说明原出处,谢谢~~ 从暑假到现在中秋刚过,我用duilib开发仿酷狗播放器大概经历了50天.做仿酷狗的意图只是看原酷狗的界面比较漂亮,想做个完整一些的工程来练习一下duilib.今天把写好的程 ...
- 仿酷狗音乐播放器开发日志二十七 用ole为窗体增加文件拖动功能(附源码)
转载请说明原出处,谢谢~~ 中秋到了,出去玩了几天.今天把仿酷狗程序做了收尾,已经开发完成了,下一篇博客把完结的情况说一下.在这篇博客里说一下使用OLE为窗体增加文件拖拽的功能.使用播放器,我更喜欢直 ...
- android音乐播放器开发 SweetMusicPlayer 播放本地音乐
上一篇写了载入歌曲列表,http://blog.csdn.net/huweigoodboy/article/details/39856411,如今来总结下播放本地音乐. 一,MediaPlayer 首 ...
- android音乐播放器开发 SweetMusicPlayer 实现思路
一,实现效果 眼下还不是特别完好,主要有下面几个功能, 1,载入歌曲列表(实现a-z字母检索) 2,播放本地音乐 3.智能匹配本地歌词 4.智能载入在线歌词(事实上不算智能.发现歌词迷api提供的歌词 ...
- android音乐播放器开发 SweetMusicPlayer 载入歌曲列表
上一篇写了播放器的总体实现思路,http://blog.csdn.net/huweigoodboy/article/details/39855653,如今来总结下载入歌曲列表. 代码地址:https: ...
随机推荐
- 车联网V-2X智能汽车驾驶
车联网V-2X智能汽车驾驶 早期的功能互联汽车无法满足全球车主针对不同应用和定制移动服务的各种需求.这导致较低的客户续订率,较高的建造和运营成本以及较低的组装率.通常,在没有统一平台的情况下,不同的车 ...
- H265与ffmpeg改进开发
H265与ffmpeg改进开发 1. Introduction KSC265是集编码.解码于一体的H.265编解码软件,完全遵循H.265协议标准.符合H.265编码规范的视频都可以通过KSC265进 ...
- 像Swing这种已经不太用的技术,大学还在教,到底要不要学?
一直以来,写日常问题.前沿技术和架构思考类的文章比较多,今天为什么突然来说说Swing这个陈年老技术呢? 因为在CSDN上看到了这样的一篇文章: 可以看到作者对于学Swing还是挺愤怒的,不过确实Sw ...
- Task02:基础查询与排序
2.1 SELECT语句基础 2.1.1 从表中选取数据 SELECT语句 从表中选取数据时需要使用SELECT语句,也就是只从表中选出(SELECT)必要数据的意思.通过SELECT语句查询并选取出 ...
- 代码生成器:IDEA 强大的 Live Templates
前言 Java 开发过程经常需要编写有固定格式的代码,例如说声明一个私有变量,logger或者bean等等.对于这种小范围的代码生成,我们可以利用 IDEA 提供的 Live Templates功能. ...
- 玩转STM32MP157-开发环境搭建
(一)STM32MP 1.什么是 STM32MPU STM32MPU是 ST 推出的 Cortex-A7 + Cortex-M4 多核异构处理器 STM32MPU151 是单核 A7+M4,.STM3 ...
- Linux 从头学 01:CPU 是如何执行一条指令的?
作 者:道哥,10+年的嵌入式开发老兵. 公众号:[IOT物联网小镇],专注于:C/C++.Linux操作系统.应用程序设计.物联网.单片机和嵌入式开发等领域. 公众号回复[书籍],获取 Linux. ...
- 升级openssl并重新编译Nginx
在漏洞扫描的时候出现"启用TLS1.0"的安全漏洞,描述为:不被视为 PCI 数据安全标准,推荐使用TLS1.2及以上版本: 我这边服务器使用的是CentOS7,默认自带的open ...
- 34、mysql数据库(介绍)
34.1.什么是数据库: 数据库(database,DB)是指长期存储在计算机内的,有组织,可共享的数据的集合.数据库中的数据按一定的数学模型组织. 描述和存储,具有较小的冗余,较高的数据独立性和易扩 ...
- [心得笔记]spring常用的三种依赖注入方式
一.目前使用最广泛的 @Autowired:自动装配 基于@Autowired的自动装配,默认是根据类型注入,可以用于构造器.接口.方法注入,使用方式如下: @Autowired 构造方法.方法.接口 ...