XSPF Playlist generates a playlist feed in the standard XSPF format from files that are attached to a piece of content. XSPF files are used by audio and video players to present playlists--displays of media a user can view or listen to.

The module was designed for Jeroen Wijering's flash player, though it should work with other flash players. The administrative interface allows the administrator to select what node types it works on, choose a default thumbnail file to use, and configure support for CCK fields. The module supports multiple file types (audio, video, flash).

This module is partially supported by CivicActions.

Overview: Associating media files with content

Playlists are specially formatted xml files. They are constructed by XSPF Playlist module from media files associated with a piece of content (a node). Files can be associated in various methods, including:

  • Using the Upload module (part of Drupal core). Enable the upload module, configure one or more content types to accept uploads, and upload files associated with content. Sample configurations:
    • Create an 'Album' content type and enable uploads on it. For each audio album, create a new piece of content and upload all the album's songs as attachments to the content.
    • Create a 'Video' content type and enable uploads on it. Upload one or more videos and thumbnail images with each piece of video content created.
  • Use the Media Mover module, http://drupal.org/project/media_mover. Install and configure Media Mover and use it to associate media with content.
  • Use CCK (filefield, multiimage, etc.) to associate media with content.

Setup and configuration

XSPF Playlist configuration

First, enable appropriate XSPF Playlist modules: admin/build/modules/list:

  • XSPF Playlist
  • XSPF Playlist Node
  • XSPF Playlist Thumbnail

    Optionally(?) enable

  • XSPF Playlist Audio - useful if you're doing audio/music playlists
  • XSPF Playlist CCK - useful if you're using CCK fields instead of attachments

To make things work, do this:

  1. Browse to XSPF Playlist Administration settings: admin/settings/xspf_playlist
  2. Provide some default playlist settings such as Title and Info
  3. List all file types supported. use file extentions such as: flv jpg jpeg gif png mp3 mp4 wav ogg swf mov avi
  4. Choose which content types you want to build playlists from
  5. Save the configuration, and prepare to go back

Important!! Setup Playlist Content Types

  1. To do this, you need to Re-visit the admin settings page: admin/settings/xspf_playlist, after choosing a content type (above).
  2. Upon re-visiting the page, you'll see a new link in the Content settings group (under the content types list). Now visit each Content Settings link for the content "Type(s)" you've enabled. for example, admin/settings/xspf_playlist/video, if you have enabled a custom video content type.
  3. Finally, configure settings for content type, such as determining the files & thumbnails associated with the playlist

Test your setup

Now, go to a node made from a music/video content type. Use the format node/XX/xspf where XX is a node ID. If everything is setup correctly, this will provide an xspf formated playlist (you should expect to see an xml file).

If you have problems, be certain you've chosen a node made from a content type that you've just configured for XSPF.

Views 1 usage (Drupal 5)

XSPF Playlist integrates with Views to provide the XSPF format from any view with appropriate content. To produce a playlist from a view:

  • Create a new view, filtered to display nodes with associated media files.
  • Enable page display for the view and give it a path. For the page view type, select 'XSPF Playlist'.
  • The view must have "Provide page view" and "Provide block".
  • Visit the URL at which the view page displays, e.g., /myview. You should get a playlist with all files associated with the content in the view.

Viewing playlists through FLV Media Player

XSPF Playlist can be used with the FLV Media Player module to provide URLs and content online status to a media player.

For an example of a site that's doing this really well, take a look at the video player on the homepage of The Hub. (To see the playlist in action do this: on the Editor's Picks video player, click on the little icon that looks like four squares, alongside the time track bar. This will open up the playlist inside the video window.)

Developer usage

XSPF Playlist provides a set of hooks enabling other modules to define and alter playlist data and associated thumbnail images.

Defining the items in a playlist

Modules can implement hook_xspf_playlist_use() to define the items a playlist should be constructed from. Here's a sample implementation:


/**
 * implemenation of hook_xspf_playlist_use
 */
function media_mover_api_xspf_playlist_use($op, $node, $config) {
  switch($op) {
    case 'define' :  
      $configurations = _mm_get_active_configurations();  
      foreach ($configurations as $configuration ) {
        $define['media_mover_api--'. $configuration->cid] = t('Media Mover: ') . $configuration->name;    
      }
      return $define;  
    break;
    
    case 'return':
      // get files for the running configuration
      if ($mmfiles = $node->media_mover[$config]) {
        $items = array();
        foreach($mmfiles as $mmfile) {     
          $filepath = $mmfile['complete_file'];
          // make sure that the file path is complete      
          if (! strstr($filepath, 'http://')) {
            // we're using base_url here because things get messy otherwise
            $filepath = $GLOBALS['base_url'] .'/'. $filepath;
          }
          // only add the file if we have an incoming item
          if ($xspf_item = xspf_playlist_node_create_file_item($node, $filepath, $node->type)) {
            $items[] = $xspf_item;
          }  
        }
        return $items;
      }
   break;
  }
}

Altering existing playlist items or entire playlists

