stopplay_waiting_thread.cpp 1000 B

12345678910111213141516171819202122232425262728293031323334
  1. // ***********************************************************/
  2. // stopplay_waiting_thread.cpp
  3. //
  4. // Copy Right @ Steven Huang. All rights reserved.
  5. //
  6. // Waiting play-stop thread
  7. // ***********************************************************/
  8. #include "stopplay_waiting_thread.h"
  9. #include "playercontroller.h"
  10. #include <QLoggingCategory>
  11. Q_LOGGING_CATEGORY(playerControllerStopWaitingThread, "player.controller.StopWaitingThread")
  12. StopWaitingThread::StopWaitingThread(PlayerController* parent, const std::string& file)
  13. : m_file(file), m_parent(parent)
  14. {}
  15. StopWaitingThread::~StopWaitingThread() {}
  16. void StopWaitingThread::run()
  17. {
  18. // 这里建议用回调或轮询方式通知主线程
  19. if (!m_parent) return;
  20. m_parent->stopPlay();
  21. while (m_parent->isPlaying()) {
  22. if (isExit())
  23. break;
  24. std::this_thread::sleep_for(std::chrono::milliseconds(2));
  25. }
  26. if (!m_exit) {
  27. m_parent->startToPlay(m_file.c_str());
  28. }
  29. // 可加日志
  30. }