aboutsummaryrefslogtreecommitdiff
path: root/player.cpp
blob: dd95b23f4cca786b73767c7d52f1483b31ab4ca2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <QMediaPlayer>
#include <QDebug>
#include <QFileDialog>
#include <QMessageBox>
#include "player.h"
#include "ui_player.h"
#include "about.h"



void Player::mFileDialog()
{
    QString mFile;
    QMessageBox msgbox;
    mFile = QFileDialog::getOpenFileName(this, "Open any audio file", QDir::homePath(), tr("Audio Files (*.mp3 *.wav *.ogg)"));
    if (mFile == NULL) {
        qDebug() << "File cannot be found";
        msgbox.setWindowTitle("Uh oh! An error has occured!");
        msgbox.setText("File is invalid. Maybe try loading a valid audio file.");
        msgbox.setIcon(QMessageBox::Critical);
        msgbox.exec();
        return;
    } else {
        mPlayer->setMedia(QUrl::fromLocalFile(mFile));
        qDebug() << "Opening" << mFile;
        msgbox.setWindowTitle("Success!");
        msgbox.setText("This audio file has been loaded.");
        msgbox.setIcon(QMessageBox::Information);
        msgbox.exec();
        return;
    }
}



Player::Player(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::Player)
{
    QSlider volumeSlider;
    //connect()
    ui->setupUi(this);

}

Player::~Player()
{
    qInfo() << "Closing AleePlayer...";
    mPlayer->deleteLater();
    delete ui;
}

void Player::on_actionQuit_triggered()
{
    close();
}

void Player::on_playButton_pressed()
{
    QPushButton playButton;
    if (mPlayer->state() == mPlayer->PlayingState) {
         qDebug() << "Pausing music...";
         mPlayer->pause();
         playButton.setText("Pause");
     } else {
         qDebug() << "Playing music...";
         mPlayer->play();
         playButton.setText("Play");
     }
}

void Player::on_stopButton_pressed()
{
    qInfo() << "Stopping music...";
    mPlayer->stop();
}

void Player::on_actionAbout_triggered()
{
    qDebug() << "Opening dialog";
    About about;
    about.exec();
}

void Player::on_mediaButton_pressed()
{
    mFileDialog();
}

void Player::on_actionOpen_triggered()
{
    mFileDialog();
}