#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
界面效果:
写的草率,记录使用的功能,怕忘记了。
最主要的部分还是借鉴了很多大佬的。