Order Now AdSolution Sign Up | Login » Bits on the Run Sign Up | Login »

Forums

/

Direct Linking Part 2

18 replies [Last post]

Alright, let me word my post a little differently. Hopefully I can find some help that way.

How can I have call a video to play based on its "title" rather than its item position in the XML document with the getQueryParamValue?

I currently need the link by a number for one part of my site but would like to have the additional option to call by the title.

My current code based off of another post here:

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

<script type="text/javascript" src="swfobject.js"></script>

<script type="text/javascript">
var player = null;
var playItem = null;
var file = null;

if(!(playItem = swfobject.getQueryParamValue('item')))
{
// default is first item (array counting starts at 0)
playItem = 0;
}

if(!(file = swfobject.getQueryParamValue('playlist')))
{
// default playlist
file = 'playlist.xml';
}

//alert('Play Item: ' + playItem + '\nFile: ' + file);

function playerReady(obj)
{
player = document.getElementById(obj.id);
playAway();
};

// start the player on the query parameter item
function playAway()
{
if(player)
{
//alert('playAway:\nPlayer: ' + player.id + '\nplayAway - playItem:' + playItem);
setTimeout("player.sendEvent('ITEM', playItem)", 200);
setTimeout("player.sendEvent('PLAY', 'true')", 400);
}
else
{
setTimeout("playAway()", 200);
}
};
</script>

<script type="text/javascript">
var flashvars = {
file:file,
autostart:"true",
shuffle:"false",
playlistsize:"200",
playlist:"bottom",
skin:"stylish/modieus.swf",
frontcolor:"cccccc",
lightcolor:"6e1f84",
backcolor:"111111",
repeat:"list"
//logo:"logo_overlay.png"

}
var params = {
allowfullscreen:"true",
allowscriptaccess:"always"
}
var attributes = {
id:"player1",
name:"player1"
}
swfobject.embedSWF("player.swf", "placeholder1", "570", "570", "9.0.115", false, flashvars, params, attributes);

</script>

</head>

<body>

<div id="wrapper">
<div id="placeholder1">
<a href="http://www.macromedia.com/go/getflashplayer">Get flash</a> to see this player.
</div>
</div>

</body>

Use this code: removeIt(removeItTitle) from this thread, except instead of removing the title, play it. You will have to update the code for teh v4.x players.

http://www.longtailvideo.com/support/forum/JavaScript-Interaction/9232/remove-item-by-file-title

Yes, I saw that code but I didn't know how to update it to the v4.x players. Can you help out with that?

Thanks,
Jordan

@Jordan,

The v4.x player code would be:

      // play item by Title
      function playIt(playItem)
      {
        var playlist = player.getPlaylist();

        for(var j in playlist)
        {
          if(playItem == playlist[j].title)
          {
            player.sendEvent('ITEM', j);
          }
        }
      };

You can see it in context here for a day or two:

http://willswonders.myip.org:8085/php/Jordan.html

Add a few songs by clicking on the first row of buttons; make sure "Song 3" is one of them.

Then click [Play by Title: "Song 3"]

Awesome! I will give this a try.

@noMind,

Ok, as you can tell I am new to the JW Player so I am struggling a bit. I can't figure out how to integrate the title code into my code to work properly. Could you help?

Thanks!!!!

Did you look at the demo code to see the function in context?

Post your test page or a link to it and I'll help you integrate the playIt() function.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>University of Wisconsin-Stevens Point :: Video Player</title>
<style type="text/css">
body {
padding:0;
margin:0;
}

</style>

<script type="text/javascript" src="swfobject.js"></script>

<script type="text/javascript">
  var player = null;
      var playItem = null;
      var file = null;
      var id = null;
     
     
  

      if(!(playItem = swfobject.getQueryParamValue('item')))
      {
        // default is first item (array counting starts at 0)
        playItem = 0;
      }

      if(!(file = swfobject.getQueryParamValue('playlist')))
      {
        // default playlist
        file = 'playlist.xml';
      }
     
      if(!(id = swfobject.getQueryParamValue('id')))
      {
        // default is first item (array counting starts at 0)
        id = null;
      }

     
  
//alert('Play Item: ' + playItem + '\nFile: ' + file);

      function playerReady(obj)
      {
     
        player = document.getElementById(obj.id);
       
        playAway();
      };
     
    
    
     // play item by Title
      function playIt(id)
      {
        var playlist = player.getPlaylist();

        for(var j in playlist)
        {
          if(id == playlist[j].title)
          {
            player.sendEvent('ITEM', j);
          }
        }
      };
    
  
  
      // start the player on the query parameter item
      function playAway()
      {
        if(id == null)
        {
//alert('playAway:\nPlayer: ' + player.id + '\nplayAway - playItem:' + playItem);
          setTimeout("player.sendEvent('ITEM', playItem)", 200);
          setTimeout("player.sendEvent('PLAY', 'true')", 400);
            }
        else
        {
        playIt(id);
          //setTimeout("playAway()", 200);
        }
      };
    </script>

    <script type="text/javascript">
     var flashvars = {
                    file:file,
                    autostart:"true",
                    shuffle:"false",
                    playlistsize:"200",
                    playlist:"bottom",
                    skin:"stylish/modieus.swf",
                    frontcolor:"cccccc",
                    lightcolor:"6e1f84",
                    backcolor:"111111",
                    repeat:"list"
                    //logo:"logo_overlay.png"
                   
            }
            var params = {
                    allowfullscreen:"true",
                    allowscriptaccess:"always"
            }
            var attributes = {
                    id:"player1", 
                    name:"player1"
            }
            swfobject.embedSWF("player.swf", "placeholder1", "570", "570", "9.0.115", false, flashvars, params, attributes);

    </script>

