469,357 Members | 1,565 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,357 developers. It's quick & easy.

asx playlist loaded dynamically, but links won't work.

matheussousuke
249 100+
I currently found a script that dynamically loads an ASX playlist, allowing the user to choose the item that he wants to watch in Windows media player embedded.
The trouble is that once the user click on the link in the playlist it wont work.
Take a look here http://tv.mghospedagem.com/wmp-pl3.html

Works only on IE.


Expand|Select|Wrap|Line Numbers
  1. <head>
  2. <script language="javascript1.2">
  3.  
  4. playListLoaded=false;
  5.  
  6.  
  7. function loadPlayItems() {
  8.         df=document.getElementById("playItem");
  9.         dp=document.getElementById("playlist");
  10.         WMP9=document.getElementById("MediaPlayer1");
  11.  
  12. WMP9.url="http://tv.mghospedagem.com/play.asx";
  13.         WMP9.controls.play();
  14.  
  15. }
  16.  
  17. function showPlayItems() {
  18.         WMP9=document.getElementById("MediaPlayer1");
  19.         playlistItems=WMP9.currentPlaylist.count;
  20.         for (i=0; i<playlistItems; i++) {
  21.                 playitem=document.createElement("a");
  22.                 playnext=document.createElement("br");
  23.                 playitem.setAttribute("href","#");
  24.                 playitem.setAttribute("onclick","playItem("+i+")");
  25.                 playitem.innerText=WMP9.currentPlaylist.item(i).name;
  26.                 dp.appendChild(playitem);
  27.                 dp.appendChild(playnext);
  28.         }
  29.         playListLoaded=true;
  30.         WMP9.controls.play();
  31.  
  32. }
  33.  
  34.  
  35.  
  36. function setPlayItem(index) {
  37.         WMP9=document.getElementById("MediaPlayer1");
  38.         playlistItems=WMP9.currentPlaylist.count;
  39.         if (playlistItems > 0) {
  40.  
  41. WMP9.controls.currentItem=WMP9.currentPlaylist.item(index);
  42.                 WMP9.controls.play();
  43.         }
  44. }
  45.  
  46. </script></head>
  47.  
  48. <body onLoad="loadPlayItems()">
  49. <object id="MediaPlayer1"
  50. classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6"
  51. type="application/x-oleobject" width="600" height="400">
  52. <param name="autostart" value="1">
  53.         <param name="showcontrols" value="1">
  54.         <param name="uimode" value="full">
  55.         <param name="stretchtofit" value="1">
  56.         <param name="enablecontextmenu" value="0">
  57. </object>
  58.  
  59. <div id="playlist" style="position: absolute; top: 10px; left:
  60. 640px; visibility: visible; z-index: 999999999999999;">
  61. <h2>Playlist</h2></div>
  62.  
  63. <script language="javascript1.2" for="MediaPlayer1"
  64. event="playStateChange">
  65. WMP9=document.getElementById("MediaPlayer1");
  66. if (WMP9.playState==3 && ! playListLoaded) {
  67.         showPlayItems();
  68. }
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75. </script>
  76.  
  77.  
Feb 12 '11 #1
22 2579
matheussousuke
249 100+
That's the first time that anyone help me here. That script problem must be a really hard issue to solve.
Feb 13 '11 #2
matheussousuke
249 100+
So, how can I use this information to help on my issue?

The following text is from another source:



Hi Chopz,

That's an interesting hack, but it relies on browser sniffing, which is best avoided if possible. There are a couple of other solutions to this problem, the simplest is to add event.returnValue = false to make it work in IE:
Expand|Select|Wrap|Line Numbers
  1. <a href="#" onclick="doSomething(); event.returnValue = false; return false;">click me</a>
  2.  
And then there is the much more convoluted but more OOP method of attaching events at onLoad (which of course requires harvesting the element/s to change and using different methods for IE and everyone else):

Expand|Select|Wrap|Line Numbers
  1.  
  2. function preventDefaultAction(evt) {
  3.    if (evt) {
  4.       if (typeof evt.preventDefault!= 'undefined') {
  5.          evt.preventDefault(); // W3C
  6.       } else {
  7.          evt.returnValue = false; // IE
  8.       }
  9.    }
  10.    // safey for handling DOM Level 0
  11.    return false;
  12. }
  13.  
  14. function doSomething(evt) {
  15.    alert('do something cool');
  16.    return preventDefaultAction(evt);
  17. }
  18. function init() {
  19.    var target = document.getElementById('target');
  20.     if (target.addEventListener) { // use addEventListener for DOM
  21.        target.addEventListener('click', doSomething, false);
  22.     } else if (target.attachEvent) { // use attachEvent for IE
  23.        target.attachEvent('onclick', doSomething);
  24.     }
  25. }
  26.  

