Skip to content

Commit

Permalink
fix: 使用qt播放器播放ape文件
Browse files Browse the repository at this point in the history
使用qt播放器播放ape文件

Bug: https://pms.uniontech.com/bug-view-275987.html
Log: 使用qt播放器播放ape文件
  • Loading branch information
myk1343 committed Sep 29, 2024
1 parent ba7b93b commit 92c9194
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/music-player/core/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,7 @@ void Player::initPlayer()
qDebug() << __func__ << "QtPlayer";
} else {
m_basePlayer = new VlcPlayer(this);
(static_cast<VlcPlayer*>(m_basePlayer))->setQtPlayer(new QtPlayer(this));
qDebug() << __func__ << "VlcPlayer";
}
m_basePlayer->setVolume(m_volume);
Expand Down
62 changes: 52 additions & 10 deletions src/music-player/core/vlcplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ void VlcPlayer::releasePlayer()

void VlcPlayer::release()
{
m_qtPlayer->release();
releasePlayer();
}

Expand Down Expand Up @@ -132,12 +133,18 @@ void VlcPlayer::startCdaThread()

void VlcPlayer::play()
{
if(m_bApe) {
return m_qtPlayer->play();
}
init();
m_qvplayer->play();
}

void VlcPlayer::pause()
{
if(m_bApe) {
return m_qtPlayer->pause();
}
if (m_qvplayer) {
#ifndef __sw_64__
static_cast<SdlPlayer*>(m_qvplayer)->setCachingThreadPause(true);
Expand All @@ -148,13 +155,19 @@ void VlcPlayer::pause()

void VlcPlayer::pauseNew()
{
if(m_bApe) {
return m_qtPlayer->pauseNew();
}
if (m_qvplayer) {
m_qvplayer->pauseNew();
}
}

void VlcPlayer::resume()
{
if(m_bApe) {
return m_qtPlayer->resume();
}
if (m_qvplayer) {
m_qvplayer->resume();
#ifndef __sw_64__
Expand All @@ -164,6 +177,9 @@ void VlcPlayer::resume()
}
PlayerBase::PlayState VlcPlayer::state()
{
if(m_bApe) {
return m_qtPlayer->state();
}
init();
Vlc::State state = m_qvplayer->state();
switch (state) {
Expand All @@ -183,26 +199,38 @@ PlayerBase::PlayState VlcPlayer::state()

void VlcPlayer::stop()
{
if(m_bApe) {
return m_qtPlayer->stop();
}
if (m_qvplayer) {
m_qvplayer->stop();
}
}

int VlcPlayer::length()
{
if(m_bApe) {
return m_qtPlayer->length();
}
init();
qDebug() << "VlcPlayer: m_qvplayer->length()" << m_qvplayer->length();
return m_qvplayer->length();
}

void VlcPlayer::setTime(qint64 time)
{
if(m_bApe) {
return m_qtPlayer->setTime(time);
}
init();
m_qvplayer->setTime(time);
}

qint64 VlcPlayer::time()
{
if(m_bApe) {
return m_qtPlayer->time();
}
init();
return m_qvplayer->time();
}
Expand All @@ -211,17 +239,14 @@ void VlcPlayer::setMediaMeta(MediaMeta meta)
{
init();
m_activeMeta = meta;
if(MetaDetector::getInstance()->getAudioType(meta).toLower() == "ape") {
QString curPath = Global::cacheDir();
QString toPath = QString("%1/images/%2.mp3").arg(curPath).arg(meta.hash);
if(!QFile::exists(toPath)) {
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
QString program = QString("ffmpeg -i %1 -ac 1 -ab 32 -ar 24000 %2").arg(meta.localPath).arg(toPath);
QProcess::execute(program);
QApplication::restoreOverrideCursor();
}
m_qvmedia->initMedia(toPath, meta.mmType == MIMETYPE_CDA ? false : true, m_qvinstance, meta.track);
m_bApe = (MetaDetector::getInstance()->getAudioType(meta).toLower() == "ape");
if(m_bApe) {
connect(m_qtPlayer, &PlayerBase::positionChanged, this, &PlayerBase::positionChanged);
m_qtPlayer->setMediaMeta(meta);
m_qtPlayer->play();
} else {
m_qtPlayer->stop();
disconnect(m_qtPlayer, &PlayerBase::positionChanged, this, &PlayerBase::positionChanged);
m_qvmedia->initMedia(meta.localPath, meta.mmType == MIMETYPE_CDA ? false : true, m_qvinstance, meta.track);
}
m_qvplayer->open(m_qvmedia);
Expand Down Expand Up @@ -267,18 +292,27 @@ float VlcPlayer::amplificationForBandAt(uint bandIndex)

void VlcPlayer::setVolume(int volume)
{
if(m_bApe) {
return m_qtPlayer->setVolume(volume);
}
init();
m_qvplayer->setVolume(volume);
}

void VlcPlayer::setMute(bool value)
{
if(m_bApe) {
return m_qtPlayer->setMute(value);
}
init();
m_qvplayer->setMute(value);
}

void VlcPlayer::initCddaTrack()
{
if(m_bApe) {
return m_qtPlayer->initCddaTrack();
}
init();
m_qvplayer->initCddaTrack();
}
Expand Down Expand Up @@ -316,8 +350,16 @@ QList<MediaMeta> VlcPlayer::getCdaMetaInfo()
return QList<MediaMeta>();
}

void VlcPlayer::setQtPlayer(PlayerBase *qtPlayer)
{
m_qtPlayer = qtPlayer;
}

bool VlcPlayer::getMute()
{
if(m_bApe) {
return m_qtPlayer->getMute();
}
return m_qvplayer->getMute();
}

Expand Down
3 changes: 3 additions & 0 deletions src/music-player/core/vlcplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class VlcPlayer : public PlayerBase
void initCdaThread();
void initCddaTrack() override;
QList<MediaMeta> getCdaMetaInfo() override;
void setQtPlayer(PlayerBase *qtPlayer);

public:
void play() override;
Expand Down Expand Up @@ -66,6 +67,8 @@ class VlcPlayer : public PlayerBase
CdaThread *m_pCdaThread = nullptr;
int m_Vlcstate = -1; //休眠状态缓存(上一次休眠时的状态)
int m_volume = 50.0;
PlayerBase *m_qtPlayer = nullptr;
bool m_bApe = false;
};

#endif // VLCPLAYER_H

0 comments on commit 92c9194

Please sign in to comment.