wx.media.MediaCtrl EVT_MEDIA_LOADED on Windows, plus a Timer events question

1,211 views
Skip to first unread message

Transana

unread,
Aug 12, 2019, 3:16:03 PM8/12/19
to wxpytho...@googlegroups.com
I'm using Python 3.7 and wxPython 4.0.6.  I use the same code on both
MacOS and Windows.

tldr:

Can anyone confirm for me that wx.media.EVT_MEDIA_LOADED does not get
called on Windows?

Also, there are some instances where my EVT_TIMER events are not getting
fired.  Do Timer events depend on idle time to fire?

Long version:

For the last 20 years, I've written and maintained a cross-platform
program that specializes in the academic analysis of the contents of
video and audio data.  I have relied upon a 32-bit Python 2.7 wxPython
3.0.2.0 version of my software for the last several years, and am
finally taking the plunge to upgrade to Python 3.7 wxPython 4.0.6.

One feature of my software is that it supports multiple simultaneous
media files.  I have historically relied on the EVT_MEDIA_LOADED event
to allow me to wait for large data files to load before working on tasks
relating to synchronizing the files into a visually unified data
stream.  Sometimes files are very large, sometimes there are multiple
files, and sometimes files must be pulled off a network server, which
slows the load process down.  EVT_MEDIA_LOADED has historically worked
very well for this.

At present, my EVT_MEDIA_LOADED handler never gets called on Windows
like it does on MacOS.  Is that event handler broken on Windows in
wxPython 4.0.6?

I am also noticing that EVT_TIMER events don't seem to fire 100% of the
time.  They work perfectly most of the time, but every once in a while,
they fail.  My current hypothesis is that this happens primarily during
the loading of some media files sometimes.  (The failure is sporadic,
inconsistent, and hard to reproduce across test runs.  It only happens
with some files, only with video as opposed to audio, and only with
certain video formats, perhaps different formats on different OSes.  It
also might be more likely the first time I load a file after I've taken
a break, when maybe the computer or network doesn't have the data
cached.)  I think I've noticed that my wx.EVT_IDLE events are not firing
when the timers fail, but I'm still working to confirm that.  EVT_IDLE
call frequency also varies a surprising amount based on media formats.

(I originally tried to use Timers to track media position, as was in
multiple sample programs I found.  When that wasn't completely reliable,
I shifted to a wx.EVT_IDLE model.  It's better, but still not perfect.)

So are Timers linked to idle time?  Does this make any sense? Does
anyone have any alternate theories for me to look into?

Thanks in advance,

David

--
David K. Woods, Ph.D.
President, Researcher, and Lead Transana Developer
https://www.transana.com

Tim Roberts

unread,
Aug 12, 2019, 4:46:27 PM8/12/19
to 'Khanh D Dang' via wxPython-users
On Aug 12, 2019, at 12:15 PM, Transana <tran...@gmail.com> wrote:
>
> I'm using Python 3.7 and wxPython 4.0.6. I use the same code on both MacOS and Windows.
>
> Can anyone confirm for me that wx.media.EVT_MEDIA_LOADED does not get called on Windows?

This one I do not know.

> Also, there are some instances where my EVT_TIMER events are not getting fired. Do Timer events depend on idle time to fire?

Yes. Most window messages in Windows are placed in a queue, so if they fire multiple times, you’ll get multiple calls. But WM_PAINT and WM_TIMER are handled differently. Instead of being queued, they just set a flag in the window data structure. When the message queue goes empty, GetMessage will check to see if either the WM_PAINT or WM_TIMER flag is set, and if it is, it will dispatch the message.

So, if you receive six WM_TIMER (or WM_PAINT) hits before you empty your message queue, you’ll only get one dispatch.

Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

Robin Dunn

unread,
Aug 13, 2019, 12:40:12 PM8/13/19
to wxPython-users
On Monday, August 12, 2019 at 1:46:27 PM UTC-7, Tim Roberts wrote:
On Aug 12, 2019, at 12:15 PM, Transana <tran...@gmail.com> wrote:
>
> I'm using Python 3.7 and wxPython 4.0.6.  I use the same code on both MacOS and Windows.
>
> Can anyone confirm for me that wx.media.EVT_MEDIA_LOADED does not get called on Windows?

This one I do not know.


It may depend somewhat on the mediactrl backend in use, but I see calls to NotifyMovieLoaded in all the MSW backends, and that is where the EVT_MEDIA_LOADED event is sent from. So it looks like it is at least intended for it to be sent, but there could be some reason it is not getting to the point where NotifyMovieLoaded is sent. For example, there is a comment in the MP10 backend that indicates that the wxWidgets code might not be called until the movie is "about to play."

--
Robin

Transana

unread,
Aug 13, 2019, 8:13:24 PM8/13/19
to wxpytho...@googlegroups.com

Thanks Robin and Tim. 

Getting consistent behavior across platforms and media formats has been really tricky, even just using the WMP10 backend on Windows and the QuickTime back end on MacOS.  Having wx.media events and wx.Timer events behaving inconsistently adds to the challenge, but it kind of makes sense that these problems are tied to the quirks of different media formats.  I'm really close to getting what I want using flag variables and EVT_IDLE processing.  It's inelegant at times, especially when I load videos from a server for the first time which causes a long wait for necessary information to become available. 

And unfortunately, GetBestSize() doesn't appear to be working on Windows either.  I get (20, 20) for everything.

Reply all
Reply to author
Forward
0 new messages