昆仑山:眼中无形心中有穴之穴人合一

夫君子之行,静以修身,俭以养德;非澹泊无以明志,非宁静无以致远。夫学须静也,才须学也;非学无以广才,非志无以成学。怠慢则不能励精,险躁则不能冶性。年与时驰,意与岁去,遂成枯落,多不接世。悲守穷庐,将复何及!

 

Qt艺术编程(音乐播放器)

1

2

3

4

5

6

7

8

9

10

#-------------------------------------------------
#
# Project created by QtCreator 2018-12-13T22:12:33
#
#-------------------------------------------------

QT       += core gui
QT       +=  multimedia
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = CheckPlayer
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

CONFIG += c++11

SOURCES += \
        main.cpp \
        dialog.cpp

HEADERS += \
        dialog.h

FORMS += \
        dialog.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

11

12

#ifndef DIALOG_H
#define DIALOG_H

#include <QDialog>
#include<QMediaPlayer>
#include<QDebug>



namespace Ui {
class Dialog;
}

class Dialog : public QDialog
{
    Q_OBJECT

public:
    explicit Dialog(QWidget *parent = nullptr);
    ~Dialog();

private slots:


    void on_sliderVolume_sliderMoved(int position);

    void on_sliderProgress_sliderMoved(int position);

    void on_StartButton_clicked();

    void on_StopButton_clicked();

    void onPositionchanged(qint64 position);
    void onDurationchanged(qint64 position);

private:
    Ui::Dialog *ui;
    QMediaPlayer *player;
};

#endif // DIALOG_H

13

#include "dialog.h"
#include "ui_dialog.h"

Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);
    player=new QMediaPlayer(this);
    connect(player,
            &QMediaPlayer::positionChanged,
            this,
            &Dialog::onPositionchanged);
    connect(player,
            &QMediaPlayer::durationChanged,
            this,
            &Dialog::onDurationchanged);
}

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



void Dialog::on_sliderVolume_sliderMoved(int position)
{
    player->setVolume(position);
}

void Dialog::on_sliderProgress_sliderMoved(int position)
{
    player->setPosition(position);
}

void Dialog::on_StartButton_clicked()
{
        //加载文件
    player->setMedia(QUrl::fromLocalFile("C:/Users/happy/Desktop/the story of the city.mp3"));
    player->play();
    qDebug()<<player->errorString();
}

void Dialog::on_StopButton_clicked()
{
    player->stop();
}

void Dialog::onPositionchanged(qint64 position)
{
    ui->sliderProgress->setValue(position);
}

void Dialog::onDurationchanged(qint64 position)
{
    ui->sliderProgress->setMaximum(position);
}

14

posted on 2018-12-13 23:39  Indian_Mysore  阅读(284)  评论(0编辑  收藏  举报

导航