stopplay_waiting_thread.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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::stop()
  17. {
  18. *m_exit = true;
  19. m_cv.notify_all();
  20. }
  21. void StopWaitingThread::run()
  22. {
  23. // 这里建议用回调或轮询方式通知主线程
  24. if (!m_parent) return;
  25. m_parent->stopPlay();
  26. while (m_parent->isPlaying()) {
  27. if (m_exit && *m_exit) break;
  28. std::this_thread::sleep_for(std::chrono::milliseconds(2));
  29. }
  30. if (!m_exit) {
  31. m_parent->startToPlay(m_file.c_str());
  32. }
  33. // 可加日志
  34. }