#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
ui->search_edit->setPlaceholderText("鼓楼-赵雷");
setFixedSize(1024,610);
setButtonImage(ui->search, ":/image/search.png"); //设置按钮图标
setButtonImage(ui->play,":/image/play.png");
setButtonImage(ui->last,":/image/last.png");
setButtonImage(ui->next,":/image/next.png");
setButtonImage(ui->download,":/image/download.png");
setButtonImage(ui->playlist,":/image/playlist.png",25);
setButtonImage(ui->all_circle,":/image/all_circle.png");
setButtonImage(ui->valum,":/image/valum.png",25);
setButtonImage(ui->setting,":/image/setting.png");
setButtonImage(ui->all_screen,":/image/all_screen.png");
setButtonImage(ui->open,":/image/open.png");
player=new QMediaPlayer;
playlist=new QMediaPlaylist;
playlist->setPlaybackMode(QMediaPlaylist::Loop); //设置默认播放模式
local_list=new QMediaPlaylist;
onlien=new online_play;
ui->background->setFixedSize(1024,610);
ui->lyrics_area->setFrameShape(QFrame::NoFrame);
ui->play_list_area->setFrameShape(QFrame::NoFrame);
ui->lyrics->setFrameShape(QFrame::NoFrame);
qDebug()<<"QSslSocket="<<QSslSocket::sslLibraryBuildVersionString();
qDebug() << "OpenSSL支持情况:" << QSslSocket::supportsSsl();
http_acc = new QNetworkAccessManager;
connect(http_acc,SIGNAL(finished(QNetworkReply*)),this,SLOT(recv(QNetworkReply*))); //收到信息后进行json解析
connect(onlien,SIGNAL(searchFinal(int,int,int,QString,QString,QString,int)),this,SLOT(init_playlist(int,int,int,QString,QString,QString,int)));
connect(ui->search_combbox,SIGNAL(currentTextChanged(QString)),ui->search_edit,SLOT(setText(QString))); //设置搜索框内容
connect(ui->search_combbox,SIGNAL(currentIndexChanged(int)),this,SLOT(change_play_id(int))); //从搜索框中获取歌曲
connect(player,SIGNAL(durationChanged(qint64)),this,SLOT(set_toltaltime(qint64))); //设置总播放时长
connect(player,SIGNAL(positionChanged(qint64)),this,SLOT(set_currenttime(qint64))); //设置当前播放时间
connect(ui->horizontalSlider_2,SIGNAL(valueChanged(int)),player,SLOT(setVolume(int))); //调整音量
connect(ui->playrate,SIGNAL(currentTextChanged(QString)),this,SLOT(set_playrate(QString))); //调整播放倍速
}
Widget::~Widget()
{
delete ui;
}
void Widget::setButtonImage(QPushButton *button, QString image,int size) //设置按钮图标
{
button->setText("");
QPixmap pixmap(image);
QPixmap fitpixmap = pixmap.scaled(size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
button->setIcon(QIcon(fitpixmap));
button->setIconSize(QSize(30, 30));
button->setFlat(true);
button->setStyleSheet("border: 0px"); //消除边框
}
void Widget::on_search_clicked() //点击搜索按钮
{
//发送一个http请求
QString str;
str=QString("https://music.cyrilstudio.top/search?keywords=%0").arg(ui->search_edit->text());
// qDebug()<<"结果"<<str;
QNetworkRequest request;
request.setUrl(QString(str));
http_acc->get(request);
}
void Widget::on_play_clicked() //点击播放按钮
{
if(QMediaPlayer::StoppedState==player->state()||player->state()==QMediaPlayer::PausedState) //如果是停止状态或暂停就播放
{
setButtonImage(ui->play,":/image/pause.png");
player->play();
}
else if(QMediaPlayer::PlayingState==player->state()) //如果是播放状态就暂停
{
setButtonImage(ui->play,":/image/play.png");
player->pause();
}
for(int i=0;i<music_all_msg.length();i++)
ui->lyrics->append(music_all_msg.at(i));
}
void Widget::recv(QNetworkReply* r) //
{
onlien->recv_ack(r);
}
void Widget::init_playlist(int number,int musicId,int mvId,QString musicName,QString singerName,QString albumName,int musicDuration) //初始化播放器
{
QString url;
url=QString("https://music.163.com/song/media/outer/url?id=%0").arg(musicId);
int secs =musicDuration/1000;
int mins = secs/60;
secs = secs%60;
QString musictime=QString::asprintf("%d分%d秒",mins,secs);
music_msg.push_back("正在播放:"+singerName+"-"+musicName);
music_all_msg.push_back(" "+musicName+" - "+singerName+" - "+albumName);
totalTime = QString::asprintf("%d分%d秒",mins,secs); // 总时长
QString str=singerName+"-"+musicName;
ui->search_combbox->addItem(str);
playlist->addMedia(QUrl(url)); //添加一音乐到播放列表中
player->setPlaylist(playlist); //将playlist设置为当前播放列表
player->setMedia(playlist); //将列表设置到播放器中
}
void Widget::change_play_id(int index) //当点击搜索框中的歌曲时自动播放
{
playlist->setCurrentIndex(index);
if(QMediaPlayer::StoppedState==player->state()||QMediaPlayer::PausedState==player->state())
{
player->play();
}
ui->currentmusic->setText(music_msg.at(index));
}
void Widget::on_next_clicked() //下一曲
{
play_index=playlist->currentIndex();
play_index++;
playlist->setCurrentIndex(play_index);
ui->currentmusic->setText(music_msg.at(play_index));
}
void Widget::on_last_clicked() //上一曲
{
play_index=playlist->currentIndex();
play_index--;
playlist->setCurrentIndex(play_index);
ui->currentmusic->setText(music_msg.at(play_index));
}
void Widget::set_toltaltime(qint64 time)
{
int secs =time/1000;
int mins = secs/60;
secs = secs%60;
ui->totaltime->setText(QString::asprintf("%d分%d秒",mins,secs));
ui->horizontalSlider->setMaximum(time);
}
void Widget::set_currenttime(qint64 time)
{
int secs =time/1000;
int mins = secs/60;
secs = secs%60;
ui->currenttime->setText(QString::asprintf("%d分%d秒",mins,secs));
ui->horizontalSlider->setValue(time); //设置进度条
}
void Widget::on_valum_clicked() //设置静音
{
if(player->isMuted())
{
player->setMuted(false);
setButtonImage(ui->valum,":/image/valum.png",25);
}
else
{
player->setMuted(true);
setButtonImage(ui->valum,":/image/mute.png",25);
}
}
void Widget::on_open_clicked() //播放本地音乐
{
QStringList path;
path=QFileDialog::getOpenFileNames(this,"选择音乐",".","Music (*.mp3)");
for(int i=0;i<path.count();i++)
{
local_list->addMedia(QUrl::fromLocalFile(path.at(i))); //将本地音乐添加到本地播放列表
locl_music_msg.push_back(path.at(i));
}
player->setPlaylist(local_list);
player->setMedia(local_list);
}
void Widget::set_playrate(QString text)
{
player->setPlaybackRate(text.toDouble());
}
void Widget::on_all_circle_clicked()
{
if(QMediaPlaylist::Loop==playlist->playbackMode())
{
playlist->setPlaybackMode(QMediaPlaylist::CurrentItemInLoop); //设置为单曲循环播放
setButtonImage(ui->all_circle,":/image/sigle_circle.png");
}
else if(QMediaPlaylist::CurrentItemInLoop==playlist->playbackMode())
{
playlist->setPlaybackMode(QMediaPlaylist::Random); //设置为随机播放
setButtonImage(ui->all_circle,":/image/suiji_play.png");
}
else if(QMediaPlaylist::Random==playlist->playbackMode())
{
playlist->setPlaybackMode(QMediaP
没有合适的资源?快使用搜索试试~ 我知道了~
Qt设计在线音乐播放器支持本地播放(music-player)源代码.zip
共38个文件
png:27个
cpp:3个
h:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 2 浏览量
2024-05-26
11:42:35
上传
评论
收藏 406KB ZIP 举报
温馨提示
Qt设计在线音乐播放器支持本地播放(music_player)源代码,Qt中提供了音视频播放的类,类中提供了很多播放类的接口供调用,可以实现一个完整播放器的所有功能。 class online_play : public QWidget { Q_OBJECT signals: void searchFinal(int,int,int,QString,QString,QString,int); public slots: void recv_ack(QNetworkReply*); public: explicit online_play(QWidget *parent = nullptr); private: QByteArray searchInfo; int musicId; //音乐ID int musicDuration; QString musicName; //音乐名 int mvId;
资源推荐
资源详情
资源评论
收起资源包目录
Qt设计在线音乐播放器支持本地播放(music_player)源代码.zip (38个子文件)
widget.ui 12KB
widget.cpp 8KB
image
playlist_area.png 36KB
听歌识曲.png 7KB
mylove.png 4KB
download.png 3KB
all_screen.png 2KB
last.png 3KB
crrentmusic.png 11KB
next.png 3KB
love.png 5KB
search.png 5KB
mute.png 4KB
all_circle.png 4KB
setting.png 7KB
background.jfif 81KB
cancle_all_screen.png 2KB
sigle_circle.png 5KB
lyrics.png 78KB
unlove.png 7KB
open.png 4KB
play.png 3KB
background - 副本.jfif 81KB
circle_play.png 7KB
slider.png 8KB
valum.png 5KB
suiji_play.png 6KB
pause.png 5KB
pause (2).png 2KB
point.png 4KB
playlist.png 4KB
image.qrc 1KB
main.cpp 175B
online_play.cpp 3KB
music_player.pro.user 22KB
music_player.pro 1KB
online_play.h 1KB
widget.h 2KB
共 38 条
- 1
资源评论
GJZGRB
- 粉丝: 2943
- 资源: 7737
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Python 中数据结构和算法的最少示例.zip
- 全国大学生智能车竞赛:基于Arduino的智能车设计与实现
- Python SOAP 客户端.zip
- Python ODBC 桥.zip
- Python MIDI 库.zip
- Python for DevOps repo 包含有用的 Python 脚本,可供您学习并在日常 DevOps 自动化任务中实施 .zip
- Python API 包装器和库列表.zip
- Python - 与我的 YouTube 频道相关的脚本存储在这里,可以用任何版本的 Python 编写.zip
- PyClass 课程计划.zip
- Puppet 模块用于安装和管理 Python、pip、virtualenvs 和 Gunicorn 虚拟主机 .zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功