Skip to content

Commit

Permalink
新增 进度条和缩略图显示章节信息;
Browse files Browse the repository at this point in the history
  • Loading branch information
RealChuan committed Feb 26, 2024
1 parent 5b89b8e commit 2f411db
Show file tree
Hide file tree
Showing 16 changed files with 200 additions and 169 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- macos-latest
- ubuntu-latest
qt_ver:
- 6.6.1
- 6.6.2
build_type:
- "RelWithDebInfo"
generators:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/qmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- macos-latest
- ubuntu-latest
qt_ver:
- 6.6.1
- 6.6.2

steps:
- name: Restore windows vcpkg
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/toolchain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- macos-latest
- ubuntu-latest
qt_ver:
- 6.6.1
- 6.6.2

steps:
- name: Install Qt
Expand Down
6 changes: 5 additions & 1 deletion 3rdparty/3rdparty.pri
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ win32{
}

macx{
vcpkg_path = /usr/local/share/vcpkg/installed/x64-osx
contains(QMAKE_APPLE_DEVICE_ARCHS, arm64) {
vcpkg_path = /usr/local/share/vcpkg/installed/arm64-osx
} else {
vcpkg_path = /usr/local/share/vcpkg/installed/x64-osx
}
}

unix:!macx{
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(utils)

if(CMAKE_HOST_WIN32)
list(APPEND CMAKE_PREFIX_PATH "C:\\Qt\\6.6.1\\msvc2019_64")
list(APPEND CMAKE_PREFIX_PATH "C:\\Qt\\6.6.2\\msvc2019_64")
elseif(CMAKE_HOST_APPLE)

elseif(CMAKE_HOST_UNIX)
list(APPEND CMAKE_PREFIX_PATH "/opt/Qt/6.6.1/gcc_64")
list(APPEND CMAKE_PREFIX_PATH "/opt/Qt/6.6.2/gcc_64")
endif()

project(
Expand Down
10 changes: 10 additions & 0 deletions examples/player/controlwidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,19 @@ void ControlWidget::setDuration(int value)
d_ptr->slider->blockSignals(true);
d_ptr->slider->setRange(0, value);
d_ptr->slider->blockSignals(false);
d_ptr->slider->clearNodes();
setPosition(0);
}

void ControlWidget::setChapters(const Ffmpeg::Chapters &chapters)
{
QVector<qint64> nodes;
for (const auto &chapter : std::as_const(chapters)) {
nodes.append(chapter.startTime);
}
d_ptr->slider->setNodes(nodes);
}

void ControlWidget::setPosition(int value)
{
auto str = QTime::fromMSecsSinceStartOfDay(value * 1000).toString("hh:mm:ss");
Expand Down
3 changes: 3 additions & 0 deletions examples/player/controlwidget.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef CONTROLWIDGET_HPP
#define CONTROLWIDGET_HPP

#include <ffmpeg/mediainfo.hpp>

#include <QWidget>

class ControlWidget : public QWidget
Expand All @@ -15,6 +17,7 @@ class ControlWidget : public QWidget

void setDuration(int value);
[[nodiscard]] auto duration() const -> int;
void setChapters(const Ffmpeg::Chapters &chapters);

[[nodiscard]] auto sliderGlobalPos() const -> QPoint;

Expand Down
45 changes: 23 additions & 22 deletions examples/player/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static auto isPlaylist(const QUrl &url) -> bool // Check for ".m3u" playlists.
}
const QFileInfo fileInfo(url.toLocalFile());
return fileInfo.exists()
&& !fileInfo.suffix().compare(QLatin1String("m3u"), Qt::CaseInsensitive);
&& (fileInfo.suffix().compare(QLatin1String("m3u"), Qt::CaseInsensitive) == 0);
}

class MainWindow::MainWindowPrivate
Expand Down Expand Up @@ -142,7 +142,7 @@ class MainWindow::MainWindowPrivate
controlWidget->setVisible(visible);
}

