use jwplayer to get current play time - javascript

I am using jwplayer to play embedded video,
the javascript api tells me
jwplayer("mediaplayer").getPosition()
will get the current position, but my result is undefined
Can anyone help me get the correct resilts

Works fine for me just how the documentation specifies :
<div id="container"></div>
jwplayer("container").setup({
file: "http://content.bitsontherun.com/videos/nPripu9l-60830.mp4",
flashplayer: "http://player.longtailvideo.com/player.swf",
image: "http://content.bitsontherun.com/thumbs/nPripu9l-480.jpg",
height: 270,
width: 480
});
var state = jwplayer("container").getState();
var elapsed = jwplayer("container").getPosition();

How does your HTML and JavaScript look? Without seeing these, I can only assume the following.
According to the API documentation on the website this can be achieved without specifying a container, like so...
jwplayer().getPosition()

Related

I need help to add a swf in my site - swfobject

I need some help to implement swfobject.
I add this to my page:
<script src="https://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js" src_type="url" />
then I create a div with ID: flash-banner
<div id="flash-banner"></div>
and this is how I try to call the swfobject
<script>
var flash = document.getElementById("#flash-banner");
swfobject.embedSWF("pub/media/wysiwyg/welcome.swf", flash, 300, 120, 10);
</script>
I do something wrong? What is not good here?
Thank you
As mentioned, no one should be doing anything new with Flash these days - it's a dead end technology (I don't have it installed in any of my browsers, on any platform, for example). But the technical problem is that embedSWF wants the name of the ID as a string, but document.getElementByID returns the object, not its name. So, what you want is simply:
<script>
swfobject.embedSWF("pub/media/wysiwyg/welcome.swf", "flash-banner", "300", "120", "10");
</script>
swfobject should be avoided because it no longer works in Chrome.
More details in this answer: swfobject.embedSWF not working?

document.getElementById("").getElementsByTagName("img")[0].src = Not Working

I have these 3 lines of code in an external javascript file
function init(){
document.getElementById("upcoming_event").getElementsByTagName("img")[0].src = "images/fastnet_2013_poster.jpg";
document.getElementById("club_championship").getElementsByTagName("img")[0].src = "images/club_championship.png";
document.getElementById("setMembership").getElementsByTagName("img")[0].src = "images/join_our_club.png";
}
document.addEventListener( "DOMContentLoaded" , init , false);
This code works perfectly on this site which i used just to develop a little bit of it with 000webhosting.
But I have now moved my hosting to hosting24 to complete the development of the site. When i load the site through the new host(hosting24) the images are not getting loaded.
I have taken these 3 line of code out and tried them in an <body onload="init()"> but this dose not load the images either.
I know that both methods above are being called as i have got them to display a window.alert("Display").
Is there another way of doing this?
(document.getElementById("upcoming_event").getElementsByTagName("img")[0].src = "images/fastnet_2013_poster.jpg";) that i could try and use? Or solve my problem.
Changing servers should not effect javascript code at all. Only thing that comes to mind is that the URL's for the images sources isn't correct anymore, because of the move.
First you can use jQuery to help you do this in a simpler way like:
$('#upcoming_event').find('img')[0].src = "url";
or
$('#imgid').attr('src', 'xpto.jpg');
Secound, the code seems to work... I think the problem may be in the urls of the IMGs. Check if the images are in the correct folder or if the path is right.

jwplayer 6: how to dynamically load file, using javascript api?

I am trying to migrate from jw5 to jw6.
In jw5, I was able to dynamically load a video:
myplayer.load({file: 'myfile.mov', image: 'mysplash.jpg'});
This does not work in jw6. I have spent a lot of time looking through the online documentation, and have not found any references to .load. I am beginning to fear this is no longer supported. The document 'migrating from jw5 to jw6' has this cryptic comment:
The jwplayer().setup() call is now the only valid method to embed media
Does this mean it is no longer possible to dynamically load the player with a new file, for example in response to a click event, using the javascript api? Must all files be specified in a playlist, during the initial player setup?
Thank you.
I got this problem too and I found what is the issue.
Instead of JWP5, JWP6 does not work with the load() function if no media is specified upon setup.
If I used this code:
jwplayer("container").setup({
width: 640,
height: 480
});
after that, the load() function is not working.
The workaround is to specify initial some existing dummy media file:
jwplayer("container").setup({
width: 640,
height: 480,
file: '/some/summy/file.mp4'
});
after that JavaScript function load() can load new media.
This is the BUG !!!
You should still be able to use the load() call in JW6. http://www.longtailvideo.com/support/jw-player/28851/javascript-api-reference
load(playlist)
Loads a new playlist into the player. The playlist parameter is required and can be either an array with playlist items or a string that points to the location of an RSS feed.
If you are having issues getting load() to work in JW6, please provide an example for debugging, thanks.
This is an old post however i would like to give an example of what i would do (JWplayer6)
var playerInstance = undefined;
button.onclick = function(newData){
if (playerInstance === undefined){
playerInstance = jwplayer("myElement");
playerInstance.setup({
width: 640,
height: 480,
file: newData
});
} else {
playerInstance.load(newData);
}
};
Dummy content loads the player with data the user may not want, and the bonus of pre-loading the player on the page offers only a slight advantage to loading on a request. (waiting for the player js to execute)

