Order Now AdSolution Sign Up | Login » Bits on the Run Sign Up | Login »

Forums

/

Sending Stop Call with JS not working

6 replies [Last post]

Hoping someone can help, I ...Hoping someone can help, I know this is so easy, I'm just messing up the syntax somehow. I've tried a few things but can't seem to get it working.

Basically I have three videos on my page controlled by a jquery like "tabs" interface. Think 3 videos, 3 thumbnails. Only 1 video is showing at a time. When you click a thumbnail jquery hides the active div(video) and then shows the second.

In browsers like Firefox there is no problem. But in IE, the audio from the first video continues playing when I click a second video. So I need to someone say when I click a thumbnail and show a new video, stop all videos/stop the video playing etc..

Here is the base javascript:

$(function () {
var tabContainers = $('div.tabs > div');
tabContainers.hide().filter(':first').show();

$('ul.tabNavigation a').click(function () {                               
tabContainers.hide();
tabContainers.filter(this.hash).show();

$('ul.tabNavigation a').removeClass('selected');
$(this).addClass('selected');
return false;
}).filter(':first').click();
});

And here is my the Javascript where I've tried integrating the stop command:

$(function () {
var tabContainers = $('div.tabs > div');
tabContainers.hide().filter(':first').show();

$('ul.tabNavigation a').click(function () {                               
tabContainers.hide();
tabContainers.filter(this.hash).show();
player = document.getElementById(obj['id']);
                             player.sendEvent('STOP');
$('ul.tabNavigation a').removeClass('selected');
$(this).addClass('selected');
return false;
}).filter(':first').click();
});

Any help appreciated.

Hi, I think that as you have several reference like this:

player=document.getElementById("idplayer");

Luckily, that will help this.

Alicia, thanks for the tip. The problem is, each player has it's own unique id. I'm assuming your code assumes all players have an id of idplayer?

Will it break anything if I set them to all the same ID?

Quick & Dirty — just call all three players by id, with a STOP Event.

Much more involved, keep track of or find out who is playing and stop him cold!

lost-

Your method does accomplish stopping all players, however now javascript errors will be thrown by any browser because the currently hidden (style="dislplay:none;") divs (tabs) are well... hidden, as in not really "present" in the DOM.

I'm struggling with this issue as well Todd.

@mandle - Easy: put the stop in a try / catch block.

harder: check to see which div has display:visible (or whatever)

best: Add an event listener for time events (or player state events) and have it update a variable that keeps track of the currently playing player. When you're looking to stop it, tell that player to stop.

This took me a bit, but might help out some other folks. I dug around for 2 days without finding too much help.

My project is like a portfolio. With multiple jobs that show/hide from a main nav, and using a slider to show multiple videos per job.

Here's my solution.

js on HTML page.

<script type="text/javascript">
var players = [];
var movieOpen = []; // will use that in jquery

function playerReady(obj) {
players.push(document.getElementById(obj.id));
};

function stopAllPlayers(){
for (var player in players){
   players[player].sendEvent("STOP");
}

}
/* above works fine if you don't hide some of your jobs containing videos. */
</script>

and some jQuery where I trigger the function.

$('.jqGSPagination ul li a').click(function() {

movieOpen = $('embed[id^="mpl"]:visible').toArray(); // get movies available in array all mine start with 'mpl'

players = movieOpen; // replace array in var for function

stopAllPlayers();
});

The movies in the slideshow are still 'visible' just outside of the clipping area. So you can get what movies are ready in a array and push that to players.

no js errors since it's only targeting movies that are available.

hope it helps some.

cheers.
gary.