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: ...
随机推荐
- postman环境变量配置的详细过程(步骤加截图)
环境变量的配置 实战:https://www.baidu.com/s?wd=博客园 使用cmd命令模式输入代码:Nslookup www.baidu.com 模拟环境:线上环境14.215.177.3 ...
- SpringCloud-OAuth2(二):实战篇
如果不了解Oauth2 是什么.工作流程的可以看我上一篇文章: SpringCloud-OAuth2(一):基础篇 这篇讲的内容是:Oauth2在SpringBoot/SpringCloud中的实战. ...
- Java课程设计-算术运算测试(D级) 齐鲁工业大学 计科20-1 王瀚垠 202003010033
Java课程设计-算术运算测试(D级) 齐鲁工业大学 计科20-1 王瀚垠 202003010033 目录 1.项目简介 2.项目采用技术 3.功能需求分析 4.项目亮点 5.项目功能架构图和UML类 ...
- [Azure DevOps] 如何使用任务组
1. 使用 PowerShell 脚本 在上一篇文章中我们学会了怎么使用扩展在编译前实时更改版本号.有些情况下我们希望不适用扩展,例如喜欢发明轮子,或者根本没有安装扩展的权限.这时候我们可以自己写 P ...
- MySQL 为什么使用 B+ 树来作索引?
什么是索引? 所谓的索引,就是帮助 MySQL 高效获取数据的排好序的数据结构.因此,根据索引的定义,构建索引其实就是数据排序的过程. 平时常见的索引数据结构有: 二叉树 红黑树 哈希表 B Tree ...
- 入门Kubernetes - YAML文件
前言 前篇文章中简单了解到如何把.Net Core 程序部署到k8s中,过程中使用了多个*.yaml文件,那么这些文件的格式及含义.语法是如何的呢? 接下来,进一步了解学习 一.YAML介绍: 1.简 ...
- C#WebApi的创建与发布
VS中新建项目-Web-ASP.NET Web应用程序 然后确定,选择空模版就可以了,勾上Webapi(也可以选择webapi模板,这样生成的文件比较多) 添加好之后Controllers和Model ...
- Golang写文件的坑
Golang写文件一般使用os.OpenFile返回文件指针的Write方法或者WriteString或者WriteAt方法,但是在使用这三个方法时候经常会遇到写入的内容和实际内容有出入,因为这几个函 ...
- Golang编写Windows动态链接库(DLL)及C调用范例
一.准备. 1.GoLang在1.10版本之后开始支持编译windows动态链接库,可以打开命令行工具使用go version 查看自己的go版本. 2.你的电脑上需要gcc,如果没有的话[点击这里] ...
- js笔记14
1.作用域面试题 画图分析 2.DOM document object model 节点树状图 document>documentElement>body>tagname 3.我们常 ...