Google SWFObject javascript detection when video stopped or get completed play

hiii all,
this is my very first post on stackoverflow, I always used to be a guy sitting back and see what happens here, never contributed, but now i finally got a chance..
MY question is I have a swf file, and I am playing it on my html page using SWFObject,now I want to implement a javascript method which triggers when videos gets completely played or get stopped..
here's my code
<html><head>
<title>PENSIONS BOOST</title>
<script type="text/javascript" src="https://aimhighermarketing.s3.amazonaws.com/videocontrollers/swfobject.js"></script>
</head><body>
<div id="player" align="center">
<script type="text/javascript">
var so = new SWFObject('https://aimhighermarketing.s3.amazonaws.com/videocontrollers/player.swf','mp1','640','480','10');
so.addParam('allowscriptaccess','always');
so.addParam('allowfullscreen','true');
so.addVariable('frontcolor','FFFFFF');
so.addVariable('lightcolor','FFFFFF');
so.addVariable('screencolor','FFFFFF');
so.addParam('flashvars','&file=HTTP://soci7361#socialnetworkbizbuilder.com/videos/pbsalesvideov2.mp4&&controlbar=none&autostart=true');
so.write('player');</script>
</div>
</body>
</html>
,any kind of help is very much appreciated..
Kindly help..
Thanks
Would love to help you out, but unfortunately you are missing very important information. SWFObject is just a tool to place the object tag safely on the user's browser. Remember those days you had to click on the OBJECT tag in order to activate it? Well, SWFObject fixes that... and much more.
What we need to know is which video player are you using? Flash is actually what fires the events to a javascript, which is what you'd be listening for.
The most popular of them is usually JWPlayer or Flowplayer.
If you can let us know which one it is, or what kind of flash player you are using, I'd be happy to do some quick research for you.
Never mind, I just visited your SWF File and found it is JW Player 4.
Here is the JS Code to listen for event changes:
var player;
function playerReady(object) {
player = document.getElementById(object.id);
player.addModelListener("state","playerStateChanged");
}
function playerStateChanged(obj) {
if (obj.newstate == 'COMPLETED') {
// Your video has finished playing
} else if (obj.oldstate == 'IDLE' AND obj.newstate == 'PLAYING') {
// Your video started to play. Now, this is not fully accurate. IDLE can also mean they pressed STOP and sat there.
}
}
In all reality, you should have a "startedVideo = false;" and on the first play change it to true. Then you'll be able to tell when it was first started playing..
Even though JWPlayer is up to version 5, they do still have a full JS API Doc online:
JWPlayer 4 JavaScript API

Flash in fullscreen mode works in <embed>, but not work within <a> tag

I have this code
<div id="c01" class="hider">
< a href="flash.swf" class="bump">flash</a>
</div>
and it displays flash content within a bumpbox (lightbox alternative) window. It works perfectly, but there is a fullscreen button in the flash animation and it do not works. The other button (to stop the animation) works ok.
I find out, that with this
<embed src="flash.swf" width="100%" height="100%" allowFullScreen="true"> </embed>
fullscreen button works fine, but the flash animation runs since the page is loaded and I have about 50 of those animations, so I need to run only one of them at a time. I need to make it clickable (within ) and with working fullscreen button at the same time. Is it possible? Thank you!
The issue you're having is actually coming from Mootools. Mootools has an Flash embed class called Swiff, which is what BumpBox uses when you pass an SWF in your link.
Unfortunately, I think you're either going to have to hack into BumpBox or Mootools to get full screen permission working.
If you look into the expanded version of BumpBox 2.0.1, you will see where Swiff is instantiated, around line 372:
var obj = new Swiff(content, {
id: 'video',
width: maxw-40,
height: maxh-40,
container: div
})
You may be able to pass in the additional parameter you require here, which would look something like this:
var obj = new Swiff(content, {
id: 'video',
width: maxw-40,
height: maxh-40,
container: div,
params: {
allowFullScreen: true
},
})
If that fails you will have to make the adjustment to the Swiff class itself. Open up Mootools and search for Swiff=new Class. That will lead you to the code that creates the Flash object. Finding the params list should be easy from there, it looks like:
params:{quality:"high",allowScriptAccess:"always",wMode:"window",swLiveConnect:true}
and you would just need to add the fullscreen permission:
params:{allowFullScreen:true,quality:"high",allowScriptAccess:"always",wMode:"window",swLiveConnect:true}
Some browsers can't open a Flash file without Flash container (embed).
The embed code in your post is fine, put it on a PHP page and replace:
src="flash.swf"
with
<?php echo $_GET['flashurl']; ?>
Then you can put as link: nameofphpscript.php?flashurl=flash.swf

Categories

Resources