</head>

<body>

<div id="wrapper">
    <div id="placeholder1">
        <a href="http://www.macromedia.com/go/getflashplayer">Get flash</a> to see this player.
    </div>
</div>

</body>

</html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

  <head>

    <!--  call with:  http://www.mydomain.com/Jordan-2.html?&amp;id=Doing My Time&amp;item=&amp;playlist=playlist.xml  -->
    <!--  call with:  http://www.mydomain.com/Jordan-2.html?&amp;id=&amp;item=3&amp;playlist=playlist.xml  -->

    <title>University of Wisconsin-Stevens Point :: Video Player</title>

    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

    <style type="text/css">
      body 
      {
        padding:                  0;
        margin:                   0;
      }
    </style>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.1/swfobject.js"></script>

    <script type="text/javascript">
      var player     = null;
      var playItem   = null;
      var file       = null;
      var id         = null;

      if(!(playItem = swfobject.getQueryParamValue('item')))
      {
        //...default is first item (array counting starts at 0)
        playItem = 0;
      }

      if(!(file = swfobject.getQueryParamValue('playlist')))
      {
        // default playlist
        file = 'playlist.xml';
      }

      if(!(id = swfobject.getQueryParamValue('id')))
      {
        //...default is first item
        id = null;
      }

//alert('Play Item: ' + playItem + '\nFile: ' + file + '\nID (Title): ' + id);

      function playerReady(obj)
      {
        player = document.getElementById(obj.id);
        playAway();
      };

      //...start the player on the query parameter item
      function playAway()
      {
        if(id == null)
        {
//alert('playAway:\nplayAway - playItem:' + playItem);
          setTimeout("player.sendEvent('ITEM', playItem)", 200);
          setTimeout("player.sendEvent('PLAY', 'true')", 400);
        }
        else
        {
          playIt(id);
        //setTimeout("playAway()", 200);
        }
      };

      //...start the player on the play item by Title
      function playIt(id)
      {
        var title    = unescape(id);
        var playlist = player.getPlaylist();

        for(var j in playlist)
        {
//alert(playlist[j].title);
          if(title == playlist[j].title)
          {
//alert('playIt:\nTitle:' + title + '\nPlaylist Title: ' + playlist[j].title + '\nIndex: ' + j);
            player.sendEvent('ITEM', j);
            break;
          }
        }
      };
    </script>

    <script type="text/javascript">
      var flashvars =
      {
        file:                          file,
        autostart:                    'true',
        shuffle:                      'false',
        playlist:                     'bottom',
        playlistsize:                 '200',
        skin:                         'stylish/modieus.swf',
        frontcolor:                   'cccccc',
        lightcolor:                   '6e1f84',
        backcolor:                    '111111',
        repeat:                       'list'
      //logo:                         'logo_overlay.png'
      };

      var params =
      {
        allowfullscreen:              'true', 
        allowscriptaccess:            'always'
      };

      var attributes =
      {
        id:                           'player1', 
        name:                         'player1'
      };

      swfobject.embedSWF('player-4.4.135.swf', 'placeholder1', '570', '570', '9.0.124', false, flashvars, params, attributes);
    </script>

  </head>

  <body>

    <div id="wrapper">
      <div id="placeholder1">
        <a href="http://www.macromedia.com/go/getflashplayer">Get flash</a> to see this player.
      </div>
    </div>

  </body>

</html>

Awesome, thank you, thank you, Thank You!!!

yer welcome!

to: lefTy

Wow!!! Thanks a lot for your code!
It took me 3 days to find the solution for this!!!

REALLY THANK YOU!

Thank you lost.
After my last post i had a problem, that i had to refresh the page after i call it with title, or it just loaded the first video in the playlist.
Your callpage_title script helped me a lot.
Thank you!!!

@OLEG,

You're welcome.

    Good Luck!

http://ocf.mcddesign.com/help_system/js/OCF_Help-call_from_URL.html?&id=&item=1&playlist=playlist.xm...

Always plays video list item 0 - the URL's above from lost are no longer available. Using ID is the same.

@Terry

Check that you are using <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.1/swfobject.js"></script>. I had a similar problem until I did so.

OK I have most of this working now. According to the code I can call a playlist with the URL: &playlist=playlist.xml but that does not seem to work. I can call the "item" with the URL if I add the location of the playlist to the player code.
URL to my playlist: http://ocf.mcddesign.com/help_system/js/playlist.xml
URL to the player:
http://ocf.mcddesign.com/help_system/js/OCF_Help-call_from_URL-1.html?playlist=playlist.xml&item=3

Removed