|
|
|
date: Thu, 7 Aug 2008 05:24:00 -0700,
group: microsoft.public.windowsmedia.sdk
back
Windows Media Player - Javascript Control in Browser is unpredicta
Hi,
I've been attempting to manipulate the Player.controls etc in order to use
the WMP within IE and FF without the normal control panel as I need to
control the videos via javascript. This has proved to be enormously
unpredictable (after repeated attempts over several months).
Essentially attempting to do things like Player.controls.isAvailable only
appears to work under certain circumstances. E.g. I test to see if
currentPosition is available. The code says it isn't but setting the
currentPosition then works as expected.
I've recently abandoned all use of isAvailable as a result. Additionally,
many of the controls only work after a delay. See code below (new to this
forum so not sure if code tags work).
In my HTML file
[CODE]
if (-1 != navigator.userAgent.indexOf("MSIE"))
{
document.write('<object id="Player"');
document.write(' classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6"');
document.write(' type="application/x-oleobject"');
document.write(' <param name="autostart" value="0" />');
document.write(' width=320 height=240></object>');
}
else if(-1 != navigator.userAgent.indexOf("Firefox"))
{
document.write('<object id="Player"');
document.write(' type="application/x-ms-wmp"');
document.write(' width=320 height=240>');
document.write(' <param name="windowlessVideo" value="1" />');
document.write(' <param name="autostart" value="0" /> </object>');
}
[/CODE]
and in the javascript - global vars moviesID, moviesDOM, theImage etc
[CODE]
function initMovie (showMe) {
// start video to expose functions then delay before progressing
moviesID = document.getElementById("Player");
if (browser == "IE") {
moviesDOM.style.bottom = "70px"; // simple solution to IE hiding icons
// http://msdn.microsoft.com/en-us/library/bb249373(VS.85).aspx Only
set at design time and upsets Vista!!!
moviesID.windowlessVideo = true; // doing this here instead of object
appears to help IE but break FF
moviesID.stretchToFit = true; // make it fit window
}
moviesID.uiMode = "none"; // this worked as FF param but not IE param -
vital for IE here
//moviesID.settings.volume = 0;
theImage =
"mms://wm.microsoft.com/ms/msnse/0410/23725/PhotoStory/Photostory_demonstration_MBR.wmv";
// Nice short video but not sure if either of these have indexing...
// theImage="http://www.ananova.com/about/vap_windows_check.wmv";
moviesID.URL = theImage;
moviesID.controls.play(); // in FF the first time around the play
doesn't work unless the entire path is provided
// wait an interval to allow video to start then proceed in next function
setTimeout ("getDuration()", 500); // Need a pause or
currentMedia.duration won't be available.
}
function getDuration () {
// duration can only be detected after a delay?
duration = moviesID.currentMedia.duration;
moviesID.controls.currentPosition = Math.floor(duration / 2); // cP
needs to come just before play
setTimeout ("videoPositioned ()", 15); // need to allow time for play to
start
// FF needs just a 1 millisecond delay (plus function call losses).
// IE needs around 15 milliseconds
}
function videoPositioned () {
moviesDOM.style.left = "10px"; // video was tucked away out of sight -
need to do this here or FF gets upset (was style.left = "-500px"; perhaps an
issue?
// now play - and pause to allow play to settle then position and pause
moviesID.controls.play();
setTimeout ("videoReady()", 500); // need to allow time for play to start
// 5:40pm 5th August Video starts and pauses at midpoint in both IE and FF.
// longer pause here helped (was 15 now 500). Perhaps this can be lowered
but problem intermittent so hard to test
}
function videoReady () {
// now pause - the movie is ready to play with...
moviesID.controls.pause ();
}
[/CODE]
Without these pauses the Player is totally unpredictable. I've tried a
number of videos from WMV v7 through to v9. All the same.
Also, I'm having trouble setting the rate to -1 to play the video in reverse.
moviesID.controls.currentPosition = 10; // move a few seconds into the file
moviesID.settings.rate = -1.0;
moviesID.controls.play();
Setting rate to 2 etc works fine but the reverse play results in a long
delay (I suspect the entire video has to be read in - I use short videos to
test). Then just 0 to 3 frames are shown and appear more or less at the
expected time (about 1 frame every 5 seconds or so). Note, I have tried lots
of delays as above - removed here for brevity. I have tried to ensure that
the files are Indexed (used Media Editor). Perhaps the Index hasn't worked.
WinXP, WMP v11, IE7, FF2.
In summary. I've spent countless hours trying to control the Player via
javascript. I've tried hundreds (no exaggeration) of combinations of
commands/params/uppercase/lowercase/false(0)/true(1) etc
WMP in a browser - does it work?
Hopefully someone can sort out this madness.
Cheers
srsm
date: Thu, 7 Aug 2008 05:24:00 -0700
author: srsm
Re: Windows Media Player - Javascript Control in Browser is unpred
From: "srsm"
> Perhaps the fact that this question has "been discussed
> over and over" may not in fact be due to the failings of
> stupid/lazy people trying to learn a new skill but may in
> fact be due to poor documentation. And I did search in
[...]
As far as I am concerned, WMP's docs can only be
successfully used in a restroom once printed out on soft
paper.
> setTimeout. It is interesting to note that this key
> requirement to successfully controlling the WMP is as you
> admit yourself "tips missing from the docs". I didn't
The key information in
http://msdn.microsoft.com/en-us/library/bb262763(VS.85).aspx
is <<<All of the methods in the Windows Media Player object
model are asynchronous.>>>. While that hint tells everything
there is to know to system programmers that have experience
with asynchronous multitasking, it is absurd for the docs to
assume that most web programmers will understand its
implications. More so since none of the samples show how to
asynchronously interact with WMP.
And the most important implication is that, when you call a
method on WMP, the method only requests that the action be
taken, but it does not imply that the request has completed
when the method returns, so you must wait for the completion
by listening for the appropriate event (which is never
specified in the docs, so you must figure it out by trial
and error).
The other 2 implications are the tips I gave you already:
- since the clip metadata in read from the clip, you must
wait for the clip to be loaded to retrieve them
- it is always a gamble to cause another event to fire
inside an event handler; when you need to do that, you
terminate the handler and post a request to another thread,
which in a browser means calling setTimeout() in the handler
to execute the actual code after the handler terminates
[...]
> couple of years. Perhaps you have had a long day. Anyhow.
It is frustrating on this side of the board when you end up
always repeating the same things.
> Assuming you are a moderator or similar may I suggest
[...]
I am no such thing and I have no influence whatsoever over
Microsoft choices:
http://mvp.support.microsoft.com/
[...]
> tasks and appear to give up and move over to using Flash
> Video (I presume as that is what I was advised to do
Flash is much easier to use, so the fact that the control's
docs are way worse than WMP's is not as important. On the
hand, WMP has more features and some quality advantages.
> And so if the Flame war hasn't totally broken out is
> there any chance you could put together a little example
> of using rate = -1 with setTimeout or similar to get
> around the various issues. Perhaps this could be the
> basis for an example in the documentation.
Despite what you see on TV, reverse playback of
temporally-compressed video files is not trivial and does
not work in the general case. I think WMP can only play
stridable WMVs in reverse, which requires the WMVs to be at
least indexed. Indexing does not guarantee the reverse
playback will work.
--
// Alessandro Angeli
// MVP :: DirectShow / MediaFoundation
// mvpnews at riseoftheants dot com
// http://www.riseoftheants.com/mmx/faq.htm
date: Thu, 7 Aug 2008 20:08:26 -0400
author: Alessandro Angeli
|
|