wildside96 / bst-player

Automatically exported from code.google.com/p/bst-player
0 stars 0 forks source link

Please leave timers running which cause constant exceptions #64

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a VLCPlayer:
final AbstractMediaPlayer player = new VLCPlayer (
  url,
  autoPlayFlag,
  height,
  width);
2. Add it to the layout
3. Let it play a bit
4. Close the layout

What is the expected output? What do you see instead?
I expect the player to go away quietly.
Instead I get these every 1000 milliseconds:

<00153> <Mon Jan 07 10:34:35 GMT-800 2013> <ERROR> <Controller> <>
exception message: Player not available, create an instance
exception: java.lang.IllegalStateException:<br><b>Player not available, create 
an instance</b><div class='log-stacktrace'>
    at Unknown.java_lang_Exception_Exception__Ljava_lang_String_2V(http://localhost:8000/portal/2D58896E8B0AAF3AD3A6A8D0A98B8272.cache.html@3)<br>
    at Unknown.java_lang_RuntimeException_RuntimeException__Ljava_lang_String_2V(http://localhost:8000/portal/2D58896E8B0AAF3AD3A6A8D0A98B8272.cache.html@55)<br>
    at Unknown.java_lang_IllegalStateException_IllegalStateException__Ljava_lang_String_2V(http://localhost:8000/portal/2D58896E8B0AAF3AD3A6A8D0A98B8272.cache.html@69)<br>
    at Unknown.com_bramosystems_oss_player_core_client_ui_VLCPlayer_$checkAvailable__Lcom_bramosystems_oss_player_core_client_ui_VLCPlayer_2V(http://localhost:8000/portal/2D58896E8B0AAF3AD3A6A8D0A98B8272.cache.html@11)<br>
    at Unknown.com_bramosystems_oss_player_core_client_ui_VLCPlayer_$getPlayPosition__Lcom_bramosystems_oss_player_core_client_ui_VLCPlayer_2D(http://localhost:8000/portal/2D58896E8B0AAF3AD3A6A8D0A98B8272.cache.html@3)<br>
    at Unknown.com_bramosystems_oss_player_core_client_skin_CustomPlayerControl_$updateSeekState__Lcom_bramosystems_oss_player_core_client_skin_CustomPlayerControl_2V(http://localhost:8000/portal/2D58896E8B0AAF3AD3A6A8D0A98B8272.cache.html@9)<br>
    at Unknown.com_bramosystems_oss_player_core_client_skin_CustomPlayerControl$2_run__V(http://localhost:8000/portal/2D58896E8B0AAF3AD3A6A8D0A98B8272.cache.html@3)<br>
    at Unknown.com_google_gwt_user_client_Timer_fire__V(http://localhost:8000/portal/2D58896E8B0AAF3AD3A6A8D0A98B8272.cache.html@8)<br>
    at Unknown.anonymous(http://localhost:8000/portal/2D58896E8B0AAF3AD3A6A8D0A98B8272.cache.html@11)<br>
    at Unknown.com_google_gwt_core_client_impl_Impl_apply__Ljava_lang_Object_2Ljava_lang_Object_2Ljava_lang_Object_2Ljava_lang_Object_2(http://localhost:8000/portal/2D58896E8B0AAF3AD3A6A8D0A98B8272.cache.html@21)<br>
    at Unknown.com_google_gwt_core_client_impl_Impl_entry0__Ljava_lang_Object_2Ljava_lang_Object_2Ljava_lang_Object_2Ljava_lang_Object_2(http://localhost:8000/portal/2D58896E8B0AAF3AD3A6A8D0A98B8272.cache.html@16)<br>
    at Unknown.anonymous(http://localhost:8000/portal/2D58896E8B0AAF3AD3A6A8D0A98B8272.cache.html@14)<br>

Versions:
bst-player 1.3, but it looks like 2.0 has the same problem
gwt 2.5.0
smartgwt 3.1p
chrome 23
FF 6

Please provide any additional information below.
It seems that the timers created are not canceled.
For example, com.bramosystems.oss.player.core.client.AbstractMediaPlayer 
creates a Timer in the constructor.
It should instead kill the timer when the widget gets detached/goes away, or at 
least automatically cancel on exception?

    /**
     * Constructor method.
     */
    public AbstractMediaPlayer() {
        readyCmdQueue = new HashMap<String, Command>();
        cmdKeys = new ArrayList<String>();

        addPlayerStateHandler(new PlayerStateHandler() {

            @Override
            public void onPlayerStateChanged(final PlayerStateEvent event) {
                Timer t = new Timer() {

                    @Override
                    public void run() {

                        // handle exceptions
                        try {
                            if (event.getPlayerState().equals(PlayerStateEvent.State.Ready)) {
                                // ensure commands are executed in the same sequence as added ...
                                Iterator<String> keys = cmdKeys.iterator();
                                while (keys.hasNext()) {
                                        readyCmdQueue.get(keys.next()).execute();
                                }
                                cmdKeys.clear();
                                readyCmdQueue.clear();
                            }
                        }
                        catch (final Exception e) {
                            // log
                            com.google.gwt.core.client.GWT.log ("killing timer because task threw exception: " + e.getClass ().getName () + ", message: " + e.getMessage ());

                            // cancel the timer
                            this.cancel ();
                        }
                    }
                };
                t.schedule(500);
            }
        });
    }

Original issue reported on code.google.com by shortpa...@gmail.com on 8 Jan 2013 at 3:35

GoogleCodeExporter commented 9 years ago
Hi,

All timers (including the one responsible for this exception) are cancelled 
whenever the player widget is unloaded.  If the layout calls 'onUnload' on all 
child widgets then this exception would not be raised.

How does your layout handle its child widgets when it is closed?

Original comment by sbrah...@gmail.com on 14 Jan 2013 at 10:49

GoogleCodeExporter commented 9 years ago
I am not sure.
I am using SmartGWT layouts this way:

final AbstractMediaPlayer player = new VLCPlayer (...);
final VLayout layout = new VLayout ();
layout.addMember (player);

Note, that VLayout.addMember () does the following, which wraps the 
AbstractMediaPlayer within a WidgetCanvas:

    public void addMember(Widget widget) {
        if (widget instanceof Canvas) {
            addMember((Canvas) widget);
        } else {
            addMember(new WidgetCanvas(widget));
        }
    }

I can definitely ask the SmartGWT guys and see what they say.

Meanwhile, you say that the timers are cancelled when the player widget 
receives an onUnload () invocation, but how does the timer cancel happen? I do 
not see any timer canceling nor unload () in AbstractMediaPlayer (version 1.3).

Original comment by shortpa...@gmail.com on 15 Jan 2013 at 7:17

GoogleCodeExporter commented 9 years ago
The timer you referenced in your post is not the cause of this exception.  That 
timer run only once and gets gc'ed eventually.

The timer concerned in this is in 
com.bramosystems.oss.player.core.client.skin.CustomPlayerControl, which is 
cancelled when the player widget is unloaded.

Original comment by sbrah...@gmail.com on 23 Jan 2013 at 3:56

GoogleCodeExporter commented 9 years ago
I reference 2 timers:
1. CustomPlayerControl, which I get every 1000 milliseconds after the player 
goes away from the screen, and
2. AbstractMediaPlayer, as an example of where a timer is created but not 
explicitly destroyed

In case #1, the timer gets cancelled when the player is unloaded, so it must 
mean that the player is not getting unloaded in my case. Other than changing 
the player reference to null, do you know if there is a way to force the unload 
or destroy of the player?  This might even be a SmartGWT side-effect, and I am 
happy to continue testing things and push to them if it's something that they 
can address -- they are pretty good about fixing things... This would mean that 
your player could have an additional audience: the smartgwt developers. Because 
in the meantime, the exceptions that popup every second render the gwt log 
unreadable...

In case #2, as I said in my original post, I was just giving you an example of 
where the timer is not explicitly destroyed. Follow-up question (just 
curiosity), why are you using a timer with a delay of 500 and not a GWT 
deferred command, for example -- does that run too quickly?
    final Scheduler scheduler = Scheduler.get ();
    scheduler.scheduleDeferred (new Scheduler.ScheduledCommand() {
      public void execute() {
        ...
      }
    });

Original comment by shortpa...@gmail.com on 23 Jan 2013 at 5:42