diff --git a/README.md b/README.md new file mode 100644 index 0000000..acdace6 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +_**This is a not ready for use, toy project**_ + + +## Note + +> The Qt Multimedia APIs build upon the multimedia framework of the underlying platform. This can mean that support for various codecs or containers can vary between machines, depending on what the end user has installed. + +Current implementation use all stuff from Qt which include the multimedia playback support, which means user may need to install codecs by themself. There is a link provided by QtWiki about [Qt 5.13 Multimedia Backends](https://wiki.qt.io/Qt_5.13_Multimedia_Backends), and here is a chart about some other things which might be helpful. + +Platform|Built-in support|Probably useful 3rd-party codecs +---|---|--- +Windows|[Supported Formats In DirectsShow](https://msdn.microsoft.com/en-us/library/windows/desktop/dd407173%28v=vs.85%29.aspx)|[Xiph.org: Directshow Filters for Ogg Vorbis, Speex, Theora, FLAC, and WebM](https://www.xiph.org/dshow/) +macOS|[Media formats supported by QuickTime Player](https://support.apple.com/en-us/HT201290)|Sorry, I don't know... +Unix/Linux|depends on [GStreamer](https://gstreamer.freedesktop.org/) plugins which user installed|[GStreamer Plug-ins: gst-plugins-base, gst-plugins-good, gst-plugins-ugly, gst-plugins-bad](https://gstreamer.freedesktop.org/documentation/additional/splitup.html?gi-language=c) + diff --git a/icons/audio-volume-high.png b/icons/audio-volume-high.png index a1ab4fd..6e41d23 100644 Binary files a/icons/audio-volume-high.png and b/icons/audio-volume-high.png differ diff --git a/icons/audio-volume-muted.png b/icons/audio-volume-muted.png index 6c7da33..213f57a 100644 Binary files a/icons/audio-volume-muted.png and b/icons/audio-volume-muted.png differ diff --git a/icons/media-playback-pause.png b/icons/media-playback-pause.png index a51dc81..bd1dfd0 100644 Binary files a/icons/media-playback-pause.png and b/icons/media-playback-pause.png differ diff --git a/icons/media-playback-start.png b/icons/media-playback-start.png index 37ee0c8..d711d9b 100644 Binary files a/icons/media-playback-start.png and b/icons/media-playback-start.png differ diff --git a/icons/media-playback-stop.png b/icons/media-playback-stop.png index 751449e..f388a75 100644 Binary files a/icons/media-playback-stop.png and b/icons/media-playback-stop.png differ diff --git a/icons/media-playlist-repeat.png b/icons/media-playlist-repeat.png index 2e1b3fc..b563a40 100644 Binary files a/icons/media-playlist-repeat.png and b/icons/media-playlist-repeat.png differ diff --git a/icons/media-skip-backward.png b/icons/media-skip-backward.png index 61bcb09..ac6b8fa 100644 Binary files a/icons/media-skip-backward.png and b/icons/media-skip-backward.png differ diff --git a/icons/media-skip-forward.png b/icons/media-skip-forward.png index 95a963f..ffc9c92 100644 Binary files a/icons/media-skip-forward.png and b/icons/media-skip-forward.png differ diff --git a/icons/view-media-playlist.png b/icons/view-media-playlist.png index 98ffdce..66c4438 100644 Binary files a/icons/view-media-playlist.png and b/icons/view-media-playlist.png differ diff --git a/icons/window-close.png b/icons/window-close.png index d0ac6e7..1085efa 100644 Binary files a/icons/window-close.png and b/icons/window-close.png differ diff --git a/icons/window-minimize.png b/icons/window-minimize.png index d6ab8fd..38c741e 100644 Binary files a/icons/window-minimize.png and b/icons/window-minimize.png differ diff --git a/mainwindow.cpp b/mainwindow.cpp index de09f1b..4dae1d1 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) @@ -18,55 +20,10 @@ MainWindow::MainWindow(QWidget *parent) this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint); this->setAttribute(Qt::WA_TranslucentBackground, true); - connect(m_mediaPlayer, &QMediaPlayer::currentMediaChanged, this, [=](const QMediaContent &media) { - ui->titleLabel->setText(media.canonicalUrl().fileName()); - }); + initConnections(); + initUiAndAnimation(); - connect(m_mediaPlayer, &QMediaPlayer::positionChanged, this, [=](qint64 pos) { - ui->nowTimeLabel->setText(ms2str(pos)); - if (m_mediaPlayer->duration() != 0) { - ui->playbackSlider->setSliderPosition(ui->playbackSlider->maximum() * pos / m_mediaPlayer->duration()); - } - }); - - connect(m_mediaPlayer, &QMediaPlayer::mutedChanged, this, [=](bool muted) { - if (muted) { - ui->volumeBtn->setIcon(QIcon(":/icons/icons/audio-volume-muted.png")); - } else { - ui->volumeBtn->setIcon(QIcon(":/icons/icons/audio-volume-high.png")); - } - }); - - connect(m_mediaPlayer, &QMediaPlayer::durationChanged, this, [=](qint64 dua) { - ui->totalTimeLabel->setText(ms2str(dua)); - }); - - connect(m_mediaPlayer, &QMediaPlayer::stateChanged, this, [=](QMediaPlayer::State newState) { - switch (newState) { - case QMediaPlayer::PlayingState: - ui->playBtn->setIcon(QIcon(":/icons/icons/media-playback-pause.png")); - break; - case QMediaPlayer::StoppedState: - case QMediaPlayer::PausedState: - ui->playBtn->setIcon(QIcon(":/icons/icons/media-playback-start.png")); - break; - } - }); - - connect(m_mediaPlayer, &QMediaPlayer::volumeChanged, this, [=](int vol) { - ui->volumeSlider->setValue(vol); - }); - - m_bgLinearGradient.setColorAt(0, QColor(255, 255, 255, 25)); // a:0 - m_bgLinearGradient.setColorAt(1, QColor(255, 255, 255, 75)); // a:200 - m_bgLinearGradient.setStart(0, 0); - m_bgLinearGradient.setFinalStop(0, height()); - - m_fadeOutAnimation = new QPropertyAnimation(this, "windowOpacity", this); - m_fadeOutAnimation->setDuration(400); - m_fadeOutAnimation->setStartValue(1); - m_fadeOutAnimation->setEndValue(0); - connect(m_fadeOutAnimation, &QPropertyAnimation::finished, this, &QMainWindow::close); + centerWindow(); } MainWindow::~MainWindow() @@ -132,7 +89,7 @@ void MainWindow::loadFile() QMediaPlaylist * playlist = new QMediaPlaylist(m_mediaPlayer); playlist->setPlaybackMode(QMediaPlaylist::CurrentItemInLoop); for (const QString & fileName : files) { - bool succ = playlist->addMedia(QMediaContent(fileName)); + bool succ = playlist->addMedia(QMediaContent(QUrl::fromLocalFile(fileName))); if (!succ) { qDebug("!!!!!!!!! break point time !!!!!!!!!"); } @@ -141,6 +98,18 @@ void MainWindow::loadFile() m_mediaPlayer->setPlaylist(playlist); } +void MainWindow::centerWindow() +{ + this->setGeometry( + QStyle::alignedRect( + Qt::LeftToRight, + Qt::AlignCenter, + this->size(), + qApp->screenAt(QCursor::pos())->geometry() + ) + ); +} + void MainWindow::on_closeWindowBtn_clicked() { m_fadeOutAnimation->start(); @@ -226,3 +195,68 @@ void MainWindow::on_minimumWindowBtn_clicked() { this->showMinimized(); } + +void MainWindow::initUiAndAnimation() +{ + m_bgLinearGradient.setColorAt(0, QColor(255, 255, 255, 25)); // a:0 + m_bgLinearGradient.setColorAt(1, QColor(255, 255, 255, 75)); // a:200 + m_bgLinearGradient.setStart(0, 0); + m_bgLinearGradient.setFinalStop(0, height()); + + m_fadeOutAnimation = new QPropertyAnimation(this, "windowOpacity", this); + m_fadeOutAnimation->setDuration(400); + m_fadeOutAnimation->setStartValue(1); + m_fadeOutAnimation->setEndValue(0); + connect(m_fadeOutAnimation, &QPropertyAnimation::finished, this, &QMainWindow::close); +} + +void MainWindow::initConnections() +{ + connect(m_mediaPlayer, &QMediaPlayer::currentMediaChanged, this, [=](const QMediaContent &media) { + ui->titleLabel->setText(media.request().url().fileName()); + }); + + connect(m_mediaPlayer, &QMediaPlayer::positionChanged, this, [=](qint64 pos) { + ui->nowTimeLabel->setText(ms2str(pos)); + if (m_mediaPlayer->duration() != 0) { + ui->playbackSlider->setSliderPosition(ui->playbackSlider->maximum() * pos / m_mediaPlayer->duration()); + } + }); + + connect(m_mediaPlayer, &QMediaPlayer::mutedChanged, this, [=](bool muted) { + if (muted) { + ui->volumeBtn->setIcon(QIcon(":/icons/icons/audio-volume-muted.png")); + } else { + ui->volumeBtn->setIcon(QIcon(":/icons/icons/audio-volume-high.png")); + } + }); + + connect(m_mediaPlayer, &QMediaPlayer::durationChanged, this, [=](qint64 dua) { + ui->totalTimeLabel->setText(ms2str(dua)); + }); + + connect(m_mediaPlayer, &QMediaPlayer::stateChanged, this, [=](QMediaPlayer::State newState) { + switch (newState) { + case QMediaPlayer::PlayingState: + ui->playBtn->setIcon(QIcon(":/icons/icons/media-playback-pause.png")); + break; + case QMediaPlayer::StoppedState: + case QMediaPlayer::PausedState: + ui->playBtn->setIcon(QIcon(":/icons/icons/media-playback-start.png")); + break; + } + }); + + connect(m_mediaPlayer, &QMediaPlayer::volumeChanged, this, [=](int vol) { + ui->volumeSlider->setValue(vol); + }); + + connect(m_mediaPlayer, static_cast(&QMediaPlayer::error), + this, [=](QMediaPlayer::Error error) { + switch (error) { + default: + break; + } + qDebug(m_mediaPlayer->errorString().toUtf8() + "aaaaaaaaaaaaa"); + }); +} diff --git a/mainwindow.h b/mainwindow.h index 804cfb6..46f2506 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -26,6 +26,7 @@ protected: void mouseReleaseEvent(QMouseEvent *event) override; void loadFile(); + void centerWindow(); private slots: void on_closeWindowBtn_clicked(); @@ -54,6 +55,9 @@ private: QMediaPlayer *m_mediaPlayer; QPropertyAnimation *m_fadeOutAnimation; + void initUiAndAnimation(); + void initConnections(); + static QString ms2str(qint64 ms); }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index fef3512..2de7e47 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -250,7 +250,7 @@ QLabel#coverLabel { - The Doge Song - Various Artists + No song loaded... @@ -266,14 +266,14 @@ QLabel#coverLabel { - 1:10 + 0:00 - 3:12 + 0:00 Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter