Large

YouTube HD Ultimate

By Avindra V.G. Last update Dec 10, 2010 — Installed 402,101 times.

Feature request

in
Subscribe to Feature request 6 posts, 2 voices



zornn User

Any way you could add an option to pause the video if clicked on it? This script http://userscripts.org/scripts/show/41691 lets you do it, but it's overall too bloated and changes the layout too much so I don't use it. Thanks.

Edit: I know JoeSimmons tried once but couldn't get it to work with the click. http://userscripts.org/scripts/show/40997

 
JoeSimmons Scriptwright
x0rnn wrote:
Edit: I know JoeSimmons tried once but couldn't get it to work with the click. http://userscripts.org/scripts/show/40997
Yeah I did try once. I'm thinking (now, not then) of getting the x and y coordinates of the player, then creating a box to go over the video (not the controls).
 
zornn User

Cool. Hope you get it to work this time! You'll also have to subtract 100px or so from the Y axis or else the video will always pause when you adjust the volume.

 
JoeSimmons Scriptwright

It's 25px, and I thought of that too. Unfortunately my idea did not work. I can add a div over the video and have the mosueover work but the onclick won't work.

 
zornn User

Well, I dissected that VidzBigger script and extracted the parts that make the pause on click work:

var unwin=unsafeWindow;
unwin.playerState=1;
player=document.getElementById('movie_player');
uwPlayer=player.wrappedJSObject;

function getFlashVar(varName){
	// Gets the flashvars from the player
	if(!player.getAttribute) return;
	var flashVars=String(player.getAttribute("flashvars"));
	// Searchs for the varName in the flashvars
	var queryRE=new RegExp("(?:^|&)"+varName+"=([^&]*)");
	var queryRet=queryRE.exec(flashVars);
	// Returns the corresponding value or null (if not found)
	return (queryRet===null) ? null : queryRet[1];
}

function setFlashVar(varName,varNewValue){
	// Gets varName value now and the flashvars from the player
	var varValue=getFlashVar(varName);
	var flashVars=String(player.getAttribute("flashvars"));
	// If varName isn't set,just adds it
	// If varName is set,replaces its value with varNewValue
	if (varValue===null){
		player.setAttribute("flashvars",flashVars+"&"+varName+"="+varNewValue);
	}
	else{
		var replaceRE=new RegExp("(^|&)"+varName+"="+varValue);
		flashVars=flashVars.replace(replaceRE,"$1"+varName+"="+varNewValue);
		player.setAttribute("flashvars",flashVars);
	}
}

unwin.gsPlayerReady=function(playerId){
	// Initializes the "first reproduction" flag
	// Tries to register the state change event listener
	// This sometimes fails for unknown reasons,so the error is cached and the player reloaded up to 4 times to try to do it again
	try{
		uwPlayer.addEventListener("onStateChange","gsStateChangeListener");
	}
	catch(err){

			player.style.backgroundColor="#000";//prevent flashy screen while JSAPI is initialized
			reloadPlayer();
		return;
	}
	initPauseClick();
};
// Function to pause the video first reproduction
// It is called by the player when its state changes
// Although the function is accesible from unwin,it's executed in the script context
unwin.gsStateChangeListener=function(stateId){
		unwin.playerState=stateId;
};

// Reloads the player by removing it from the DOM tree and inserting it again in the same position
// If the video is substituted by an icon,it won't do anything (a reload isn't necessary)
function reloadPlayer(){
	if(document.getElementById('movie_player')){
		var playerParent=player.parentNode;
		var playerNextSibling=player.nextSibling;
		playerParent.removeChild(player);
		playerParent.insertBefore(player,playerNextSibling);
	}
}

function initPauseClick()
{
		player.addEventListener('click',function(e)
		{
			if (e.layerY-player.offsetTop>=player.clientHeight-125) return;
					var state=uwPlayer.getPlayerState();
					if(state==1) uwPlayer.pauseVideo();
					else if(state==2||state==-1||state==0) uwPlayer.playVideo();
			},false);
};	

player.setAttribute('wmode','transparent');
setFlashVar("jsapicallback","gsPlayerReady");// Depends on the Main Reload
reloadPlayer();

It works, but not when I have this script enabled. Don't know why it works or why it doesn't work with this script, but I think it has something to do with the flashvars.
You think you or Avindra could implement this into this YouTube HD Ultimate script?

 
JoeSimmons Scriptwright
qufighter wrote:
if(state==1) uwPlayer.pauseVideo();
else if(state==2||state==-1||state==0)
JoeSimmons wrote:
if(state==1) mp.pauseVideo();
else if(state==2||state==-1||state==0) mp.playVideo();
Lol that guy took my code without credit. I got the code working, I just need to make it hover over the video now. It's only half over it now. I'll pm you when I get it.
Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel