misc fixes for linux
15
README.md
Normal file
|
@ -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)
|
||||||
|
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 766 B |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 541 B |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 812 B |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 428 B |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 809 B |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 553 B |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 549 B |
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 391 B |
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 494 B |
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 318 B |
132
mainwindow.cpp
|
@ -7,6 +7,8 @@
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
|
#include <QStyle>
|
||||||
|
#include <QScreen>
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
|
@ -18,55 +20,10 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint);
|
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint);
|
||||||
this->setAttribute(Qt::WA_TranslucentBackground, true);
|
this->setAttribute(Qt::WA_TranslucentBackground, true);
|
||||||
|
|
||||||
connect(m_mediaPlayer, &QMediaPlayer::currentMediaChanged, this, [=](const QMediaContent &media) {
|
initConnections();
|
||||||
ui->titleLabel->setText(media.canonicalUrl().fileName());
|
initUiAndAnimation();
|
||||||
});
|
|
||||||
|
|
||||||
connect(m_mediaPlayer, &QMediaPlayer::positionChanged, this, [=](qint64 pos) {
|
centerWindow();
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
@ -132,7 +89,7 @@ void MainWindow::loadFile()
|
||||||
QMediaPlaylist * playlist = new QMediaPlaylist(m_mediaPlayer);
|
QMediaPlaylist * playlist = new QMediaPlaylist(m_mediaPlayer);
|
||||||
playlist->setPlaybackMode(QMediaPlaylist::CurrentItemInLoop);
|
playlist->setPlaybackMode(QMediaPlaylist::CurrentItemInLoop);
|
||||||
for (const QString & fileName : files) {
|
for (const QString & fileName : files) {
|
||||||
bool succ = playlist->addMedia(QMediaContent(fileName));
|
bool succ = playlist->addMedia(QMediaContent(QUrl::fromLocalFile(fileName)));
|
||||||
if (!succ) {
|
if (!succ) {
|
||||||
qDebug("!!!!!!!!! break point time !!!!!!!!!");
|
qDebug("!!!!!!!!! break point time !!!!!!!!!");
|
||||||
}
|
}
|
||||||
|
@ -141,6 +98,18 @@ void MainWindow::loadFile()
|
||||||
m_mediaPlayer->setPlaylist(playlist);
|
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()
|
void MainWindow::on_closeWindowBtn_clicked()
|
||||||
{
|
{
|
||||||
m_fadeOutAnimation->start();
|
m_fadeOutAnimation->start();
|
||||||
|
@ -226,3 +195,68 @@ void MainWindow::on_minimumWindowBtn_clicked()
|
||||||
{
|
{
|
||||||
this->showMinimized();
|
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<void(QMediaPlayer::*)(QMediaPlayer::Error)>(&QMediaPlayer::error),
|
||||||
|
this, [=](QMediaPlayer::Error error) {
|
||||||
|
switch (error) {
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
qDebug(m_mediaPlayer->errorString().toUtf8() + "aaaaaaaaaaaaa");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ protected:
|
||||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||||
|
|
||||||
void loadFile();
|
void loadFile();
|
||||||
|
void centerWindow();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_closeWindowBtn_clicked();
|
void on_closeWindowBtn_clicked();
|
||||||
|
@ -54,6 +55,9 @@ private:
|
||||||
QMediaPlayer *m_mediaPlayer;
|
QMediaPlayer *m_mediaPlayer;
|
||||||
QPropertyAnimation *m_fadeOutAnimation;
|
QPropertyAnimation *m_fadeOutAnimation;
|
||||||
|
|
||||||
|
void initUiAndAnimation();
|
||||||
|
void initConnections();
|
||||||
|
|
||||||
static QString ms2str(qint64 ms);
|
static QString ms2str(qint64 ms);
|
||||||
};
|
};
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|
|
@ -250,7 +250,7 @@ QLabel#coverLabel {
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>The Doge Song - Various Artists</string>
|
<string>No song loaded...</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -266,14 +266,14 @@ QLabel#coverLabel {
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="nowTimeLabel">
|
<widget class="QLabel" name="nowTimeLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>1:10</string>
|
<string>0:00</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="totalTimeLabel">
|
<widget class="QLabel" name="totalTimeLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>3:12</string>
|
<string>0:00</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
|