zhuizhu 8 ماه پیش
والد
کامیت
84916d05a8
1فایلهای تغییر یافته به همراه29 افزوده شده و 2 حذف شده
  1. 29 2
      AvPlayer2/playercontroller.cpp

+ 29 - 2
AvPlayer2/playercontroller.cpp

@@ -306,7 +306,19 @@ QString PlayerController::playingFile() const
 
 
 bool PlayerController::isPlaying() const
 bool PlayerController::isPlaying() const
 {
 {
-    return m_state == PlayerState::Playing;
+    // 不仅检查状态标志,还检查线程是否实际运行
+    if (m_state != PlayerState::Playing) {
+        return false;
+    }
+    
+    // 如果状态是Playing但所有线程都已停止,则实际上不是在播放状态
+    if (areAllThreadsStopped()) {
+        qCDebug(playerControllerLog) << "[isPlaying] State is Playing but all threads stopped";
+
+        return false;
+    }
+    
+    return true;
 }
 }
 
 
 bool PlayerController::playingHasVideo()
 bool PlayerController::playingHasVideo()
@@ -354,6 +366,17 @@ void PlayerController::playStarted(bool success)
 
 
 void PlayerController::playFailed(const QString& file)
 void PlayerController::playFailed(const QString& file)
 {
 {
+    qCWarning(playerControllerLog) << "Playback failed for file:" << toNativePath(file);
+    
+    // 确保状态一致性
+    if (m_state != PlayerState::Idle) {
+        // 检查线程状态并重置
+        if (!areAllThreadsStopped()) {
+            qCDebug(playerControllerLog) << "Some threads still running, stopping them first";
+            stopAndResetThreads();
+        }
+    }
+    
     emit showMessage(QString("Playback failed: %1").arg(toNativePath(file)), "Warning", "");
     emit showMessage(QString("Playback failed: %1").arg(toNativePath(file)), "Warning", "");
 }
 }
 
 
@@ -363,30 +386,34 @@ void PlayerController::readPacketStopped()
     qCDebug(playerControllerLog) << "************* Read packets thread stopped signal received.";
     qCDebug(playerControllerLog) << "************* Read packets thread stopped signal received.";
     //m_packetReadThread.reset();
     //m_packetReadThread.reset();
 
 
-    // stopPlay();
     if (m_videoState) {
     if (m_videoState) {
         m_videoState->delete_video_state();
         m_videoState->delete_video_state();
     }
     }
 
 
     emit audioStopped();
     emit audioStopped();
 }
 }
+
 void PlayerController::decodeVideoStopped()
 void PlayerController::decodeVideoStopped()
 {
 {
     qCDebug(playerControllerLog) << "************* Video decode thread stopped.";
     qCDebug(playerControllerLog) << "************* Video decode thread stopped.";
 }
 }
+
 void PlayerController::decodeAudioStopped()
 void PlayerController::decodeAudioStopped()
 {
 {
     qCDebug(playerControllerLog) << "************* Audio decode thread stopped.";
     qCDebug(playerControllerLog) << "************* Audio decode thread stopped.";
 }
 }
+
 void PlayerController::decodeSubtitleStopped()
 void PlayerController::decodeSubtitleStopped()
 {
 {
     qCDebug(playerControllerLog) << "************* Subtitle decode thread stopped.";
     qCDebug(playerControllerLog) << "************* Subtitle decode thread stopped.";
 }
 }
+
 void PlayerController::audioPlayStopped()
 void PlayerController::audioPlayStopped()
 {
 {
     qCDebug(playerControllerLog) << "************* Audio play thread stopped.";
     qCDebug(playerControllerLog) << "************* Audio play thread stopped.";
     emit audioStopped();
     emit audioStopped();
 }
 }
+
 void PlayerController::videoPlayStopped()
 void PlayerController::videoPlayStopped()
 {
 {
     qCDebug(playerControllerLog) << "************* Video play thread stopped.";
     qCDebug(playerControllerLog) << "************* Video play thread stopped.";