and the HTML


Expand|Select|Wrap|Line Numbers
  1.  
  2. <body onLoad="init()">
  3.    <div id="scrollbox"></div>
  4.    <p>If you have JS enabled, the page should not scroll to the top when you <a id="target" href="#">click this link</a>.</p>
  5. </body>
  6.  
HTH, Scott
Feb 15 '11 #3
matheussousuke
249 100+
I've been on this for weeks (In the beginning the issue was the player itself), someone lead me some light, please =/
Feb 15 '11 #4
acoder
16,027 Expert Mod 8TB
playItem() needs to be a function and I don't see it anywhere. Also, I would avoid naming elements and functions with the same name.

PS. merged threads.
Feb 15 '11 #5
matheussousuke
249 100+
Hi sir, what do you mean with "playItem() needs to be a function and I don't see it anywhere"?

U mean that the funcition is not being used by Internet Explorer anymore?

----- EDITING ----

I'm sorry, I've read "anymore", instead of "anywhere".
Feb 15 '11 #6
acoder
16,027 Expert Mod 8TB
The line which is causing problems:
Expand|Select|Wrap|Line Numbers
  1. playitem.setAttribute("onclick","playItem("+i+")");
translates as onclick="playItem(0)", onclick="playItem(1)" and so on depending on the number of items in the play list.
Feb 15 '11 #7
matheussousuke
249 100+
I cant use numbers, cause it's asx playlist with more than 800 itens, it is loaded and showed dynamicaly, just the links wont wokr once u click them.
Feb 15 '11 #8
matheussousuke
249 100+
So it will be like this?

Expand|Select|Wrap|Line Numbers
  1. function showPlayItems() {
  2.         WMP9=document.getElementById("MediaPlayer1");
  3.         playlistItems=WMP9.currentPlaylist.count;
  4.         for (i=0; i<playlistItems; i++) {
  5.                 playitem=document.createElement("a");
  6.                 playnext=document.createElement("br");
  7.                 playitem.setAttribute("href","javascript:void(0)");
  8.                 onclick="playItem("+i+")";
  9.                 playitem.innerText=WMP9.currentPlaylist.item(i).name;
  10.                 dp.appendChild(playitem);
  11.                 dp.appendChild(playnext);
  12.         }
  13.         playListLoaded=true;
  14.         WMP9.controls.play();
  15.  
  16. }
Feb 15 '11 #9
matheussousuke
249 100+
You can see the original here

http://tv.mghospedagem.com/wmp-pl3.html
Feb 15 '11 #10
acoder
16,027 Expert Mod 8TB
No, it can't be like that. If anything, it'd be something like:
Expand|Select|Wrap|Line Numbers
  1. playitem.onclick = function() { playItem(i) };
This will still not work because you haven't defined the function playItem().

