Re: OnClick over MediaPlayer objects

From: Marc (Marc_at_discussions.microsoft.com)
Date: 02/23/05


Date: Wed, 23 Feb 2005 01:19:03 -0800

It works very well and it's pretty nice.

Thanks,
    Marc

"Neil Smith [MVP Digital Media]" wrote:

> OK sure well as long as you've now named them differently... provide a
> javascript array with the ID names and iterate it as follows : let's
> say you have 2 player objects, with HTML IDs wmp1 and wmp2 :
>
> Provide a script block (in the head or in an external js file)
>
> function initPlayerEvents() {
> var playerIDs=new Array("wmp1","wmp2");
> for (i=0; i<playerIDs.length; i++) {
> setupPlayerEvents(playerIDs[i]);
> }
> }
> function setupPlayerEvents(playerid) {
> var WMP9=document.getElementById(playerid);
> // Make sure the next line appears as a single line in your editor !
> WMP9.attachEvent('MouseDown', function()
> {showClickState(playerid)} );
> }
> function showClickState(playerid) {
> eventSrc=document.getElementById(playerid);
> if((eventSrc.playState == 1) || (eventSrc.playState == 2) ||
> (eventSrc.playState == 10)) {
> eventSrc.controls.play();
> } else if(eventSrc.playState == 3) {
> eventSrc.controls.pause();
> }
> }
>
> And add <body onload="initPlayerEvents()">
>
> That should get you working.
> Cheers - Neil
>
> On Tue, 22 Feb 2005 08:55:13 -0800, "Marc"
> <Marc@discussions.microsoft.com> wrote:
>
> >Yes, I know that, but is there a way to write it without the need to copy &
> >paste
> >the script for each ID?
> >I mean,
> >
> ><SCRIPT FOR="Player1" EVENT="Click( iButton, iShiftState, fX, fY )" >
> > if((Player1.playState == 1) || (Player.playState1 == 2))
> > Player1.controls.play();
> > else if(Player1.playState == 3)
> > Player1.controls.pause();
> ></SCRIPT>
> ><SCRIPT FOR="Player2" EVENT="Click( iButton, iShiftState, fX, fY )" >
> >...
> >the same for Player2
> ></SCRIPT>
> >
> >Thanks,
> > Marc
> >
> >"Neil Smith [MVP Digital Media]" wrote:
> >
> >> Two objects in a web page *cannot* have the same ID, that would be
> >> invalid HTML. You must give them different ID's in order to script
> >> them. Same applies to forms, images and so on, it's not a windows
> >> media exclusive problem ;-)) Give them different IDs.
> >>
> >> Cheers - Neil
> >>
> >> On Tue, 22 Feb 2005 08:05:02 -0800, "Marc"
> >> <Marc@discussions.microsoft.com> wrote:
> >>
> >> >Hi all,
> >> > I have a page with 2 MediaPlayer embeded objects without buttons to
> >> >control them(uiMode="none"). To play/pause and stop them, the user has to
> >> >click over the display so I have inserted the following code:
> >> >
> >> ><SCRIPT FOR="Player" EVENT="Click( iButton, iShiftState, fX, fY )" >
> >> > if((Player.playState == 1) || (Player.playState == 2))
> >> > Player.controls.play();
> >> > else if(Player.playState == 3)
> >> > Player.controls.pause();
> >> ></SCRIPT>
> >> >
> >> >this code works well when there's only one embeded MediaPlayer. If I embed 2
> >> >objects it fails because both of them have the same ID("Player").
> >> >I have mantained the same ID because I thought that when the event is fired,
> >> >the whole object is passed to the script so, in this scope, it's unique, but
> >> >it seems that it's wrong.
> >> >Is there any way to make it works or the only way is putting different IDs
> >> >for each MediaPlayer and copy the script for each ID as many times as objects
> >> >are in the page?
> >> >
> >> >thanks,
> >> > Marc
> >>
> >>
>
>