I needed a jPlayer with a manually compiled list of items not based on a field. Instead of reimplenting the whole theme function, it was actually really easy to make theme('jplayer') work without providing an entity and a field name, but just a list of items.

With the attached patch, it's possible to use theme('jplayer', $vars), with
$vars => array('items' => $items, 'settings' => $settings).

CommentFileSizeAuthor
jplayer_without_entities.patch1.6 KBFrando
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

EJx64’s picture

Ok, so I'm quite stuck- I've been trying to figure out a way to better control a feed of audio/video items. I just want the user to see one item at a time (Not a playlist), and play a continuous feed of nodes, controlled by database access requests (or node requests). (When the current item finishes, grab another from the system and play that).

Not sure if that's what this patch is trying to accomplish, but I've applied it and trying to get it to work as described. However I don't know how to build my array of items. Also I'm not sure if my settings are formatted correctly, they don't seem to be... I'm using hook_page_menu() to call this function below.

Any assistance will be greatly appreciated! Thanks in advance!

function music_page2() {

$items = array();
$settings = array();

$settings = array(
    'jPlayer' => array(
      'swfPath' => base_path() . variable_get('jplayer_directory', 'sites/all/libraries/jplayer'),
      'showHour' => (boolean)variable_get('jplayer_showHour', FALSE),
      'showMin' => (boolean)variable_get('jplayer_showMin', TRUE),
      'showSec' => (boolean)variable_get('jplayer_showSec', TRUE),
      'padHour' => (boolean)variable_get('jplayer_padHour', FALSE),
      'padMin' => (boolean)variable_get('jplayer_padMin', TRUE),
      'padSec' => (boolean)variable_get('jplayer_padSec', TRUE),
      'sepHour' => variable_get('jplayer_sepHour', ':'),
      'sepMin' => variable_get('jplayer_sepMin', ':'),
      'sepSec' => variable_get('jplayer_sepSec', ''),
    ),
  );


$vars = array('items' => $items, 'settings' => $settings);


theme('jplayer', $vars);

return;

}
Frando’s picture

Here's how I display a jPlayer with the patch above:

$vars = array();

$vars['items'][] = array(
    'url' => 'http://example.org/my_song.mp3',
    'ext' => 'mp3',
    'type' => 'audio',
    'label' => 'Some music',
);

$vars['settings'] = array(
    'mode' => 'single',
    'solution' => 'html, flash',
    'preload' => 'none',
    'volume' => 100,
    'muted' => FALSE,
    'autoplay' => FALSE,
    'repeat' => FALSE,
    'continuous' => FALSE,
    'backgroundColor' => '#fff',
    'progressBar' => FALSE,
);

$element['player']['#markup'] = theme('jplayer', $vars);
tripper54’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Really useful patch, RTBC!