| Author |
Message |
Marc
Guest
|
Posted:
Tue Feb 22, 2005 9:05 pm Post subject:
OnClick over MediaPlayer objects |
|
|
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
|
|
| Back to top |
|
 |
Neil Smith [MVP Digital M
Guest
|
Posted:
Tue Feb 22, 2005 9:43 pm Post subject:
Re: OnClick over MediaPlayer objects |
|
|
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:
| Quote: | 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 |
|
|
| Back to top |
|
 |
Marc
Guest
|
Posted:
Tue Feb 22, 2005 9:55 pm Post subject:
Re: OnClick over MediaPlayer objects |
|
|
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:
| Quote: | 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
|
|
|
| Back to top |
|
 |
Neil Smith [MVP Digital M
Guest
|
Posted:
Tue Feb 22, 2005 11:33 pm Post subject:
Re: OnClick over MediaPlayer objects |
|
|
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:
| Quote: | 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
|
|
|
| Back to top |
|
 |
Marc
Guest
|
Posted:
Wed Feb 23, 2005 2:19 pm Post subject:
Re: OnClick over MediaPlayer objects |
|
|
It works very well and it's pretty nice.
Thanks,
Marc
"Neil Smith [MVP Digital Media]" wrote:
| Quote: | 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
|
|
|
| Back to top |
|
 |
Neil Smith [MVP Digital M
Guest
|
Posted:
Wed Feb 23, 2005 3:32 pm Post subject:
Re: OnClick over MediaPlayer objects |
|
|
OK so we got so far ;-) There's some further reading.
The information you need about why IE doesn't pass an object is buried
at the bottom of this page where it discusses IE and says "The event
handling function is referenced, not copied" :
http://www.quirksmode.org/js/events_advanced.html
There are some cross-browser examples which allow you to run the event
handling code below on the W3C DOM2 event model too. attachEvent isn't
a standard (much in IE is only a de-facto standard ;-p), and won't
even work on IE5/Mac.
So you need to be able to use the addEventListener too.
You can rework that code a little using the examples here :
http://www.scottandrew.com/weblog/articles/cbs-events
http://phrogz.net/JS/AttachEvent_js.txt
http://developer.apple.com/internet/webcontent/eventmodels.html
Cheers - Neil
On Wed, 23 Feb 2005 01:19:03 -0800, "Marc"
<Marc@discussions.microsoft.com> wrote:
| Quote: | 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
|
|
|
| Back to top |
|
 |
Marc
Guest
|
Posted:
Wed Feb 23, 2005 4:47 pm Post subject:
Re: OnClick over MediaPlayer objects |
|
|
Thanks for the examples/links and, even though it just needed to work under
IE6 (because the page it's inside a Windows Control), it's very interesting
to notice these differences between the W3C and microsoft.
One thing to mark is that Microsoft model doesn't suport the cancelling of
the bubble mode (the 3rd parameter of the addEventListener). It mustn't
affect necessarily (see thread "avoid full screen mode") but, as I have each
embeded object inside a different DIV to permit the movility of each one
separately, maybe it could be a reason of failure/malfunction... could be?
Thanks,
Marc.
"Neil Smith [MVP Digital Media]" wrote:
| Quote: | OK so we got so far ;-) There's some further reading.
The information you need about why IE doesn't pass an object is buried
at the bottom of this page where it discusses IE and says "The event
handling function is referenced, not copied" :
http://www.quirksmode.org/js/events_advanced.html
There are some cross-browser examples which allow you to run the event
handling code below on the W3C DOM2 event model too. attachEvent isn't
a standard (much in IE is only a de-facto standard ;-p), and won't
even work on IE5/Mac.
So you need to be able to use the addEventListener too.
You can rework that code a little using the examples here :
http://www.scottandrew.com/weblog/articles/cbs-events
http://phrogz.net/JS/AttachEvent_js.txt
http://developer.apple.com/internet/webcontent/eventmodels.html
Cheers - Neil
On Wed, 23 Feb 2005 01:19:03 -0800, "Marc"
Marc@discussions.microsoft.com> wrote:
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
|
|
|
| Back to top |
|
 |
whpodj
Joined: 25 Feb 2005
Posts: 4
|
Posted:
Fri Feb 25, 2005 10:38 pm Post subject:
Re: OnClick over MediaPlayer objects - javascript wmp plug n |
|
|
Hi,
I have a similar problem. I am trying to NOT use the Object and just use the embed (plug in). In IE this works, it responds to javascript to stop and start (so I assume that it still exposes props and mthds).
In Mozilla, the player is displayed and autostarts but won't handle the javascript... as though I am not referencing the player correctly. But it is giving me confusing errors. I scripted all 3 buttons differently to debug...
Errors returned to the Mozilla, JavaScript console when a custom button is pressed:
Play - Warning: Element referenced by ID/NAME in the global SCOPE. Use W3C standard document.getElementByID() instead Line 21
- Error: document.getElementByID is not a function Line 21
Pause - Error: document.WMPlay.pause is not a function Line 22
Stop - Warning: Element referenced by ID/NAME in the global SCOPE. Use W3C
standard document.getElementByID() instead Line 29
- Error: document.WMPlay.stop is not a function Line 29
// script code
var bWin32IE;
if ((navigator.userAgent.indexOf("IE")
> -1) && (navigator.platform == "Win32")) {
bWin32IE = true;
} else {
bWin32IE = false;
}
function playit(){
if (bWin32IE == true) {
document.WMPlay.play();
} else {
document.getElementByID(WMPlay).play();
}
}
function pauseit(){
document.WMPlay.pause();
}
function stopit(){
if (bWin32IE == true) {
document.WMPlay.stop();
} else {
WMPlay.stop();
}
} |
|
| Back to top |
|
 |
Neil Smith [MVP Digital M
Guest
|
Posted:
Fri Mar 11, 2005 4:08 pm Post subject:
Re: OnClick over MediaPlayer objects - javascript wmp plug n |
|
|
First thing to check, document.getElementByID is case sensitive, so it
should be written document.getElementById : It's a real gotcha and had
me a few times ;-))
Next thing is to try the documentation here about embedding WMP in
Netscape, it needs to use the Netscape java listener class or the
Gecko ActiveX control :
http://www.streamingmedia.com/article.asp?id=8584&page=2&c=4
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmplay10/mmp_sdk/usingwindowsmediaplayerwithnetscapenavigator.asp
Also I just found this fascinating dissection of 'how-to' install for
ActiveX in Mozilla.Firefox, which until now has been a real headache
because Firefox loads the WMP6.4 player even if WMP10 is installed
(and scripting fails) so have a look over these :
http://forums.mozillazine.org/viewtopic.php?t=206213
http://forums.mozillazine.org/viewtopic.php?t=206216
Cheers - Neil
On Fri, 11 Mar 2005 03:01:22 -0600,
wb04@moksha-dot-net.no-spam.invalid (whpodj) wrote:
| Quote: | Hi,
I have a similar problem. I am trying to NOT use the Object and just
use the embed (plug in). In IE this works, it responds to javascript
to stop and start (so I assume that it still exposes props and
mthds).
In Mozilla, the player is displayed and autostarts but won't handle
the javascript... as though I am not referencing the player
correctly. But it is giving me confusing errors. I scripted all 3
buttons differently to debug...
Errors returned to the Mozilla, JavaScript console when a custom
button is pressed:
Play - Warning: Element referenced by ID/NAME in the global SCOPE. Use
W3C standard document.getElementByID() instead Line 21
- Error: document.getElementByID is not a function Line 21
Pause - Error: document.WMPlay.pause is not a function Line 22
Stop - Warning: Element referenced by ID/NAME in the global SCOPE.
Use W3C
standard document.getElementByID() instead Line 29
- Error: document.WMPlay.stop is not a function Line 29
// script code
var bWin32IE;
if ((navigator.userAgent.indexOf("IE")
-1) && (navigator.platform == "Win32")) {
bWin32IE = true;
} else {
bWin32IE = false;
}
function playit(){
if (bWin32IE == true) {
document.WMPlay.play();
} else {
document.getElementByID(WMPlay).play();
}
}
function pauseit(){
document.WMPlay.pause();
}
function stopit(){
if (bWin32IE == true) {
document.WMPlay.stop();
} else {
WMPlay.stop();
}
} |
|
|
| Back to top |
|
 |
|
|
|
|