You mention about not being able to use numbers. Well, then you need to tell us exactly what you can use.
Feb 16 '11 #11
matheussousuke
249 100+
I mentioned number because there is an +i+, I didnt see any zero, or one, 2, 3. So I thought the developer used that to show that the script will play only what is loaded dynamicaly from the P LIst.
Feb 17 '11 #12
acoder
16,027 Expert Mod 8TB
If you follow the code, you'll see that i is in fact a variable counter holding a number - see this line:
Expand|Select|Wrap|Line Numbers
  1. for (i=0; i<playlistItems; i++) {
It starts at 0 until the number of play list items.

Anyway, until you don't define playItems as a function, it's simply not going to work and you should see errors in your error console.
Feb 17 '11 #13
matheussousuke
249 100+
I'd like to thank you again for ur great help. thx for the support. Here is what I tried now:

Expand|Select|Wrap|Line Numbers
  1.  
  2. function showPlayItems() {
  3.         WMP9=document.getElementById("MediaPlayer1");
  4.         playlistItems=WMP9.currentPlaylist.count;
  5.         for (i=0; i<playlistItems; i++) {
  6.                 playitem=document.createElement("a");
  7.                 playnext=document.createElement("br");
  8.                 playitem.setAttribute("href","#");
  9.               //  onclick="playItem("+i+")";
  10.                 playitem.innerText=WMP9.currentPlaylist.item(i).name;
  11.                 dp.appendChild(playitem);
  12.                 dp.appendChild(playnext);
  13.         }
  14.         playListLoaded=true;
  15.         WMP9.controls.play();
  16.  
  17. }
  18.  
  19.  }
  20. playitem.onclick = function() { 
  21.  
  22.  
  23.  
  24.  
  25.  WMP9=document.getElementById("MediaPlayer1");
  26.         playlistItems=WMP9.currentPlaylist.count;
  27.         for (i=0; i<playlistItems; i++) {
  28.                 playitem=document.createElement("a");
  29.                 playnext=document.createElement("br");
  30.                 playitem.setAttribute("href","#");
  31.            playItem(+i+) };   //  onclick="playItem("+i+")";
  32.                 playitem.innerText=WMP9.currentPlaylist.item(i).name;
  33.                 dp.appendChild(playitem);
  34.                 dp.appendChild(playnext);
  35.         }
  36.         playListLoaded=true;
  37.         WMP9.controls.play();
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44. {
  45.  

The error is on <body onLoad="loadPlayItems()">

error name: Object Expected.
Feb 17 '11 #14
acoder
16,027 Expert Mod 8TB
OK, that's not correct. Before we proceed any further, where did you get the original code from or did you write it yourself?
Feb 23 '11 #15
matheussousuke
249 100+
I found it here http://groups.google.com/group/micro...ceaed3a1?pli=1

Then the playlist itens were not showing, after reading something on forum, I included playListLoaded=false; in the beginning. I'm completely new in JS.
Feb 23 '11 #16
acoder
16,027 Expert Mod 8TB
Having had a better look at your code, I see that you misnamed the function (or the person you copied from).

On line 24 in your original code, the code needs to refer to setPlayItem(i) - the function defined on line 36, not playItem(i).
Feb 24 '11 #17
matheussousuke
249 100+
I did this

Expand|Select|Wrap|Line Numbers
  1.  
  2. function showPlayItems() {
  3.         WMP9=document.getElementById("MediaPlayer1");
  4.         playlistItems=WMP9.currentPlaylist.count;
  5.         for (i=0; i<playlistItems; i++) {
  6.                 setPlayItem=document.createElement("a");
  7.                 playnext=document.createElement("br");
  8.                 setPlayItem.setAttribute("href","#");
  9.                 setPlayItem.setAttribute("onclick","playItem("+i+")");
  10.                 setPlayItem.innerText=WMP9.currentPlaylist.item(i).name;
  11.                 dp.appendChild(playitem);
  12.                 dp.appendChild(playnext);
  13.         }
  14.         playListLoaded=true;
  15.         WMP9.controls.play();
  16.  
  17. }

Nothing worked, and the playlist wont load the itens dinamicaly.
Feb 24 '11 #18
acoder
16,027 Expert Mod 8TB
I didn't meant the variable playitem (note the lower-case), I meant the function called onclick on line 24 (post #1) playItem() (upper-case I).

Badly named variables/functions anyway.
Feb 25 '11 #19
matheussousuke
249 100+
Ahhh... lol

I'll take a look on that
=D
Feb 25 '11 #20
matheussousuke
249 100+
What am I doing wrong? I tried this
Expand|Select|Wrap|Line Numbers
  1. function showPlayItems() {
  2.         WMP9=document.getElementById("MediaPlayer1");
  3.         playlistItems=WMP9.currentPlaylist.count;
  4.         for (i=0; i<playlistItems; i++) {
  5.                 playitem=document.createElement("a");
  6.                 playnext=document.createElement("br");
  7.                 playitem.setAttribute("href","#");
  8.  




Expand|Select|Wrap|Line Numbers
  1.  
  2. playitem.setAttribute("onclick","setPlayItem("+i+")");
  3.  
  4.  




Expand|Select|Wrap|Line Numbers
  1.      playitem.innerText=WMP9.currentPlaylist.item(i).name;
  2.                 dp.appendChild(playitem);
  3.                 dp.appendChild(playnext);
  4.         }
  5.         playListLoaded=true;
  6.         WMP9.controls.play();
  7.  
  8. }
  9.  
I still cant make the click work.
Feb 25 '11 #21
acoder
16,027 Expert Mod 8TB
So what happens now? Do you get any errors?
Feb 25 '11 #22
matheussousuke
249 100+
No, nothing, I used IE debugger. But I think you should check it yourself, you understand better than me http://tv.mghospedagem.com/wmp-pl.html

Use IE 8
Feb 25 '11 #23

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Jim | last post: by
7 posts views Thread by simon | last post: by
7 posts views Thread by Eran.Yasso | last post: by
3 posts views Thread by pplers | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.