Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

计时器在歌曲播放结束后未停止,播放进度条和时间标签交互不正常 #17

Closed
pzhlkj6612 opened this issue May 1, 2019 · 5 comments
Labels
_Refactor the player 整个播放逻辑需要重做。
Milestone

Comments

@pzhlkj6612
Copy link
Member

pzhlkj6612 commented May 1, 2019

这是一直存在的问题:

歌曲播放结束后, labelTimeCurrent 不归零, sliderSong 回到初始位置,拖动 sliderSong 会使在其初始位置和拖动位置之间闪动。


重现:

git checkout 354e203e63fb05764e4c7280cdc14fafd516fbe2 回到 #16 版本;

播放一首歌曲(我使用的歌曲长度为 137012 ms ),当其播放结束,日志输出:

BottomWidget::positionChanged => audioOriginalPos= 136960  sliderSong->value()= 996
BottomWidget::positionChanged => audioOriginalPos= 137012  sliderSong->value()= 997
ending reached
&PlayThread::audioFinish bIsLock= false
void BottomWidget::onAudioFinished(bool isEndWithForce= false )
BottomWidget::positionChanged => audioOriginalPos= 137012  sliderSong->value()= 997
&PlayThread::finished bIsLock= true
BottomWidget::positionChanged => audioOriginalPos= 137012  sliderSong->value()= 0
BottomWidget::positionChanged => audioOriginalPos= 137012  sliderSong->value()= 0
...

labelTimeCurrent 保持 02:17.012 , sliderSong 不断被设置到初始位置。


查看代码:

https://github.com/Beslyric-for-X/Beslyric-for-X/blob/354e203e63fb05764e4c7280cdc14fafd516fbe2/BottomWidgets/BottomWidget.cpp#L273-L286

注意到 sliderSong 在播放结束后被置为 0 ( musicPlayer->duration() == 0 成立), labelTimeCurrent 被置为 position (由 showPosition(int) 处理)。


查找调用:

https://github.com/Beslyric-for-X/Beslyric-for-X/blob/354e203e63fb05764e4c7280cdc14fafd516fbe2/StackFrame/MainWidget.cpp#L249-L253

https://github.com/Beslyric-for-X/Beslyric-for-X/blob/354e203e63fb05764e4c7280cdc14fafd516fbe2/StackFrame/MainWidget.cpp#L117

https://github.com/Beslyric-for-X/Beslyric-for-X/blob/354e203e63fb05764e4c7280cdc14fafd516fbe2/Entities/MusicPlayer/musicPlayer.cpp#L1004-L1008

https://github.com/Beslyric-for-X/Beslyric-for-X/blob/354e203e63fb05764e4c7280cdc14fafd516fbe2/Entities/MusicPlayer/musicPlayer.cpp#L796

这表明,在歌曲播放结束后 m_positionUpdateTimer 仍在工作, BottomWidget::positionChanged(int position) 被反复调用。


能找到停止 m_positionUpdateTimer 并发送 0 位置的代码:

https://github.com/Beslyric-for-X/Beslyric-for-X/blob/354e203e63fb05764e4c7280cdc14fafd516fbe2/Entities/MusicPlayer/musicPlayer.cpp#L907-L917

但是目前 void MusicPlayer::stop() 方法只在制作歌词时被触发:

https://github.com/Beslyric-for-X/Beslyric-for-X/blob/354e203e63fb05764e4c7280cdc14fafd516fbe2/StackFrame/MainWidget.cpp#L97-L98

注意,该 connect 写在了 MainWidget 类里。


修复本问题需要整理 PlayThread 和 MusicPlayer 等类的逻辑;

因为从用户体验来说这并不是致命的,所以不需要太优先。

@BensonLaur
Copy link
Member

BensonLaur commented May 1, 2019

尝试解决定时器问题:
https://github.com/Beslyric-for-X/Beslyric-for-X/blob/de490e3d6cfe238097ac2c40cffff05807b6fa5b/Entities/MusicPlayer/musicPlayer.cpp#L761-L775

@pzhlkj6612
Copy link
Member Author

行,算是临时修改吧。

有个问题,这里不需要判断 m_positionUpdateTimer.isActive() 了吗?

如果这里不需要,其他地方对其的判断是多余吗?

@BensonLaur
Copy link
Member

我写的时候也有稍微想到这一点,应该也算是比较懒,直接认为如果定时器已经停止,再调用一次不会做任何动作。

不过你这么一问我倒是仔细注意了这个问题,不知道对已经停止的定时器调用stop会是什么结果?

@pzhlkj6612
Copy link
Member Author

另外有一个问题。运行 de490e3 版本,歌曲播放结束时会输出:

QObject::killTimer: Timers cannot be stopped from another thread

测试了下, 收到 audioFinish 信号后执行的匿名函数是在 PlayThread 线程中执行的,所以会有这个警告。尽管 m_positionUpdateTimer 的确是停止了,但这或许会有隐患?


不过换用 QMetaObject::Connection QObject::connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type = Qt::AutoConnection) 方法能确保代码在 receiver 中执行,就像这样:

connect(playThread, SIGNAL(audioFinish(bool)), this, SLOT(theSlot(bool)));

void MusicPlayer::theSlot(bool isEndByForce) {
	m_positionUpdateTimer.stop();
}

@pzhlkj6612
Copy link
Member Author

pzhlkj6612 commented May 1, 2019

不过你这么一问我倒是仔细注意了这个问题,不知道对已经停止的定时器调用stop会是什么结果?

我在网上找了,没看到相关的说法,可以猜测定时器会继续保持停止状态。


另外, void QTimer::start() 倒是会使已开始工作的定时器停止并重新开始。

void QTimer::start() # QTimer Class | Qt Core 5.12.3

@BensonLaur BensonLaur added the resolved-in-next-version The problem has been fixed or the requirement has been implemented label Jul 13, 2019
BensonLaur added a commit that referenced this issue Jul 13, 2019
…ther thread (同时不影响之前播放逻辑)

2、重新审视歌曲滚动条操作问题题问问题,确定最终逻辑为——在音频结束时禁用进度操作,在音频成功被载入时启用进度操作(除制作模式),一次解决 #19  #20 #21 提到的问题
@pzhlkj6612 pzhlkj6612 added this to the Next Release milestone Feb 23, 2020
@pzhlkj6612 pzhlkj6612 added _Refactor the player 整个播放逻辑需要重做。 and removed resolved-in-next-version The problem has been fixed or the requirement has been implemented labels Feb 23, 2020
@pzhlkj6612 pzhlkj6612 modified the milestones: Next Release, v3.1.1 Feb 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
_Refactor the player 整个播放逻辑需要重做。
Projects
None yet
Development

No branches or pull requests

2 participants