Skip to content

Commit

Permalink
Prevent errors when calling methods while the player is destroied
Browse files Browse the repository at this point in the history
  • Loading branch information
pupunzi committed Oct 1, 2017
1 parent 3ab65f2 commit c232efa
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
"test",
"tests"
],
"buildnum": "6397"
"buildnum": "6406"
}
4 changes: 2 additions & 2 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
<meta charset="UTF-8">
<title>youtube Chromeless Player - mb.YTPlayer</title>
<link href='//fonts.googleapis.com/css?family=Lekton|Lobster' rel='stylesheet' type='text/css'>
<link href="css/jquery.mb.YTPlayer.min.css?_bn=6397" media="all" rel="stylesheet" type="text/css">
<link href="css/jquery.mb.YTPlayer.min.css?_bn=6406" media="all" rel="stylesheet" type="text/css">
<script src="//code.jquery.com/jquery-3.0.0.min.js"></script>
<script src="jquery.mb.YTPlayer.js?_bn=6397"></script>
<script src="jquery.mb.YTPlayer.js?_bn=6406"></script>
<script src="../examples/assets/apikey.js"></script>
<style>
*:focus {
Expand Down
39 changes: 36 additions & 3 deletions dist/jquery.mb.YTPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var getYTPVideoID = function( url ) {
jQuery.mbYTPlayer = {
name: "jquery.mb.YTPlayer",
version: "3.1.0",
build: "6397",
build: "6406",
author: "Matteo Bicocchi (pupunzi)",
apiKey: "",
defaults: {
Expand Down Expand Up @@ -911,6 +911,10 @@ var getYTPVideoID = function( url ) {
*/
fullscreen: function( real ) {
var YTPlayer = this.get( 0 );

if( !YTPlayer.player.length )
return

if( typeof real == "undefined" ) real = YTPlayer.opt.realfullscreen;
real = eval( real );
var controls = jQuery( "#controlBar_" + YTPlayer.id );
Expand Down Expand Up @@ -1100,6 +1104,10 @@ var getYTPVideoID = function( url ) {
*/
togglePlay: function( callback ) {
var YTPlayer = this.get( 0 );

if( !YTPlayer.player.length )
return;

if( YTPlayer.state == 1 )
this.YTPPause();
else
Expand Down Expand Up @@ -1132,6 +1140,10 @@ var getYTPVideoID = function( url ) {
*/
pause: function() {
var YTPlayer = this.get( 0 );

if( !YTPlayer.player.length )
return;

YTPlayer.player.pauseVideo();
YTPlayer.state = 2;
return this;
Expand All @@ -1145,6 +1157,10 @@ var getYTPVideoID = function( url ) {
*/
seekTo: function( val ) {
var YTPlayer = this.get( 0 );

if( !YTPlayer.player.length )
return;

YTPlayer.player.seekTo( val, true );
return this;
},
Expand All @@ -1157,6 +1173,10 @@ var getYTPVideoID = function( url ) {
*/
setVolume: function( val ) {
var YTPlayer = this.get( 0 );

if( !YTPlayer.player.length )
return;

if( !val && !YTPlayer.opt.vol && YTPlayer.player.getVolume() == 0 )
jQuery( YTPlayer ).YTPUnmute();
else if( ( !val && YTPlayer.player.getVolume() > 0 ) || ( val && YTPlayer.opt.vol == val ) ) {
Expand All @@ -1179,7 +1199,10 @@ var getYTPVideoID = function( url ) {
*/
toggleVolume: function() {
var YTPlayer = this.get( 0 );
if( !YTPlayer ) return;

if( !YTPlayer.player.length )
return;

if( YTPlayer.player.isMuted() ) {
jQuery( YTPlayer ).YTPUnmute();
return true;
Expand All @@ -1196,6 +1219,10 @@ var getYTPVideoID = function( url ) {
*/
mute: function() {
var YTPlayer = this.get( 0 );

if( !YTPlayer.player.length )
return;

if( YTPlayer.isMute ) return;
YTPlayer.player.mute();
YTPlayer.isMute = true;
Expand All @@ -1221,7 +1248,13 @@ var getYTPVideoID = function( url ) {
*/
unmute: function() {
var YTPlayer = this.get( 0 );
if( !YTPlayer.isMute ) return;

if( !YTPlayer.player.length )
return;

if( !YTPlayer.isMute )
return;

YTPlayer.player.unMute();
YTPlayer.isMute = false;
YTPlayer.player.setVolume( YTPlayer.opt.vol );
Expand Down
4 changes: 2 additions & 2 deletions dist/jquery.mb.YTPlayer.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@
"directories": {
"example": "examples"
},
"buildnum": "6397"
"buildnum": "6406"
}
37 changes: 35 additions & 2 deletions src/jquery.mb.YTPlayer.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,10 @@ var getYTPVideoID = function( url ) {
*/
fullscreen: function( real ) {
var YTPlayer = this.get( 0 );

if( !YTPlayer.player.length )
return this;

if( typeof real == "undefined" ) real = YTPlayer.opt.realfullscreen;
real = eval( real );
var controls = jQuery( "#controlBar_" + YTPlayer.id );
Expand Down Expand Up @@ -1100,6 +1104,10 @@ var getYTPVideoID = function( url ) {
*/
togglePlay: function( callback ) {
var YTPlayer = this.get( 0 );

if( !YTPlayer.player.length )
return this;

if( YTPlayer.state == 1 )
this.YTPPause();
else
Expand Down Expand Up @@ -1132,6 +1140,10 @@ var getYTPVideoID = function( url ) {
*/
pause: function() {
var YTPlayer = this.get( 0 );

if( !YTPlayer.player.length )
return this;

YTPlayer.player.pauseVideo();
YTPlayer.state = 2;
return this;
Expand All @@ -1145,6 +1157,10 @@ var getYTPVideoID = function( url ) {
*/
seekTo: function( val ) {
var YTPlayer = this.get( 0 );

if( !YTPlayer.player.length )
return this;

YTPlayer.player.seekTo( val, true );
return this;
},
Expand All @@ -1157,6 +1173,10 @@ var getYTPVideoID = function( url ) {
*/
setVolume: function( val ) {
var YTPlayer = this.get( 0 );

if( !YTPlayer.player.length )
return;

if( !val && !YTPlayer.opt.vol && YTPlayer.player.getVolume() == 0 )
jQuery( YTPlayer ).YTPUnmute();
else if( ( !val && YTPlayer.player.getVolume() > 0 ) || ( val && YTPlayer.opt.vol == val ) ) {
Expand All @@ -1179,7 +1199,10 @@ var getYTPVideoID = function( url ) {
*/
toggleVolume: function() {
var YTPlayer = this.get( 0 );
if( !YTPlayer ) return;

if( !YTPlayer.player.length )
return this;

if( YTPlayer.player.isMuted() ) {
jQuery( YTPlayer ).YTPUnmute();
return true;
Expand All @@ -1196,6 +1219,10 @@ var getYTPVideoID = function( url ) {
*/
mute: function() {
var YTPlayer = this.get( 0 );

if( !YTPlayer.player.length )
return;

if( YTPlayer.isMute ) return;
YTPlayer.player.mute();
YTPlayer.isMute = true;
Expand All @@ -1221,7 +1248,13 @@ var getYTPVideoID = function( url ) {
*/
unmute: function() {
var YTPlayer = this.get( 0 );
if( !YTPlayer.isMute ) return;

if( !YTPlayer.player.length )
return this;

if( !YTPlayer.isMute )
return this;

YTPlayer.player.unMute();
YTPlayer.isMute = false;
YTPlayer.player.setVolume( YTPlayer.opt.vol );
Expand Down

0 comments on commit c232efa

Please sign in to comment.