mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-08 23:46:24 -06:00
FIX: media play state conflict when switch device
Change-Id: I95680159a50b2085cb6de5b7cd612d6b444a6446
This commit is contained in:
parent
3c8d9be77e
commit
2ecdf43ca1
4 changed files with 38 additions and 23 deletions
|
@ -17,6 +17,7 @@ MediaPlayCtrl::MediaPlayCtrl(wxWindow *parent, wxMediaCtrl2 *media_ctrl, const w
|
|||
m_media_ctrl->Bind(wxEVT_MEDIA_STATECHANGED, &MediaPlayCtrl::onStateChanged, this);
|
||||
|
||||
m_button_play = new Button(this, "", "media_play", wxBORDER_NONE);
|
||||
m_button_play->SetCanFocus(false);
|
||||
|
||||
m_label_status = new Label(this);
|
||||
|
||||
|
@ -27,12 +28,7 @@ MediaPlayCtrl::MediaPlayCtrl(wxWindow *parent, wxMediaCtrl2 *media_ctrl, const w
|
|||
Bind(wxEVT_RIGHT_UP, [this](auto & e) { wxClipboard & c = *wxTheClipboard; if (c.Open()) { c.SetData(new wxTextDataObject(m_url)); c.Close(); } });
|
||||
|
||||
wxBoxSizer * sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
sizer->Add(m_button_play, 0, wxEXPAND | wxALL, 0)
|
||||
#if BBL_RELEASE_TO_PUBLIC
|
||||
->Show(false);
|
||||
#else
|
||||
;
|
||||
#endif
|
||||
sizer->Add(m_button_play, 0, wxEXPAND | wxALL, 0);
|
||||
sizer->AddStretchSpacer(1);
|
||||
sizer->Add(m_label_status, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, FromDIP(25));
|
||||
SetSizer(sizer);
|
||||
|
@ -40,6 +36,10 @@ MediaPlayCtrl::MediaPlayCtrl(wxWindow *parent, wxMediaCtrl2 *media_ctrl, const w
|
|||
m_thread = boost::thread([this] {
|
||||
media_proc();
|
||||
});
|
||||
|
||||
#if BBL_RELEASE_TO_PUBLIC
|
||||
m_next_retry = wxDateTime::Now();
|
||||
#endif
|
||||
}
|
||||
|
||||
MediaPlayCtrl::~MediaPlayCtrl()
|
||||
|
@ -64,16 +64,16 @@ void MediaPlayCtrl::SetMachineObject(MachineObject* obj)
|
|||
m_failed_retry = 0;
|
||||
if (m_last_state != MEDIASTATE_IDLE)
|
||||
Stop();
|
||||
#if BBL_RELEASE_TO_PUBLIC
|
||||
Play();
|
||||
#else
|
||||
SetStatus("");
|
||||
#endif
|
||||
if (m_next_retry.IsValid())
|
||||
Play();
|
||||
else
|
||||
SetStatus("");
|
||||
}
|
||||
|
||||
void MediaPlayCtrl::Play()
|
||||
{
|
||||
if (m_machine.empty()) {
|
||||
Stop();
|
||||
SetStatus(_L("Initialize failed (No Device)!"));
|
||||
return;
|
||||
}
|
||||
|
@ -121,21 +121,24 @@ void MediaPlayCtrl::Stop()
|
|||
boost::unique_lock lock(m_mutex);
|
||||
m_tasks.push_back("<stop>");
|
||||
m_cond.notify_all();
|
||||
m_last_state = MEDIASTATE_IDLE;
|
||||
SetStatus(_L("Stopped."));
|
||||
}
|
||||
m_last_state = MEDIASTATE_IDLE;
|
||||
SetStatus(_L("Stopped."));
|
||||
++m_failed_retry;
|
||||
#if BBL_RELEASE_TO_PUBLIC
|
||||
m_next_retry = wxDateTime::Now() + wxTimeSpan::Seconds(5 * m_failed_retry);
|
||||
#endif
|
||||
if (m_next_retry.IsValid())
|
||||
m_next_retry = wxDateTime::Now() + wxTimeSpan::Seconds(5 * m_failed_retry);
|
||||
}
|
||||
|
||||
void MediaPlayCtrl::TogglePlay()
|
||||
{
|
||||
if (m_last_state != MEDIASTATE_IDLE)
|
||||
if (m_last_state != MEDIASTATE_IDLE) {
|
||||
m_next_retry = wxDateTime();
|
||||
Stop();
|
||||
else
|
||||
} else {
|
||||
m_failed_retry = 0;
|
||||
m_next_retry = wxDateTime::Now();
|
||||
Play();
|
||||
}
|
||||
}
|
||||
|
||||
void MediaPlayCtrl::SetStatus(wxString const& msg2)
|
||||
|
@ -203,7 +206,6 @@ void MediaPlayCtrl::onStateChanged(wxMediaEvent& event)
|
|||
if (last_state == MEDIASTATE_IDLE && state == wxMEDIASTATE_STOPPED) {
|
||||
return;
|
||||
}
|
||||
m_last_state = state;
|
||||
if ((last_state == wxMEDIASTATE_PAUSED || last_state == wxMEDIASTATE_PLAYING) &&
|
||||
state == wxMEDIASTATE_STOPPED) {
|
||||
Stop();
|
||||
|
@ -214,6 +216,7 @@ void MediaPlayCtrl::onStateChanged(wxMediaEvent& event)
|
|||
BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl::onStateChanged: size: " << size.x << "x" << size.y;
|
||||
m_failed_code = m_media_ctrl->GetLastError();
|
||||
if (size.GetWidth() > 1000) {
|
||||
m_last_state = state;
|
||||
SetStatus(_L("Playing..."));
|
||||
m_failed_retry = 0;
|
||||
boost::unique_lock lock(m_mutex);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue