*********
Please note that responses to this post should be posted to the RealForum Bulletin 
Board.  Email responses will be forwarded to the bulletin board, but will not be 
mailed to the RealForum mailing list.  The RealForum Bulletin Board can be found at:

http://realforum.real.com/cgi-bin/realforum/wwwthreads.pl
*********

From: "Porter Woodward" <[EMAIL PROTECTED]>
Subject: Solution for SetPosition Woes!

Hey -

I found a solution for the SetPosition woes that people seem to be having.
For the most part it centers around the fact that the RealPlayer ignores the
SetPosition message if it's not playing a clip.  If you use a
while(rm.GetPlayState() != 3) to wait until playing starts, that pretty much
seems to hang the browser/player.

I suspect this is the case for the following reasons:

1> methods like SetSource(), DoPlay() are "non-blocking" in that they return
ASAP, and don't return any status.

2> methods like GetPlayState() are blocking calls - causing the component to
stop and respond to the call.

So - if you use the following code:

     rm.SetSource(myURL);
     rm.DoPlay();
     rm.SetPosition(myOffset);

You likely won't be fast forwarded to the appropriate position in the clip.
This is because when the call to SetPosition() is made, the component hasn't
even started to contact the host, and isn't anywhere near finished buffering
it - let alone started to play it.  To solve it you might use the following:

     rm.SetSource(myURL);
     rm.DoPlay();
     for(i=1; i<1000000; i++) {}
     rm.SetPosition(myOffset);

This won't work well because depending on the speed of the end users
connection, the clip may still be queuing up, or even worse, have already
started to play from the beginning, and then magically jump to the right
point...

You might also try:

     rm.SetSource(myURL);
     rm.DoPlay();
     while(rm.GetPlayState != 3) {}
     rm.SetPosition(myOffset);

Which will hang your browser.  The component gets so bogged down responding
to the "whatcha doin?" calls to it that it never has time to actually load
the clip and buffer and play it...  Thus an endless loop.

Here's the solution I used - and it works pretty good.  No thanks to
RealNetworks - whose API documentation is 2 years out of date (embedded
player guide last updated in 1998) and contains no useful examples!  Sure -
if you know you're on IE - you could use VBS, or if you're on NS - you could
use a Java based callback.  But - why should you have to if both browsers
support JavaScript?  I really didn't want to introduce too much "if this
browser, then render using this code" type of processing.

var offset=null;
var timerID=null;

function playClip(myOffset,myAsset) {
     // set the global to milisecond length.
     offset = myOffset * 1000;

     // get a handle to the Player object
     var d=top.media.document;

     // signal the player object to load and play a clip.
     if (d.rmObj.CanPlay()) {
         d.rmObj.SetSource(myAsset);
         d.rmObj.DoPlay();
         //  keep trying to fastforward the tape...
         timerID = setInterval("fastforward()",1000);
     }
}

function fastforward() {
     // Grab the handle to the player object.
     var d=top.media.document;

     // Jump ahead into streamable asset...
     if (offset  > 0) {
         d.rmObj.SetPosition(Math.round(offset));
     } else {
         d.rmObj.SetPosition(0);
     }

     if(d.rmObj.GetPlayState() == 5){
         clearInterval(timerID);
         timerID = null;
         offset = null;
     }
     return true;
}

Essentially this sets up a timer that calls the fastforward function every
second until it sees the status of "seeking" which is what will occur when
the message to SetPosition() is recieved by the component.

YMMV,
Porter Woodward

********
You may reply to this post at:
http://realforum.real.com/cgi-bin/realforum/dosearch.pl?Cat=&Forum=All_Forum 
s&Match=Entire%20Phrase&Limit=25&Old=allposts&Words=Solution%20for%20SetPosi 
tion%20Woes

*******************************************************
The RealForum is an email discussion group focused on using RealNetworks
products. The RealForum is a place to post messages about the best methods
for creating content using RealNetworks technologies and the planning and
implementation of streaming-media web sites.  Archives of RealForum can
be found at http://realforum.real.com

If you ever want to remove yourself from this mailing list,
you can send mail to <[EMAIL PROTECTED]> with the following
command in the body of your email message:

    unsubscribe realforum

or from another account, besides the address you subscribed with:

    unsubscribe realforum <[EMAIL PROTECTED]>

Reply via email to