misc fixes for linux

This commit is contained in:
Gary Wang 2020-04-07 12:58:08 +08:00
parent f8d9b347a8
commit 6435c4e79f
15 changed files with 105 additions and 52 deletions

15
README.md Normal file
View 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)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 766 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 541 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 812 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 428 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 809 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 553 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 549 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 391 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 494 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 318 B

View File

@ -7,6 +7,8 @@
#include <QPropertyAnimation>
#include <QFileDialog>
#include <QTime>
#include <QStyle>
#include <QScreen>
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<void(QMediaPlayer::*)(QMediaPlayer::Error)>(&QMediaPlayer::error),
this, [=](QMediaPlayer::Error error) {
switch (error) {
default:
break;
}
qDebug(m_mediaPlayer->errorString().toUtf8() + "aaaaaaaaaaaaa");
});
}

View File

@ -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

View File

@ -250,7 +250,7 @@ QLabel#coverLabel {
</sizepolicy>
</property>
<property name="text">
<string>The Doge Song - Various Artists</string>
<string>No song loaded...</string>
</property>
</widget>
</item>
@ -266,14 +266,14 @@ QLabel#coverLabel {
<item>
<widget class="QLabel" name="nowTimeLabel">
<property name="text">
<string>1:10</string>
<string>0:00</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="totalTimeLabel">
<property name="text">
<string>3:12</string>
<string>0:00</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>