Project

General

Profile

WMediaPlayer and js timeupdate events

Added by Emeric Poupon about 7 years ago

Hello,

I know nothing about js and I hit some trouble to get the js timeupdate event of a jPlayer instance.

What I want is to update a Wt::Wtext using the current playing time, client side.

Here is the only thing I managed to do:

       _curTime = new Wt::WText(this);

       if (Wt::WApplication::instance()->environment().javaScript())
       {
               _timeUpdated = new Wt::JSlot(this);

               _timeUpdated->setJavaScript("\
                       function(obj, event) {\n\
                               " + _curTime->jsRef() + ".innerHTML = \"TEST\";\n\
                       }\n");

               _mediaPlayer->timeUpdated().connect( *_timeUpdated );
       }

The JSlot seems to be called at 4Hz, but unfortunately the 'event' does not seem to be set/usable

However I do manage to change the _curTime contents using this static string as shown in the example.

How can I make this work?

Best Regards,

Emeric


Replies (6)

RE: WMediaPlayer and js timeupdate events - Added by Koen Deforche about 7 years ago

Hey Emeric,

The additional JSignal arguments are passed as additional JavaScript arguments, but unfortunately it seems that timeUpdated() does not actually pass on the time (how silly).

I've made the change in my copy so that it's a JSignal which gets the updated time.

In this way you can do:

_timeUpdated->setJavaScript("\
                       function(obj, event, a1) {\n\
                               " + _curTime->jsRef() + ".innerHTML = a1;\n\
                       }\n");

RE: WMediaPlayer and js timeupdate events - Added by Emeric Poupon almost 7 years ago

Thanks a lot for your support,

I will try soon on the latest Wt git version.

Emeric

RE: WMediaPlayer and js timeupdate events - Added by Emeric Poupon almost 7 years ago

Hello,

Unfortunately, this does not seem to work, using the latest git version:

The innerHTML of my current time widget is set to "undefined"

Maybe I missed something?

       _curTime = new Wt::WText(this);

        if (Wt::WApplication::instance()->environment().javaScript())
        {
                _timeUpdated = new Wt::JSlot(this);

                _timeUpdated->setJavaScript("\  
                                function(obj, event, a1) {\n\
                                " + _curTime->jsRef() + ".innerHTML = a1;\n\
                                }\n");

                _mediaPlayer->timeUpdated().connect( *_timeUpdated );
        }

RE: WMediaPlayer and js timeupdate events - Added by Koen Deforche almost 7 years ago

Hey,

If you use a JSlot, then you need to set the number of (user) arguments in the constructor:

  new Wt::JSlot("", 1, this);

or

  _timeUpdated->setJavaScript("\  
                                function(obj, event, a1) {\n\
                                " + _curTime->jsRef() + ".innerHTML = a1;\n\
                                }\n", 1);  

Koen

RE: WMediaPlayer and js timeupdate events - Added by Emeric Poupon almost 7 years ago

Hello,

Thanks for you response.

                _timeUpdated = new Wt::JSlot(this);

                _timeUpdated->setJavaScript("\
                                function(obj, event, a1) {\n\
                                " + _curTime->jsRef() + ".innerHTML = a1;\n\
                                }\n", 1);

                _mediaPlayer->timeUpdated().connect( *_timeUpdated );

-> still get 'undefined' in the innerHTML.

                _timeUpdated = new Wt::JSlot("", 1, this);

                _timeUpdated->setJavaScript("\
                                function(obj, event, a1) {\n\
                                " + _curTime->jsRef() + ".innerHTML = a1;\n\
                                }\n");

                _mediaPlayer->timeUpdated().connect( *_timeUpdated );

-> I get disconnected when creating the widget: it seems to be related to the "new session id"?

[2015-Sep-30 14:08:14.321051] 4634 [/ RgBevQN7lsUnlAjD] [debug] - [UI] Creating root widget. First connection = 0

[2015-Sep-30 14:08:14.321534] 4634 [/ RgBevQN7lsUnlAjD] [warning] "WApplication: WApplication::addMetaHeader() with no effect"

[2015-Sep-30 14:08:16.272099] 4634 [/ nGDAkiakVwfKReYR] [info] "Wt: new session id for RgBevQN7lsUnlAjD"

[2015-Sep-30 14:08:16.272385] 4634 [/ nGDAkiakVwfKReYR] [info] - [UI] User 'admin' logged in from '127.0.0.1', user agent = 6107, session = nGDAkiakVwfKReYR

...

127.0.0.1 - - [2015-Sep-30 14:08:17.322924] "POST /?wtd=RgBevQN7lsUnlAjD HTTP/1.1" 200 32157

[2015-Sep-30 14:08:17.322980] 4634 - [info] "WebRequest: took 1155.27ms"

[2015-Sep-30 14:08:17.345115] 4634 - [info] "Wt: session created (#sessions = 2)"

[2015-Sep-30 14:08:17.345195] 4634 [/ Bs1HCznQOpv8GxUy] [info] "WEnvironment: UserAgent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0 Iceweasel/38.2.1"

[2015-Sep-30 14:08:17.345238] 4634 [/ Bs1HCznQOpv8GxUy] [info] "Wt: signal from dead session, sending reload."

[2015-Sep-30 14:08:17.345274] 4634 - [info] "WebController: Removing session Bs1HCznQOpv8GxUy"

                _timeUpdated = new Wt::JSlot(
                                "function(obj, event, a1) {\n\
                                " + _curTime->jsRef() + ".innerHTML = a1;\n\
                                }\n",
                                1,
                                this);

                _mediaPlayer->timeUpdated().connect( *_timeUpdated );

-> It works :)

What do you thinK?

RE: WMediaPlayer and js timeupdate events - Added by Koen Deforche almost 7 years ago

Hey,

I'm not sure why Wt::Auth's session change on login interferes with this javascript function. I've filed this as a bug (#4497).

Koen

    (1-6/6)