ENH: [STUDIO-2070] MediaCtrl on macOS: stop on player notify

Change-Id: I9b11a99e8b3f043ff4d8837cda89bc41bfb5eb0e
This commit is contained in:
chunmao.guo 2023-01-17 17:50:20 +08:00 committed by Lane.Wei
parent 6ea24dfd89
commit 5666f8fce9
2 changed files with 9 additions and 4 deletions

View file

@ -39,6 +39,8 @@ public:
protected:
void DoSetSize(int x, int y, int width, int height, int sizeFlags) override;
static void bambu_log(void const * ctx, int level, char const * msg);
private:
void create_player();
void * m_player = nullptr;

View file

@ -18,7 +18,7 @@
#define BAMBU_DYNAMIC
static void bambu_log(void const * ctx, int level, char const * msg)
void wxMediaCtrl2::bambu_log(void const * ctx, int level, char const * msg)
{
if (level == 1) {
wxString msg2(msg);
@ -26,11 +26,14 @@ static void bambu_log(void const * ctx, int level, char const * msg)
int n = msg2.find_last_of('[');
if (n != wxString::npos) {
long val = 0;
int * error = (int *) ctx;
wxMediaCtrl2 * ctrl = (wxMediaCtrl2 *) ctx;
if (msg2.SubString(n + 1, msg2.Length() - 2).ToLong(&val))
*error = (int) val;
ctrl->m_error = (int) val;
}
}
} else if (level < 0) {
wxMediaCtrl2 * ctrl = (wxMediaCtrl2 *) ctx;
ctrl->Stop();
}
BOOST_LOG_TRIVIAL(info) << msg;
}
@ -69,7 +72,7 @@ void wxMediaCtrl2::create_player()
NSView * imageView = (NSView *) GetHandle();
BambuPlayer * player = [cls alloc];
[player initWithImageView: imageView];
[player setLogger: bambu_log withContext: &m_error];
[player setLogger: bambu_log withContext: this];
m_player = player;
}