Skip to content

Commit

Permalink
[增加日志记录和配置目录设置功能]:在mpvplayer示例程序中增加了日志记录和配置目录设置的功能,并更新了相关代码。
Browse files Browse the repository at this point in the history
- 在`mainwindow.cc`中为`mpvPlayer`增加了日志文件路径设置和配置目录设置,使用`Utils`命名空间下的函数获取日志路径和配置路径。
- 更新了`mpvplayer.cc`,为`MpvPlayer`类增加了设置和获取日志文件路径以及配置目录的函数。
- 在`mpvplayer.hpp`中,为`MpvPlayer`类声明了新的公共成员函数,包括设置和获取日志文件路径及配置目录。
- 修改了`previewwidget.cc`中的`startPreview`函数,使用新的接口设置音频和字幕轨道为"no",替换了旧的阻塞方法。
  • Loading branch information
RealChuan committed Jun 17, 2024
1 parent 4e8cd86 commit c21bfb4
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 20 deletions.
13 changes: 10 additions & 3 deletions examples/mpvplayer/mainwindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <mpv/mpvplayer.hpp>
#include <mpv/mpvwidget.hpp>
#include <mpv/previewwidget.hpp>
#include <utils/utils.h>

#include <QtWidgets>

Expand All @@ -34,6 +35,12 @@ class MainWindow::MainWindowPrivate
mpvWidget->setAcceptDrops(true);
mpvPlayer->setPrintToStd(true);

auto logFilePath = QString("%1/mpv_%2.log")
.arg(Utils::logPath(),
QDateTime::currentDateTime().toString("yyyyMMdd"));
mpvPlayer->setLogFile(logFilePath);
mpvPlayer->setConfigDir(Utils::configPath());

logWindow = new Mpv::MpvLogWindow(q_ptr);
logWindow->setMinimumSize(500, 325);
logWindow->show();
Expand Down Expand Up @@ -773,15 +780,15 @@ void MainWindow::initMenu()

connect(d_ptr->videoTracksGroup, &QActionGroup::triggered, this, [this](QAction *action) {
auto data = action->data().value<Mpv::TraskInfo>();
d_ptr->mpvPlayer->setVideoTrack(data.id);
d_ptr->mpvPlayer->setVid(data.id);
});
connect(d_ptr->audioTracksGroup, &QActionGroup::triggered, this, [this](QAction *action) {
auto data = action->data().value<Mpv::TraskInfo>();
d_ptr->mpvPlayer->setAudioTrack(data.id);
d_ptr->mpvPlayer->setAid(data.id);
});
connect(d_ptr->subTracksGroup, &QActionGroup::triggered, this, [this](QAction *action) {
auto data = action->data().value<Mpv::TraskInfo>();
d_ptr->mpvPlayer->setSubTrack(data.id);
d_ptr->mpvPlayer->setSid(data.id);
});
connect(d_ptr->loadSubTitlesAction, &QAction::triggered, this, &MainWindow::onLoadSubtitleFiles);
connect(d_ptr->subDelayAction,
Expand Down
40 changes: 31 additions & 9 deletions src/mpv/mpvplayer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,37 +242,37 @@ auto MpvPlayer::subTracks() const -> TraskInfos
return d_ptr->subTracks;
}

void MpvPlayer::setVideoTrack(int vid)
void MpvPlayer::setVid(const QVariant &vid)
{
qInfo() << "vid: " << vid;
mpv::qt::set_property_async(d_ptr->mpv, "vid", vid);
}

void MpvPlayer::blockVideoTrack()
QVariant MpvPlayer::vid() const
{
mpv::qt::set_property_async(d_ptr->mpv, "vid", "no");
return mpv::qt::get_property(d_ptr->mpv, "vid");
}

void MpvPlayer::setAudioTrack(int aid)
void MpvPlayer::setAid(const QVariant &aid)
{
qInfo() << "aid: " << aid;
mpv::qt::set_property_async(d_ptr->mpv, "aid", aid);
}

void MpvPlayer::blockAudioTrack()
QVariant MpvPlayer::aid() const
{
mpv::qt::set_property_async(d_ptr->mpv, "aid", "no");
return mpv::qt::get_property(d_ptr->mpv, "aid");
}

void MpvPlayer::setSubTrack(int sid)
void MpvPlayer::setSid(const QVariant &sid)
{
qInfo() << "sid: " << sid;
mpv::qt::set_property_async(d_ptr->mpv, "sid", sid);
}

void MpvPlayer::blockSubTrack()
QVariant MpvPlayer::sid() const
{
mpv::qt::set_property_async(d_ptr->mpv, "sid", "no");
return mpv::qt::get_property(d_ptr->mpv, "sid");
}

void MpvPlayer::addAudio(const QStringList &paths)
Expand Down Expand Up @@ -537,6 +537,28 @@ QString MpvPlayer::targetPrimariesName() const
return mpv::qt::get_property(d_ptr->mpv, "target-prim").toString();
}

void MpvPlayer::setLogFile(const QString &logFile)
{
qInfo() << "log-file: " << logFile;
mpv::qt::set_property_async(d_ptr->mpv, "log-file", logFile);
}

QString MpvPlayer::logFile() const
{
return mpv::qt::get_property(d_ptr->mpv, "log-file").toString();
}

void MpvPlayer::setConfigDir(const QString &configDir)
{
qInfo() << "config-dir: " << configDir;
mpv::qt::set_property_async(d_ptr->mpv, "config-dir", configDir);
}

QString MpvPlayer::configDir() const
{
return mpv::qt::get_property(d_ptr->mpv, "config-dir").toString();
}

void MpvPlayer::pauseAsync()
{
auto state = !isPaused();
Expand Down
20 changes: 14 additions & 6 deletions src/mpv/mpvplayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ class MPV_LIB_EXPORT MpvPlayer : public QObject
[[nodiscard]] auto audioTracks() const -> TraskInfos;
[[nodiscard]] auto subTracks() const -> TraskInfos;

void setVideoTrack(int vid);
void blockVideoTrack();
void setAudioTrack(int aid);
void blockAudioTrack();
void setSubTrack(int sid);
void blockSubTrack();
void setVid(const QVariant &vid);
[[nodiscard]] auto vid() const -> QVariant;

void setAid(const QVariant &aid);
[[nodiscard]] auto aid() const -> QVariant;

void setSid(const QVariant &sid);
[[nodiscard]] auto sid() const -> QVariant;

void addAudio(const QStringList &paths);
void addSub(const QStringList &paths);
Expand Down Expand Up @@ -98,6 +100,12 @@ class MPV_LIB_EXPORT MpvPlayer : public QObject
void setTargetPrimaries(const QString &targetPrimaries);
[[nodiscard]] auto targetPrimariesName() const -> QString;

void setLogFile(const QString &logFile);
[[nodiscard]] auto logFile() const -> QString;

void setConfigDir(const QString &configDir);
[[nodiscard]] auto configDir() const -> QString;

void pauseAsync();
void pauseSync(bool state);
auto isPaused() -> bool;
Expand Down
4 changes: 2 additions & 2 deletions src/mpv/previewwidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ void PreviewWidget::startPreview(const QString &filepath, int timestamp)
{
if (filepath != d_ptr->mpvPlayer->filepath()) {
d_ptr->mpvPlayer->openMedia(filepath);
d_ptr->mpvPlayer->blockAudioTrack();
d_ptr->mpvPlayer->blockSubTrack();
d_ptr->mpvPlayer->setAid("no");
d_ptr->mpvPlayer->setSid("no");
}
d_ptr->mpvPlayer->seek(timestamp);
}
Expand Down

0 comments on commit c21bfb4

Please sign in to comment.