Popcorn Maker – Bug 67

My second Popcorn Maker bug that is now up for review is bug 67. The issue is that users are able to change their video source to nothing, and doing so breaks the application. Below is a screenshot showing what happens when the media’s source is changed to nothing.

Popcorn Maker  No Video Source

The event handler that is responsible for changing the URL is in js/menu.js.

js/menu.js

      buttonManager.add( "change-url", $( ".change-url-btn" ), {
        click: function() {
          $(".media-title-div").html( $('#url').val() );
          popupManager.hidePopups();
          var newUrl = $('#url').val();
          if ( newUrl !== butter.currentMedia.url ) {
            butter.currentMedia.url = ( $('#url').val() );
            pm.toggleLoadingScreen( true );
            function changeComplete( media ) {
              pm.toggleLoadingScreen( false );
              butter.unlisten( "mediacontentchangecomplete", changeComplete );
            }
            butter.listen( "mediacontentchangecomplete", changeComplete );
          } //if
        } //click
      }); //change-url-btn

It turns out that butter broadcasts a “previewerfail” message when changing the media’s source fails. So, to fix this bug, all that needs to be added in is an event handler that will listen for the “previewerfail” message and revert the media’s source back to what it was originally.

      buttonManager.add( "change-url", $( ".change-url-btn" ), {
        click: function() {
          var newUrl = $('#url').val(),
          oldUrl = butter.currentMedia.url;
          popupManager.hidePopups();
          if ( newUrl !== butter.currentMedia.url ) {
            butter.currentMedia.url = newUrl;
            $(".media-title-div").html( newUrl );
            pm.toggleLoadingScreen( true );
            function changeComplete( media ) {
              pm.toggleLoadingScreen( false );
              butter.unlisten( "mediacontentchangecomplete", changeComplete );
            }
            function changeError( media ) {
              butter.currentMedia.url = oldUrl;
              $(".media-title-div").html( oldUrl );
              butter.unlisten( "previewerfail", changeError );
            }
            butter.listen( "mediacontentchangecomplete", changeComplete );
            butter.listen( "previewerfail", changeError );
          } //if
        } //click
      }); //change-url-btn

The diff for this commit is here.

While testing this out, I found another bug. If users enters in “badURL” as the media’s source, they are presented with an alert that tells them the loading failed, and allows them to enter in another URL. This is a good thing, but it only happens the first time. So if you once again chose “badURL” as the media’s source, Popcorn Maker would accept it, and would be left in a broken state. This patch also fixes this issue. Now the users will always be presented with an error message and a chance to correct it if the new media’s source fails for whatever reason.

Advertisements
This entry was posted in Open Source and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s