pupunzi / jquery.mb.YTPlayer

use a custom yutube player for a video as background on jQuery framework
https://pupunzi.com/mb.components/mb.YTPlayer/demo/demo.html
1.33k stars 429 forks source link

onError #317

Closed ak545 closed 6 years ago

ak545 commented 6 years ago

Hi, pupunzi! This piece of code:

                            'onError': function( err ) {
                                    if( err.data == 150 ) {
                                        console.log( "Embedding this video is restricted by Youtube." );
                                        alert( "mb.YTPlayer: Embedding this video (" + YTPlayer.videoID + ") is restricted by Youtube" );
                                        if( YTPlayer.isList )
                                            jQuery( YTPlayer ).YTPPlayNext();
                                    }

                                    if( err.data == 2 && YTPlayer.isList ) {
                                        jQuery( YTPlayer ).YTPPlayNext();
                                    }

                                    if( typeof YTPlayer.opt.onError == "function" )
                                        YTPlayer.opt.onError( $YTPlayer, err );
                                }

should be done like this:


                                'onError': function( err ) {
                                    if( typeof YTPlayer.opt.onError == "function" ) {
                                        YTPlayer.opt.onError( $YTPlayer, err );
                                    } else {

                                        if( err.data == 150 ) {
                                            console.log( "Embedding this video is restricted by Youtube." );
                                            alert( "mb.YTPlayer: Embedding this video (" + YTPlayer.videoID + ") is restricted by Youtube" );
                                            if( YTPlayer.isList )
                                                jQuery( YTPlayer ).YTPPlayNext();
                                        }

                                        if( err.data == 2 && YTPlayer.isList ) {
                                            jQuery( YTPlayer ).YTPPlayNext();
                                        }
                                    }
                                }

If a user function is specified, then execute it. If not, then perform the standard. Best Regards, Andrey Klimov :)

pupunzi commented 6 years ago

The one specified by the user should be executed in conjunction with the others that must be executed anyway.

ak545 commented 6 years ago

Now after YTPPlayNext in the standard error handler in the user function, the VideoID is already different (not the one that caused the error), So, if I want to track the video's restricted, I do not recognize its ID because mb.YTPlayer first calls the video change method (jQuery( YTPlayer ).YTPPlayNext();), and after that calls the user function.

pupunzi commented 6 years ago

The solution is to execute the user callback before the others :

'onError': function( err ) {

    if( typeof YTPlayer.opt.onError == "function" )
        YTPlayer.opt.onError( $YTPlayer, err );

    switch (err.data) {
        case 2:
                      console.error( "video ID:: " + YTPlayer.videoID + ": The request contains an invalid parameter value. For example, this error occurs if you specify a video ID that does not have 11 characters, or if the video ID contains invalid characters, such as exclamation points or asterisks." );
        case 5:
                      console.error( "video ID:: " + YTPlayer.videoID + ": The requested content cannot be played in an HTML5 player or another error related to the HTML5 player has occurred." );
        case 100:
                      console.error( "video ID:: " + YTPlayer.videoID + ": The video requested was not found. This error occurs when a video has been removed (for any reason) or has been marked as private." );
        case 101:
        case 150:
                      console.error( "video ID:: " + YTPlayer.videoID + ": The owner of the requested video does not allow it to be played in embedded players." );
    }

    if( YTPlayer.isList )
        jQuery( YTPlayer ).YTPPlayNext();

}
ak545 commented 6 years ago

Yes exactly. Thank you!