/    Sign up×
Community /Pin to ProfileBookmark

Windows Media Embedded

Hi there! I have a embedded windows media player in my page that allows me to stream movies. I was trying to write a function that will display the movie duration at the bottom.

Heres some code to show how simple it is.

[CODE]<object classid=”clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6″ id=”WMP”>
<param name=”URL” value=”Lemonade.wmv”>
<param name=”animationatStart” value=”true”>
<param name=”transparentatStart” value=”true”>
<param name=”autoStart” value=”true”>
<param name=”showControls” value=”true”>
<embed type=”application/x-mplayer2″ name=”MediaPlayer1″
pluginspage=”http://www.microsoft.com/Windows/MediaPlayer/”

src=”Lemonade.wmv” autostart=”true” align=”middle” height=”285″

width=”320″>
</object>[/CODE]

i researched on the windows developer site and found a function called player.currentMedia.duration which should display the length of the wmv movie.

Can anyone give me a hint on how to have javascript grab this data and allow me to print it out in the html code?

Thank you!

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@konithomimoNov 02.2006 — Simply use player.currentMedia.duration to get the duration. The example referrences an object named "player". To make it work for yours simply do:

document.getElementById('WMP').currentMedia.duration

You can assign it to a variable or do whatever you want to do with it.
Copy linkTweet thisAlerts:
@shred444authorNov 03.2006 — Hey! Thanks for your reply.

so i added this after the object was displayed


[CODE]<SCRIPT LANGUAGE="JavaScript">
var length = document.getElementById('WMP').currentMedia.duration;
document.write(length);

</SCRIPT>[/CODE]


but each time, it ouputs 0. any ideas?
Copy linkTweet thisAlerts:
@konithomimoNov 03.2006 — The movie wont start until after the page is loaded. Therefore there is no currentMedia playing, so the duration is 0.
Copy linkTweet thisAlerts:
@konithomimoNov 04.2006 — Here is an example of how it should be:

&lt;html&gt;
&lt;head&gt;
&lt;script type="text/javascript"&gt;
function showDuration(){
var wmp = document.getElementById('WMP');
var dis = document.getElementById('dis');
var ps = wmp.playState;
var dur=wmp.currentMedia.durationString;
if(ps==9)
setTimeout("showDuration()",100);
else
{
dis.firstChild.data=dur;
return true;
}
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="showDuration()"&gt;
&lt;object classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" id="WMP"&gt;
&lt;param name="URL" value="Lemonade.wmv"&gt;
&lt;param name="animationatStart" value="true"&gt;
&lt;param name="transparentatStart" value="true"&gt;
&lt;param name="autoStart" value="true"&gt;
&lt;param name="showControls" value="true"&gt;
&lt;embed type="application/x-mplayer2" name="MediaPlayer1"
pluginspage="http://www.microsoft.com/Windows/MediaPlayer/"
src="Lemonade.wmv" autostart="true" align="middle" height="285" width="320"&gt;
&lt;/object&gt;
&lt;div id="dis"&gt;
Loading...
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
×

Success!

Help @shred444 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...