473,513 Members | 2,677 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

matheussousuke
249 New Member
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 2751
matheussousuke
249 New Member
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 New Member
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 New Member
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 Recognized Expert Moderator MVP
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 New Member
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 Recognized Expert Moderator MVP
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 New Member
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 New Member
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 New Member
You can see the original here

http://tv.mghospedagem.com/wmp-pl3.html
Feb 15 '11 #10
acoder
16,027 Recognized Expert Moderator MVP
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 New Member
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 Recognized Expert Moderator MVP
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 New Member
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 Recognized Expert Moderator MVP
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 New Member
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 Recognized Expert Moderator MVP
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 New Member
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 Recognized Expert Moderator MVP
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 New Member
Ahhh... lol

I'll take a look on that
=D
Feb 25 '11 #20
matheussousuke
249 New Member
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 Recognized Expert Moderator MVP
So what happens now? Do you get any errors?
Feb 25 '11 #22
matheussousuke
249 New Member
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

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

Similar topics

1
1530
by: Jim | last post by:
Hey guys I DESPERATLY need some help with this small javascript i have on this website. All that it's supposed to do is change the button image once it's pressed but alas... I copy-pasted the code as it was given to me from Imageready but it won't work. The event that i wanted (and "created" with Imageready) was ondown. The code is this:...
4
2281
by: Mark | last post by:
the Following bit of code doesn't work. It seems to respond to the second, starting with 'add iif statement for Good Practice', but not to the first, starting 'add iif statement for archived' Help me to sort this out, it has taken me almost a week to wade through and it still won't work. Select Case Forms("frmForce").OpenArgs
4
3064
by: Chad | last post by:
I have a link (.ascx) and that generates an Add form on that page. The autopostback dropdown is within a "If Not IsPostBack Then" statement. The form that is created is all via static html in the user control. The problem is, no matter what even when no data is filled out in the form, the submit button just postsback the page and nothing...
7
1763
by: simon | last post by:
I have simple html(aspx) page, but vertical height won't work. Even if i had set the height of a table=100%, the table is not 100% height. I spend a lot of time(my real page is more complicated) to figured it out that this won't work because of attribute of a page: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"...
3
5041
by: musosdev | last post by:
Hi guys Okay, I've setup my projects to open and compile fine in VS2005 using FPSE and remote web, but it's *really* slow. So I thought I'd have a go at doing it the normal way, by loading from the network share. It loads in VS2005 fine, and I can edit and save code changes etc, but when I try and Build the solution, I get the following...
6
4174
by: b. hotting | last post by:
Hi, I don't see why this won't work, it are 3 links, the last one (a get) does work, but the first 2 won't. i would like to use a post, through hidden input types any idea? thanks for your help! bjorn
7
11183
by: Eran.Yasso | last post by:
Hi, I have project that automate excel(using Excel COM) which works fine in my home. I took the project from my home to work and tried to build the project but it won't built. I get error "The type or namespace name 'Excel' could not be found". the error points to line in my code: "public Excel.Application ExcelObj = null".
3
2104
by: pplers | last post by:
it's an example. I want a script to print the real url behind a lix.in one so i tried these: use LWP::UserAgent; use LWP::UserAgent; my $ua = new LWP::UserAgent; my $response = $ua->post('http://lix.in/53fe67',{ tiny => '53fe67', submit => 'continue',}); my $con = $response->content;
4
5573
by: justabeginner | last post by:
First of all, let me say I've had very little training in html and probably know just enough to be dangerous. I designed a website for my alumni association last summer using XHTML Transitional and CSS. I finally got around to posting it, but in the meantime IE7 came out. Everything looks fine in IE6 and FF, but when the page is opened in IE7 the...
4
2493
by: z55177 | last post by:
My domain: http://www.esthevision.cz/ This is the cause of my problem. The template is supposed to look somewhat like this: PINK STRIPE http://themebot.com/website-templates/ht... I created an extra copy of it called Natvrdo, since I modified the logo. Okay, I have this in my HTML (Natvrdo being the CSS style sheet) This is what I have...
0
7269
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7177
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7394
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7559
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7123
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3248
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3237
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.