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

Forums

/

Does version 4 handle the add of an item?

6 replies [Last post]

Hi,

The documentation about the version changes says that these functions have been deleted:
"addItem / removeItem javascript calls (the LOAD call is more flexible now).".

I search on the forum and in the source code how to add an item to the playlist, but I didn't found how to do it. So my question is simple: Does the version 4 of the player handle the add of an item to the playlist with javascript.

Anyone seems to have the answer, that's why I wanted to ask it to you JeroenW.

Thx!

PS: sorry for my english!

I haven't tried this yet, but is seems that you would:

1) get a reference to the player:var player = getPlayer('myplayer');
2) create your new item (track object):var newItem = {file:'video.flv', title:'New Video File', author:'Somebody'};
3) get the existing playlist:var oldList = player.getPlaylist();
4) concatenate the objects:var newList = oldList.concat(newItem);
5) load the new playlist into the player:player.sendEvent("LOAD", newList);

It also looks like you can load multiple objects, so maybe steps 4 & 5 can be combined into this:

var lst = array(oldList, newItem);
player.sendEvent("LOAD", lst);

Assuming that this works correctly, you could load multiple new items in one call:

var lst = array(oldList, newItem1, newItem2, newItem3);
player.sendEvent("LOAD", lst);

Excellent JSON reference: http://www.hunlock.com/blogs/Mastering_JSON_(_JavaScript_Object_Notation_)

Hi basic,

Thanks for your answer, I just tried your code (here is a test page: http://mypodpage.webdynamit.net/test.player3.php), but there are two problems.

First, it clear the old playlist and then it load the new one, so if your listening something while you push the button to add the item, your music is stopped. That wasn't like this with the version 3.

Secondly, the elements added to the playlist can't be read. Flash debugger send this error message:

TypeError: Error #1010: Un terme n'est pas défini et n'a pas de propriété. (In english: A term is not defined and has no property.)
at com.jeroenwijering.player::Model/::itemHandler()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.jeroenwijering.player::Controller/::playItem()
at com.jeroenwijering.player::Controller/::itemHandler()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.jeroenwijering.player::View/sendEvent()
at com.jeroenwijering.views::PlaylistView/::clickHandler()

Bye!

Thanks for testing it.

Certainly any time that you load a new playlist, the player will stop playing the currently playing item, it simply doesn't exist anymore.

Unless we can figure out a better way to do this (and there probably IS a better way), you could delay the loading of the new playlist until the currently playing item completes. Of course, the new item won't appear on the playlist immediately. Perhaps you could output a short message, something like, "Playlist will be updated when the current item finishes playing.".
I know —— kind of kludgy.

The second item is much more serious. I noticed that the first item from the old playlist still plays, so it's likely somethng wrong with the format or contents of the JSON object newItem.

It seems that the item being added must be a complete object (see code);

<html>

  <head>

    <title>Add Item To Playlist - JW FLV Media Player v4.0</title>

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

  </head>

  <body>

    <script type="text/javascript">
      var container     = 'player_container';
      var player_id     = 'player';
      var width         = 400;
      var playlistWidth = 300;
      var height        = 300;
      var playerName    = new String();
      var playerState   = null;

      if(window.addEventListener)
      {
        window.addEventListener('load', createPlayer, false);
      }
      else if(document.addEventListener)
      {
        document.addEventListener('load', createPlayer, false);
      }
      else if(window.attachEvent)
      {
        window.attachEvent('onload', createPlayer);
      }

      function createPlayer()
      {
        var so = new SWFObject('player-4.0c.swf', player_id, width + playlistWidth, height, '9', '#FFFFFF');
            so.addParam('allowscriptaccess',     'always');
            so.addParam('allowfullscreen',       'true');
            so.addVariable('width',               width + playlistWidth);
            so.addVariable('height',              height);
            so.addVariable('playlistsize',        playlistWidth);
            so.addVariable('playlist',           'right');
            so.addVariable('link',               'http://www.google.fr/');
            so.addVariable('file',               'http://mypodpage.webdynamit.net/players/mp3/Jackass - Start.mp3');
            so.addVariable('title',              'Jackass');
            so.addVariable('description',        'description');
            so.addVariable('image',              'http://www.google.fr/logos/tourdefrance08.gif');
            so.addVariable('author',             'Google');
            so.addVariable('repeat',             'true');
            so.write(container);
      };

      function addPlaylist(newItem)
      {
        var addItem =
        {
          link:         newItem.link,
          file:         newItem.file,
          author:       newItem.author,
          start:        '0',
          type:         'sound',
          image:        newItem.image,
          description:  'description',
          title:        newItem.title,
          duration:     '0'
        };
        var player  = document.getElementsByName(player_id)[0];
        var oldList = player.getPlaylist();
        var newList = oldList.concat(addItem);
        player.sendEvent("LOAD", newList);

        //...alternate method - loses first item
        //var lst = Array(oldList, addItem);
        //player.sendEvent("LOAD", lst);

        for(var j in newList)
        {
          var nodes = '<br />';
          for(var k in newList[j])
          {
            nodes += '<li>' + k + ': ' + newList[j][k] + '</li>';
          }
          gid('dump' + j).innerHTML = nodes;
        }
      };

      function gid(name)
      {
        return document.getElementById(name);
      };
    </script>

    <button onclick="addPlaylist({link:'http://www.google.fr/',                                         file: 'http://mypodpage.webdynamit.net/players/mp3/Jackass - Start.mp3', title:'Jackass',       image:'http://www.google.fr/logos/tourdefrance08.gif',            author:'Google'});">Jackass</button>
    <button onclick="addPlaylist({link:'http://www.radiofrance.fr/chaines/lemouv/home/index_flash.php', file: 'http://mypodpage.webdynamit.net/players/mp3/willi waler.mp3',     title:'Willy Waller',  image:'http://mypodpage.webdynamit.net/img/podcasts/13-100.jpeg', author:'Radio France'});">Willy Waller</button>
    <button onclick="addPlaylist({link:'http://www.ouifm.fr',                                           file: 'http://mypodpage.webdynamit.net/players/mp3/poupipou.mp3',        title:'Poupipou',      image:'http://mypodpage.webdynamit.net/img/podcasts/33-40.jpeg',  author:'Oui FM'});">Poupipou</button>
    <div id="player_container">
    </div>
    <div id="dump0">
    </div>
    <div id="dump1">
    </div>
    <div id="dump2">
    </div>
    <div id="dump3">
    </div>
    <div id="dump4">
    </div>
    <div id="dump5">
    </div>

  </body>

</html>

With this working code, you could experiment to see exactly what is really needed, and maybe achieve a simpler method of adding an item to a playlist.

Indeed, the item to add should be an object, with AT LEAST a 'file' and 'type' reference:

{file:'myvideo.flv',type:'video'}

If somebody has an elegant way to prevent the stopping on playlist loads, I'd be happy to hear. Problem is that there's no way the player can presume the old file is the same as the new one....

I have a Video not found or acces denied if i try to play a video i added to the list
http://www.starsclips.com/playlits-add-item5.html

update
Ok, i Added type: 'youtube' and it's working

But now i try to add a complete playlist but it doesn't work

It will be interresting to update this to swfobject.2.2js

It'll still be the same thing. All swfobject does, is embed the Flash content.

    http://willswonders.myip.org:8074/AddItem_v4-1.html