#include "stopplay_waiting_thread.h"
#include "playercontroller.h"
#include <QLoggingCategory>
Q_LOGGING_CATEGORY(playerControllerStopWaitingThread, "player.controller.StopWaitingThread")

StopWaitingThread::StopWaitingThread(PlayerController* parent, const std::string& file)
    : m_file(file), m_parent(parent)
{}

StopWaitingThread::~StopWaitingThread() {}


void StopWaitingThread::run()
{
    // 这里建议用回调或轮询方式通知主线程
    if (!m_parent) return;
    m_parent->stopPlay();
    while (m_parent->isPlaying()) {
        if (isExit())
            break;
        std::this_thread::sleep_for(std::chrono::milliseconds(2));
    }
    if (!m_exit) {
        m_parent->startToPlay(m_file.c_str());
    }
    // 可加日志
}
