fix(player): reset m_isChangePlayFile in play() for same-file scenario#398
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideResets the m_isChangePlayFile flag directly in VlcPalyer::play() after playByName() when MPV is already in Playing state for same-file playback, ensuring playEnd is emitted and the progress bar clears correctly. Sequence diagram for same-file playback flag reset in VlcPalyer::playsequenceDiagram
actor User
participant UI as VoiceUI
participant VlcPalyer
participant PlayerEngine
User ->> UI: select copied_voice_note
UI ->> VlcPalyer: play()
VlcPalyer ->> PlayerEngine: addPlayFile(videoUrl)
VlcPalyer ->> PlayerEngine: playByName(videoUrl)
alt same_file_already_playing
PlayerEngine ->> VlcPalyer: state() == Playing
VlcPalyer ->> VlcPalyer: m_isChangePlayFile = false
end
PlayerEngine ->> PlayerEngine: playback finishes (state Idle)
PlayerEngine ->> VlcPalyer: onGetState(Idle)
VlcPalyer ->> UI: playEnd (progress bar cleared)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider centralizing the logic for resetting m_isChangePlayFile (currently split between onGetState and play()) into a shared helper to keep state-transition handling consistent and easier to reason about.
- Calling player->state() immediately after playByName() assumes synchronous state updates; if the engine updates state asynchronously, this condition may be flaky—verify whether a more robust trigger (e.g., a callback or queued check) is needed for the same-file scenario.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider centralizing the logic for resetting m_isChangePlayFile (currently split between onGetState and play()) into a shared helper to keep state-transition handling consistent and easier to reason about.
- Calling player->state() immediately after playByName() assumes synchronous state updates; if the engine updates state asynchronously, this condition may be flaky—verify whether a more robust trigger (e.g., a callback or queued check) is needed for the same-file scenario.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
14f50dd to
5564734
Compare
Fix by directly resetting m_isChangePlayFile in VlcPalyer::play() when MPV is already in Playing state after playByName(), rather than relying on onGetState() which is never triggered for the same file. 切换到同一文件的语音(如复制的语音笔记)时,MPV 不重新进入 Playing 状态(已经在 Playing),导致 onGetState 中 Playing && m_isChangePlayFile 分支不被触发,m_isChangePlayFile 保持 true。播放结束时 Idle && !m_isChangePlayFile 为 false,playEnd 不发出,进度条不消失。 在 VlcPalyer::play() 的 playByName 之后,若 MPV 已处于 Playing 状态, 直接重置 m_isChangePlayFile 标志,不依赖 onGetState 触发。 Log: 修复复制语音切换播放后进度条不消失的问题 Bug: https://pms.uniontech.com/bug-view-365835.html Influence: 修复后切换播放同一语音文件时进度条正常更新且播放结束后正常消失,不影响不同语音文件的正常播放。
5564734 to
9066870
Compare
deepin pr auto review★ 总体评分:95分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // Copyright (C) 2019 - 2025 UnionTech Software Technology Co.,Ltd.
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
// ... 其他代码 ...
void VlcPalyer::play()
{
// ... 前置逻辑 ...
if (!isPlayingSameFile) {
qInfo() << "Play new audio: " << videoUrl;
player->addPlayFile(videoUrl);
player->playByName(videoUrl);
// BUG修复:处理同一文件重复播放时 MPV 状态不切换导致的 m_isChangePlayFile 未重置及 playEnd 信号丢失问题
// 同一文件场景:MPV 不重新进入 Playing 状态(已经在 Playing),
// onGetState 中的 Playing && m_isChangePlayFile 分支不会被触发,
// 需在此处直接重置标志,否则播放结束时 playEnd 不发出
if (m_isChangePlayFile && player->state() == PlayerEngine::CoreState::Playing) {
m_isChangePlayFile = false;
// 同一文件 MPV 不会从头播放,需显式 seek 到起始位置
player->seekAbsolute(0);
}
}
// ... 后续逻辑 ...
} |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: max-lvs, Resurgamz The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/merge |
|
This pr cannot be merged! (status: unstable) |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
Fix by directly resetting m_isChangePlayFile in VlcPalyer::play() when MPV is already in Playing state after playByName(), rather than relying on onGetState() which is never triggered for the same file.
切换到同一文件的语音(如复制的语音笔记)时,MPV 不重新进入 Playing
状态(已经在 Playing),导致 onGetState 中 Playing && m_isChangePlayFile 分支不被触发,m_isChangePlayFile 保持 true。播放结束时 Idle && !m_isChangePlayFile 为 false,playEnd 不发出,进度条不消失。
在 VlcPalyer::play() 的 playByName 之后,若 MPV 已处于 Playing 状态, 直接重置 m_isChangePlayFile 标志,不依赖 onGetState 触发。
Log: 修复复制语音切换播放后进度条不消失的问题
Bug: https://pms.uniontech.com/bug-view-365835.html
Influence: 修复后切换播放同一语音文件时进度条正常更新且播放结束后正常消失,不影响不同语音文件的正常播放。