PDA

View Full Version : Do I need a stop function?



billyboy
12-11-2005, 02:37 AM
I found a code that can be used to choose between sources for Media Player by clicking on links on the webpage. I stripped it down to the minimum needed to play streaming audio. However, no way of turning it off was included so I just wrote a fake url called stop.asx and it seems to work. I'm just not sure exactly what is going on with Media Player, if it's a waste of resources trying to get it to call up a non-exsistent url. If a stop function would be better, how would I add that?
Thanks, Bill

<script type="text/javascript">
function play(media)
{
document.getElementById('mediaplayer').innerHTML='<object classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95"'
+'type="application/x-oleobject" width="0" height="0"><param name="fileName" value="'+media+'">'
+'<embed type="application/x-mplayer2" src="'+media+'" width="0" height="0"><\/embed><\/object>'
}
</script>

in the html...

<ul>
<li><a onclick="play(this.href);return false" href="http://www.r2.co.nz/meta/coolblue-128.asx">Jazz</a></li>
<li><a onclick="play(this.href);return false" href="http://www.novaclassicrock.nl/nova_classic_rock_player.asx">Classic Rock</a></li>
...etc.
<li><a onclick="play(this.href);return false" href="stop.asx">Stop</a></li>
</ul>

jscheuer1
12-11-2005, 04:57 AM
It does seem wasteful but, it may not be. You could just do like:


<script type="text/javascript">
function play(media)
{
if (media=='stop.jpg')
document.getElementById('mediaplayer').innerHTML='<img src="stop.jpg">'
else
document.getElementById('mediaplayer').innerHTML='<object classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95"'
+'type="application/x-oleobject" width="0" height="0"><param name="fileName" value="'+media+'">'
+'<embed type="application/x-mplayer2" src="'+media+'" width="0" height="0"><\/embed><\/object>'
}
</script>

in the html...

<ul>
<li><a onclick="play(this.href);return false" href="http://www.r2.co.nz/meta/coolblue-128.asx">Jazz</a></li>
<li><a onclick="play(this.href);return false" href="http://www.novaclassicrock.nl/nova_classic_rock_player.asx">Classic Rock</a></li>
...etc.
<li><a onclick="play(this.href);return false" href="stop.jpg">Stop</a></li>
</ul>

Also, there probably is a parameter for stoped or a play=false or something like that and a corresponding attribute for the embed tag (Google would be a good resource for finding those). If so, you could query the element for its current embed tag's src before writing to it with the same src, but in stop mode.

Note: This whole scheme would be better using links to the players on separate pages to be shown through an iframe. That way non-javascript enabled browsers would have a very good shot at getting the content in its intended presentational form. As it is now, one just has to hope that clicking on a link to an asx file will launch the non-javascript enabled client's own player.

billyboy
12-11-2005, 12:31 PM
Hi John,
Thanks for the help, that does the trick. I don't even need <img src="stop.jpg"> since media player is hidden, it's just for listening to music. Writing a blank div seems the most efficient way to deal with it. I have found bits of code that are supposed to control the stop function but I keep getting errors when I try to put them in. You do know iframe has been depreciated? And if I went that route, I'd have to write 8 different pages with media player on each one. I agree, relying on javascript is not the best option, but it's not a critical function on the page.
Thanks again,
Bill

jscheuer1
12-11-2005, 05:31 PM
That's good. I was not aware of iframe being deprecated though. I really don't keep a close track of such things but, I do pay attention when information like that crosses my radar. From what I recall, it is only in the most strict situations and possibly only in XHTML where that is the case. Standards are all well and good but, I can assure you that iframes are here to stay for quite some time. Also, innerHTML is deprecated in XHTML, possibly strict HTML as well.

mwinter
12-11-2005, 10:57 PM
I was not aware of iframe being deprecated though.Perhaps because it isn't? ;) Though many elements and attributes missing from the Strict DTD are deprecated or obsolete, not all are. The Strict DTDs have never contained anything frame-related.


Also, innerHTML is deprecated in XHTML, possibly strict HTML as well.The innerHTML property is a feature of a proprietary DOM, so it has deprecated status within any markup specification because it's out the scope of those documents. However, the property will not be defined in a true XHTML document because it will have a HTML parser applied to it.

Mike

billyboy
12-12-2005, 06:20 AM
The few pages I've written have all used strict DOCTYPES, and I got errors when I used iframe hence why I figured it was depreciated. What would be the alternative to using innerHTML according to W3C DOM?

jscheuer1
12-12-2005, 07:48 AM
Don't quote me on this, oh go ahead -

I believe it would be:

1) The use of the DOM to create, append and remove document elements.

or

2) To access the tags' involved properties and/or attributes and set them.

Doing either #1 or #2 with an embed tag would be fairly straightforward. I'm not sure how the complex syntax of the object tag, with its use of parameters that look like tags in heir own right, yet are contained within the object tag, would respond. There probably is a way though. I'd try (method #2, it's easier):


onclick="document.getElementsByTagName('param')[0].value=document.getElementsByTagName('embed')[0].src=this.href;return false;"

This assumes that the param tag and the embed tag you are trying to influence are each the 1st of their type on the page.