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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • matheussousuke
    New Member
    • Sep 2009
    • 249

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

    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.


    Code:
    <head>
    <script language="javascript1.2">
    
    playListLoaded=false;
    
    
    function loadPlayItems() {
            df=document.getElementById("playItem");
            dp=document.getElementById("playlist");
            WMP9=document.getElementById("MediaPlayer1");
    
    WMP9.url="http://tv.mghospedagem.com/play.asx";
            WMP9.controls.play();
    
    }
    
    function showPlayItems() {
            WMP9=document.getElementById("MediaPlayer1");
            playlistItems=WMP9.currentPlaylist.count;
            for (i=0; i<playlistItems; i++) {
                    playitem=document.createElement("a");
                    playnext=document.createElement("br");
                    playitem.setAttribute("href","#");
                    playitem.setAttribute("onclick","playItem("+i+")");
                    playitem.innerText=WMP9.currentPlaylist.item(i).name;
                    dp.appendChild(playitem);
                    dp.appendChild(playnext);
            }
            playListLoaded=true;
            WMP9.controls.play();
    
    }
    
    
    
    function setPlayItem(index) {
            WMP9=document.getElementById("MediaPlayer1");
            playlistItems=WMP9.currentPlaylist.count;
            if (playlistItems > 0) {
    
    WMP9.controls.currentItem=WMP9.currentPlaylist.item(index);
                    WMP9.controls.play();
            }
    }
    
    </script></head>
    
    <body onLoad="loadPlayItems()">
    <object id="MediaPlayer1"
    classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6"
    type="application/x-oleobject" width="600" height="400">
    <param name="autostart" value="1">
            <param name="showcontrols" value="1">
            <param name="uimode" value="full">
            <param name="stretchtofit" value="1">
            <param name="enablecontextmenu" value="0">
    </object>
    
    <div id="playlist" style="position: absolute; top: 10px; left:
    640px; visibility: visible; z-index: 999999999999999;">
    <h2>Playlist</h2></div>
    
    <script language="javascript1.2" for="MediaPlayer1"
    event="playStateChange">
    WMP9=document.getElementById("MediaPlayer1");
    if (WMP9.playState==3 && ! playListLoaded) {
            showPlayItems();
    }
    
    
    
    
    
    
    </script>
  • matheussousuke
    New Member
    • Sep 2009
    • 249

    #2
    That's the first time that anyone help me here. That script problem must be a really hard issue to solve.

    Comment

    • matheussousuke
      New Member
      • Sep 2009
      • 249

      #3
      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.returnVal ue = false to make it work in IE:
      Code:
      <a href="#" onclick="doSomething(); event.returnValue = false; return false;">click me</a>
      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):

      Code:
      function preventDefaultAction(evt) {
         if (evt) {
            if (typeof evt.preventDefault!= 'undefined') {
               evt.preventDefault(); // W3C
            } else {
               evt.returnValue = false; // IE
            }
         }
         // safey for handling DOM Level 0
         return false;
      }
      
      function doSomething(evt) {
         alert('do something cool');
         return preventDefaultAction(evt);
      }
      function init() {
         var target = document.getElementById('target');
          if (target.addEventListener) { // use addEventListener for DOM
             target.addEventListener('click', doSomething, false);
          } else if (target.attachEvent) { // use attachEvent for IE
             target.attachEvent('onclick', doSomething);
          }
      }

      and the HTML


      Code:
      <body onLoad="init()">
         <div id="scrollbox"></div>
         <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>
      </body>
      HTH, Scott

      Comment

      • matheussousuke
        New Member
        • Sep 2009
        • 249

        #4
        I've been on this for weeks (In the beginning the issue was the player itself), someone lead me some light, please =/

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          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.

          Comment

          • matheussousuke
            New Member
            • Sep 2009
            • 249

            #6
            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".

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              The line which is causing problems:
              Code:
              playitem.setAttribute("onclick","playItem("+i+")");
              translates as onclick="playIt em(0)", onclick="playIt em(1)" and so on depending on the number of items in the play list.

              Comment

              • matheussousuke
                New Member
                • Sep 2009
                • 249

                #8
                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.

                Comment

                • matheussousuke
                  New Member
                  • Sep 2009
                  • 249

                  #9
                  So it will be like this?

                  Code:
                  function showPlayItems() {
                          WMP9=document.getElementById("MediaPlayer1");
                          playlistItems=WMP9.currentPlaylist.count;
                          for (i=0; i<playlistItems; i++) {
                                  playitem=document.createElement("a");
                                  playnext=document.createElement("br");
                                  playitem.setAttribute("href","javascript:void(0)");
                                  onclick="playItem("+i+")";
                                  playitem.innerText=WMP9.currentPlaylist.item(i).name;
                                  dp.appendChild(playitem);
                                  dp.appendChild(playnext);
                          }
                          playListLoaded=true;
                          WMP9.controls.play();
                   
                  }

                  Comment

                  • matheussousuke
                    New Member
                    • Sep 2009
                    • 249

                    #10
                    You can see the original here

                    Comment

                    • acoder
                      Recognized Expert MVP
                      • Nov 2006
                      • 16032

                      #11
                      No, it can't be like that. If anything, it'd be something like:
                      Code:
                      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.

                      Comment

                      • matheussousuke
                        New Member
                        • Sep 2009
                        • 249

                        #12
                        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.

                        Comment

                        • acoder
                          Recognized Expert MVP
                          • Nov 2006
                          • 16032

                          #13
                          If you follow the code, you'll see that i is in fact a variable counter holding a number - see this line:
                          Code:
                          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.

                          Comment

                          • matheussousuke
                            New Member
                            • Sep 2009
                            • 249

                            #14
                            I'd like to thank you again for ur great help. thx for the support. Here is what I tried now:

                            Code:
                            function showPlayItems() {
                                    WMP9=document.getElementById("MediaPlayer1");
                                    playlistItems=WMP9.currentPlaylist.count;
                                    for (i=0; i<playlistItems; i++) {
                                            playitem=document.createElement("a");
                                            playnext=document.createElement("br");
                                            playitem.setAttribute("href","#");
                                          //  onclick="playItem("+i+")";
                                            playitem.innerText=WMP9.currentPlaylist.item(i).name;
                                            dp.appendChild(playitem);
                                            dp.appendChild(playnext);
                                    }
                                    playListLoaded=true;
                                    WMP9.controls.play();
                             
                            }
                             
                             }
                            playitem.onclick = function() { 
                            
                            
                            
                            
                             WMP9=document.getElementById("MediaPlayer1");
                                    playlistItems=WMP9.currentPlaylist.count;
                                    for (i=0; i<playlistItems; i++) {
                                            playitem=document.createElement("a");
                                            playnext=document.createElement("br");
                                            playitem.setAttribute("href","#");
                                       playItem(+i+) };   //  onclick="playItem("+i+")";
                                            playitem.innerText=WMP9.currentPlaylist.item(i).name;
                                            dp.appendChild(playitem);
                                            dp.appendChild(playnext);
                                    }
                                    playListLoaded=true;
                                    WMP9.controls.play();
                            
                            
                            
                            
                            
                            
                            {

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

                            error name: Object Expected.

                            Comment

                            • acoder
                              Recognized Expert MVP
                              • Nov 2006
                              • 16032

                              #15
                              OK, that's not correct. Before we proceed any further, where did you get the original code from or did you write it yourself?

                              Comment

                              Working...