auto setTitleWidgetVisible(bool visible) const -> bool
[[nodiscard]] auto setTitleWidgetVisible(bool visible) const -> bool
{
if (videoRender.isNull()) {
return false;
Expand All @@ -151,7 +151,7 @@ class MainWindow::MainWindowPrivate
return true;
}

void setTitleWidgetText(const QString &text)
void setTitleWidgetText(const QString &text) const
{
if (!setTitleWidgetVisible(true)) {
return;
Expand Down Expand Up @@ -382,6 +382,7 @@ void MainWindow::onProcessEvents()
case Ffmpeg::PropertyChangeEvent::EventType::Duration: {
auto *durationEvent = dynamic_cast<Ffmpeg::DurationEvent *>(eventPtr.data());
d_ptr->controlWidget->setDuration(durationEvent->duration() / AV_TIME_BASE);
d_ptr->controlWidget->setChapters(d_ptr->playerPtr->mediaInfo().chapters);
} break;
case Ffmpeg::PropertyChangeEvent::EventType::Position: {
auto *positionEvent = dynamic_cast<Ffmpeg::PositionEvent *>(eventPtr.data());
Expand Down Expand Up @@ -473,23 +474,23 @@ auto MainWindow::eventFilter(QObject *watched, QEvent *event) -> bool
if (!d_ptr->videoRender.isNull() && watched == d_ptr->videoRender->widget()) {
switch (event->type()) {
case QEvent::DragEnter: {
auto *e = dynamic_cast<QDragEnterEvent *>(event);
e->acceptProposedAction();
auto *ev = dynamic_cast<QDragEnterEvent *>(event);
ev->acceptProposedAction();
} break;
case QEvent::DragMove: {
auto *e = dynamic_cast<QDragMoveEvent *>(event);
e->acceptProposedAction();
auto *ev = dynamic_cast<QDragMoveEvent *>(event);
ev->acceptProposedAction();
} break;
case QEvent::Drop: {
auto *e = dynamic_cast<QDropEvent *>(event);
auto urls = e->mimeData()->urls();
auto *ev = dynamic_cast<QDropEvent *>(event);
auto urls = ev->mimeData()->urls();
if (!urls.isEmpty()) {
addToPlaylist(urls);
}
} break;
case QEvent::ContextMenu: {
auto *e = dynamic_cast<QContextMenuEvent *>(event);
d_ptr->menu->exec(e->globalPos());
auto *ev = dynamic_cast<QContextMenuEvent *>(event);
d_ptr->menu->exec(ev->globalPos());
} break;
case QEvent::MouseButtonDblClick:
if (isFullScreen()) {
Expand All @@ -504,8 +505,8 @@ auto MainWindow::eventFilter(QObject *watched, QEvent *event) -> bool
} else if (watched == d_ptr->playlistView) {
switch (event->type()) {
case QEvent::ContextMenu: {
auto *e = dynamic_cast<QContextMenuEvent *>(event);
d_ptr->playListMenu->exec(e->globalPos());
auto *ev = dynamic_cast<QContextMenuEvent *>(event);
d_ptr->playListMenu->exec(ev->globalPos());
} break;
default: break;
}
Expand All @@ -515,14 +516,14 @@ auto MainWindow::eventFilter(QObject *watched, QEvent *event) -> bool
d_ptr->controlWidget->show();
d_ptr->controlWidget->hide();
auto controlWidgetGeometry = d_ptr->controlWidget->geometry();
auto *e = dynamic_cast<QHoverEvent *>(event);
bool contain = controlWidgetGeometry.contains(e->position().toPoint());
auto *ev = dynamic_cast<QHoverEvent *>(event);
bool contain = controlWidgetGeometry.contains(ev->position().toPoint());
d_ptr->setControlWidgetVisible(contain);
if (isFullScreen()) {
d_ptr->titleWidget->show();
d_ptr->titleWidget->hide();
auto titleWidgetGeometry = d_ptr->titleWidget->geometry();
contain = titleWidgetGeometry.contains(e->position().toPoint());
contain = titleWidgetGeometry.contains(ev->position().toPoint());
d_ptr->setTitleWidgetVisible(contain);
}
break;
Expand All @@ -533,12 +534,12 @@ auto MainWindow::eventFilter(QObject *watched, QEvent *event) -> bool
return QMainWindow::eventFilter(watched, event);
}

void MainWindow::keyPressEvent(QKeyEvent *ev)
void MainWindow::keyPressEvent(QKeyEvent *event)
{
QMainWindow::keyPressEvent(ev);
QMainWindow::keyPressEvent(event);

qInfo() << "MainWindow Pressed key:" << ev->key();
switch (ev->key()) {
qInfo() << "MainWindow Pressed key:" << event->key();
switch (event->key()) {
case Qt::Key_Escape:
if (isFullScreen()) {
showNormal();
Expand Down Expand Up @@ -578,9 +579,9 @@ void MainWindow::buildConnect()
d_ptr->playerPtr->addEvent(Ffmpeg::EventPtr(new Ffmpeg::SeekEvent(position * AV_TIME_BASE)));
});
connect(d_ptr->controlWidget, &ControlWidget::play, this, [this](bool checked) {
if (checked && !d_ptr->playerPtr->isRunning())
if (checked && !d_ptr->playerPtr->isRunning()) {
d_ptr->playerPtr->onPlay();
else {
} else {
d_ptr->playerPtr->addEvent(Ffmpeg::EventPtr(new Ffmpeg::PauseEvent(!checked)));
}
});
Expand Down
4 changes: 2 additions & 2 deletions examples/player/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ private slots:
void onOpenWebMedia();
void onRenderChanged(QAction *action);

void playlistPositionChanged(int);
void playlistPositionChanged(int /*currentItem*/);
void jump(const QModelIndex &index);

void onProcessEvents();

protected:
auto eventFilter(QObject *watched, QEvent *event) -> bool override;
void keyPressEvent(QKeyEvent *ev) override;
void keyPressEvent(QKeyEvent *event) override;

private:
void setupUI();
Expand Down
Loading

0 comments on commit 2f411db

Please sign in to comment.