程序示例精选
网易云音乐播放器
如需安装运行环境或远程调试,见文章底部个人QQ名片,由专业技术人员远程协助!
前言
这篇博客针对《网易云音乐播放器》编写代码,代码整洁,规则,易读。 学习与应用推荐首选。
运行结果
文章目录
一、所需工具软件
二、使用步骤
1. 主要代码
2. 运行结果
三、在线协助
一、所需工具软件
1. VS2019, Qt
2. C++
二、使用步骤
代码如下(示例):
#include "NetEasyMusicPlayer.h"
#include "mypyvirtualbox.h"
#include "NetEasyModual.h"
#include <QMessageBox>
#include <QtCore>
#include <QFileInfo>
NetEasyMusicPlayer::NetEasyMusicPlayer(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
m_selectIndex = -1;
m_musicmodel = new QStandardItemModel(ui.tableView);
m_player = new QMediaPlayer(this);
connect(ui.tableView, &QTableView::doubleClicked, this, &NetEasyMusicPlayer::slotDoubleClicked);
connect(ui.tableView, &QTableView::clicked, this, &NetEasyMusicPlayer::slotClicked);
setWindowTitle(QString::fromLocal8Bit("网易云音乐播放器"));
auto box = MyPyVirtualBox::getInstance();
auto bindTable = [=]() {
m_musicmodel->clear();
QStringList headers = QStringList() << QStringLiteral("音乐ID") << QStringLiteral("音乐名称") << QStringLiteral("歌手ID") << QStringLiteral("歌手名称")
<< QStringLiteral("下载地址") << QStringLiteral("音乐封面");
m_musicmodel->setHorizontalHeaderLabels(headers); //设置列头
ui.tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
ui.tableView->horizontalHeader()->setStyleSheet("QHeaderView::section{color:#800080;}");
};
QFileInfo info("2884035.json");
if (info.exists())
{
//如果存在JSON文件就使用JSON的数据
NetEasyModual mo;
datalist = mo.getToplistData("2884035.json");
//for (int i = 0; i < datalist.size(); i++)
//{
// auto item = datalist.at(i);
// QString strItem = QString::fromStdString(item);
// qDebug() << strItem;
//}
bindTable();
}
connect(ui.pushButton, &QPushButton::clicked, this, [=]() {
NetEasyModual mo;
/*mo.sayHello();*/
datalist = mo.cacheAndGetToplistData("http://music.163.com/api/playlist/detail?id=2884035");
if (datalist.size() <= 1)
{
QMessageBox::information(NULL, QString::fromLocal8Bit("请重试!"), QString::fromLocal8Bit("服务器繁忙,请重试!"));
return;
}
binTable();
});
connect(ui.pushButton_download, &QPushButton::clicked, this, [=]() {
qDebug() << "download click";
if (m_selectIndex == -1)
{
QMessageBox::information(NULL, QString::fromLocal8Bit("SORRY!"), QString::fromLocal8Bit("请选好歌在下载!"));
return;
}
auto s = datalist.at(m_selectIndex);
QStringList row = QString::fromStdString(s).split(QString(','));
QString songname = row[1];
QString songid = row[0];
qDebug() << songname << songid;
auto songfile = QString("./mp3/%1.mp3").arg(songid);
qDebug() << songfile;
QFileInfo info(songfile);
if (info.exists())
{
QMessageBox::information(NULL, QString::fromLocal8Bit("SORRY!"), QString::fromLocal8Bit("此MP3已经缓存直接播放即可!"));
return;
}
NetEasyModual mo;
if (mo.downloadMp3(songid.toStdString()))
{
qDebug() << "downoad!";
QMessageBox::information(NULL, QString::fromLocal8Bit("Download!"), QString::fromLocal8Bit("此MP3下载成功!"));
return;
}
else
{
QMessageBox::information(NULL, QString::fromLocal8Bit("Sorry!"), QString::fromLocal8Bit("下载失败!"));
return;
}
});
auto s = datalist.at(m_selectIndex);
QStringList row = QString::fromStdString(s).split(QString(','));
QString songname = row[1];
QString songid = row[0];
qDebug() << songname << songid;
auto songfile = QString("./mp3/%1.mp3").arg(songid);
qDebug() << songfile;
QFileInfo info(songfile);
if (info.exists())
{
m_player->setMedia(QUrl::fromLocalFile(songfile));
m_player->play();
}
else
{
QMessageBox::information(NULL, QString::fromLocal8Bit("Sorry!"), QString::fromLocal8Bit("MP3不存在请下载!"));
return;
});
connect(ui.pushButton_stop, &QPushButton::clicked, this, [=]() {
m_player->stop();
});
}
运行结果
三、在线协助:
如需安装运行环境或远程调试,见文章底部个人 QQ 名片,由专业技术人员远程协助!
1)远程安装运行环境,代码调试
2)Visual Studio, Qt, C++, Python编程语言入门指导
3)界面美化
4)软件制作
5)云服务器申请
6)网站制作
当前文章连接:https://blog.csdn.net/alicema1111/article/details/132666851
个人博客主页:https://blog.csdn.net/alicema1111?type=blog
博主所有文章点这里:https://blog.csdn.net/alicema1111?type=blog
博主推荐:
Python人脸识别考勤打卡系统:
https://blog.csdn.net/alicema1111/article/details/133434445
Python果树水果识别:https://blog.csdn.net/alicema1111/article/details/130862842
Python+Yolov8+Deepsort入口人流量统计:https://blog.csdn.net/alicema1111/article/details/130454430
Python+Qt人脸识别门禁管理系统:https://blog.csdn.net/alicema1111/article/details/130353433
Python+Qt指纹录入识别考勤系统:https://blog.csdn.net/alicema1111/article/details/129338432
Python Yolov5火焰烟雾识别源码分享:https://blog.csdn.net/alicema1111/article/details/128420453
Python+Yolov8路面桥梁墙体裂缝识别:https://blog.csdn.net/alicema1111/article/details/133434445