stopplay_waiting_thread.cpp 942 B

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