Qt 简单的声音播放器

#include "voicetest.h"
#include "ui_voicetest.h"

VoiceTest::VoiceTest(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::VoiceTest)
{
    ui->setupUi(this);

    p = new QProcess(this);
    ui->pushButton->setEnabled(false);
    ui->btn_stop_1->setEnabled(false);

    music = new QMediaPlayer(this);//初始化音乐


}

VoiceTest::~VoiceTest()
{
    delete ui;
}

void VoiceTest::on_pushButton_clicked()
{
//    if(p->state() == QProcess::Running){
//        return ;
//    }
//    QString buf = QString("madplay");

//    QStringList args;
//    args << Ms_path << "&";
//    p->start(buf, args);
//    qDebug() <<"start!!!";



    QMediaPlaylist *playlist = new QMediaPlaylist(this);//初始化播放列表
    playlist->setPlaybackMode(QMediaPlaylist::Loop);
    playlist->addMedia(QUrl::fromLocalFile(Ms_path));
    music->setPlaylist(playlist);
    music->play();
    ui->pushButton->setEnabled(false);
    ui->btn_stop_1->setEnabled(true);


}

void VoiceTest::on_btn_FindDataPath_clicked()
{
    QString sFilePath = QFileDialog::getOpenFileName(this);
    qDebug() << "sFilepath = " << sFilePath;

    if(sFilePath == NULL)
        return;
    ui->edt_DataPath->setText(sFilePath);

    Ms_path = sFilePath;
    ui->pushButton->setEnabled(true);
}

void VoiceTest::on_btn_stop_1_clicked()
{
    music->stop();
    ui->pushButton->setEnabled(true);
    ui->btn_stop_1->setEnabled(false);
}
头文件里面就添加这几项,其他都是转到槽
QProcess *p;    
QString Ms_path;    
QMediaPlayer *music

界面效果:

 写的草率,记录使用的功能,怕忘记了。

最主要的部分还是借鉴了很多大佬的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值