Playlists and playlist items are passed through drupal_alter() style hooks prior to display. Contextual information fed to these hooks can be used to determine the type of playlist or item being generated.

hook_xspf_playlist_item_alter() receives a single item and can be used to alter existing attributes or add new ones. Sample implementation adding metadata to an item:


/**
 * Implementation of hook_xspf_playlist_item_alter().
 *
 * Add player and bookmark metadata.
 */
function mymodule_xspf_playlist_item_alter(&$item, $node, $url, $thumb, $meta) {
  $item[] = array(
    'key' => 'meta',
    'value' => array('first', 'second'),
    'attributes' => array(
      'rel' => 'bookmark_data'
    ),
  );
  
}

hook_xspf_playlist_list_alter() receives a playlist and can be used to alter existing attributes, including an array of items in the playlist, or add new ones.

Associating thumbnail images with playlist items

Modules can return methods for defining the thumbnail images that can be associated with playlist items. Sample implementation:


/**
 * implements hook_xspf_playlist_thumbnail
 * build the default options for the admin screen
 * @param $op is the operation happening
 * @param $node is a node object
 * @param $config is which config to run
 */
function xspf_playlist_thumb_xspf_playlist_thumbnail ($op, $node, $config = null) {
  switch($op){
    case 'define':
      $items = array(
        'xspf_playlist_thumb--1' => t('none'),
        'xspf_playlist_thumb--2' => t('XSPF: Default thumbnail'),
        'xspf_playlist_thumb--3' => t('XSPF: Attached files'),
      );
      return $items;
    break;

    case 'config':
      // return a configuration array
      $form['xspf_playlist_thumb_'. $node->type] = array(
        '#type' => 'textfield',
        '#title' => t('Path to default thumbnail'),
        '#default_value' => variable_get('xspf_playlist_thumb_'. $node->type, null),
        '#description' => t('Enter a path to a thumbnail you wish to use as a default'),
        '#prefix' => '<div id="xspf_playlist--2_config" class="xspf_playlist_config_thumb">',
        '#suffix' => '</div>',
      );
      return $form;
    break;

    case 'return':
      switch ($config){
        case 1:
          return;
        break;
        case 2:
          // return default thumbnail
          return variable_get('xspf_playlist_thumb_'. $node->type, null);
        break;

        case 3:
          return xspf_playlist_thumb_get_attached_files($node);
        break;

      }
    break;
  }
}

Comments

nodecode’s picture

A critical piece of the puzzle left out in the above text: It appears that you have to select "XSPF Playlist: node has playlist content" in the Filters section of your View to get this to work.

jsulmar’s picture

My browser did not display XML at URL ../node/XX/xspf. It was necessary to select "view source" in order to see the XML. This took me some time to figure out, and it may be helpful to add this suggestion to the "Test Your Setup" section.
thanks

captaingeek’s picture

I suspect it has somthing to do with my view config. I'm just trying to create an audio playlist. I've exported my view. If somone has a view that displays all audio files that works for the xspf module that you could share that would be cool.

  $view = new stdClass();
  $view->name = 'playlist';
  $view->description = 'playlist';
  $view->access = array (
);
  $view->view_args_php = '';
  $view->page = TRUE;
  $view->page_title = 'playlist';
  $view->page_header = '';
  $view->page_header_format = '1';
  $view->page_footer = '';
  $view->page_footer_format = '1';
  $view->page_empty = '';
  $view->page_empty_format = '1';
  $view->page_type = 'xspf_playlist_node';
  $view->url = 'playlist';
  $view->use_pager = FALSE;
  $view->nodes_per_page = '50';
  $view->block = TRUE;
  $view->block_title = 'playlist';
  $view->block_header = '';
  $view->block_header_format = '1';
  $view->block_footer = '';
  $view->block_footer_format = '1';
  $view->block_empty = '';
  $view->block_empty_format = '1';
  $view->block_type = 'xspf_playlist_node';
  $view->nodes_per_block = '10';
  $view->block_more = FALSE;
  $view->block_use_page_header = FALSE;
  $view->block_use_page_footer = FALSE;
  $view->block_use_page_empty = FALSE;
  $view->sort = array(
  );
  $view->argument = array(
  );
  $view->field = array(
  );
  $view->filter = array(
    array(
      'tablename' => 'audio',
      'field' => 'downloadable',
      'operator' => '=',
      'options' => '',
      'value' => '1',
    ),
  );
  $view->exposed_filter = array(
  );
  $view->requires = array(audio);
  $views[$view->name] = $view;
captaingeek’s picture

any idea why playlist aren't generating? I'm seeing this error in the log:

Location http://localhost/admin/build/views/15/edit
Referrer http://localhost/admin/build/views/15/edit
Message Invalid argument supplied for foreach() in \includes\form.inc on line 950.

rayvan’s picture

This module is extensive and advanced but it is not user friendly. It took me more than an hour to setup and I'm still mystified as to how all of this works.

I'm putting this as a note to someone checking the module out-unless your use cases for media are very specific to JWPlayer-this probably isn't the module for you.