Maybe someone can help me with this. I'm trying to get jPlayer to work with Media module and I'm almost there I think. My problem appears in nr 3 in the list below and consist of not being able to update and save the jPlayer Playlist instance..

Important! To use jPlayer with Media I had to change "$object->nid" to "$object->fid" on line 96 in the jplayer.module.

This is how I set it up:

  1. Create a content type (playlist) and add a Multimedia asset field. In the new field set "Allowed media types" to Audio and "Number of values" to Unlimited.
  2. In Configuration » Media » Media Types » Audio media type settings » Manage display: select the Large display and set the formatter to jPlayer-Player (the Small display I use for the Single Player)
  3. Then in the jPlayer-Player format setting (icon to the right) I want to change the instance to Playlist jPlayer instance. But when I hit the Update button the format is still Single jPlayer instance.
  4. Create a view and filter the playlist content type. Settings: Format - Format:Unformatted list, Show:Fields. Fields - Add field Content: Media. Configure the Media field and set the formatter to Large and the "Multiple fields settings" to Display all values in the same row and "Display type" to Simple separator.
  5. Upload some songs to the playlist and hit the Save button.

Everything is now working besides the view is showing a list of single players instead of a playlist with a list of songs.

CommentFileSizeAuthor
#7 media_file_playlist.jpg23.92 KBdellis

Comments

dreadlocks1221’s picture

subscribing, very interested in seeing this work

tike012’s picture

subscribing.

yugongtian’s picture

Category: support » bug

Playlist jPlayer instance. But when I hit the Update button the format is still Single jPlayer instance.
Yes , I think it's bug.....
Same problem ,can not play playlist.

yugongtian’s picture

Category: bug » support

Sorry Mistake.
+1

btmash’s picture

I get the same issue. The way I resolved it was by doing things at the template layer for the field. So I'm curious to see what might be a good way to go about working this out.

dellis’s picture

the nid -> fid code change lets the module function, however the field-display formatter (jplayer) doesn't show up as an option on the manage display page of the content type configuration screen.

You can do this through the various round-about steps you have taken, but it does seem to break down at the rendering of the multiple-valued field in a playlist. I think because we are selecting "file style: large" or whatever, it is treating each value separately rather than aggregating or building the array at the field-level.

Is there any way to enable the jplayer-* field formatters for the "Multimedia Asset" field type (rather than just for the filefield type)? Would that solve the problem?

dellis’s picture

StatusFileSize
new23.92 KB

Updating to Media 7.x-2.x. and using the "file field" instead of the "media field" allows this module to work out of the box! The solution below works for "media field" types

Okay! So I have a solution for using the media module (with "Media Field") and JPlayer--so far I've tested it with Audio files and it is working quite nicely!
Using Media 7.x-2.x-dev, though still using a "media" field (multimedia asset widget) which is set to accept unlimited values.

Here is what you do:

  • Because this is not part of the module, you'll need to install another one (Custom Formatters) that allows you to write custom field formatters (without writing a custom module) and is very very slick.
  • Add a new custom formatter, and use this code in php format (As is, without the php tags):
    // fieldname is added to the jplayer-themed div dynamically so that we can have multiple players (from multiple media fields) on a page
    $fieldname = $variables['#field']['field_name'];
    
    foreach (element_children($variables['#items']) as $delta) {
      $item = $variables['#items'][$delta];
      // $newitem reformats $item into the structure that the JPlayer module is looking for
      $newitem[$delta]['file'] = $item['file']->filename;
      $newitem[$delta]['url'] = $item['file']->uri;
      $newitem[$delta]['type'] = $item['file']->type;
      // clean up html spaces in the filename for the display in the playlist
      $newitem[$delta]['label'] = str_replace("%20"," ",$item['file']->filename);
      // determine file extension
        $file_ext = $item['file']->filename;
        $file_ext = substr($file_ext, strrpos($file_ext, ".")+1);
      $newitem[$delta]['ext'] = $file_ext;
     }
    
     // Settings for the JPlayer instance
     // should really be dynamically put into the module file--but this depends on allowing for the creation of new formatter names (which I don't think is currently an option)
       $display['settings']['mode'] = 'playlist';
       $display['settings']['autoplay'] = '1';
       $display['settings']['solution'] = 'html, flash';
       $display['settings']['preload'] = 'auto';
       $display['settings']['volume'] = '80';
       $display['settings']['muted'] = FALSE;
       $display['settings']['repeat'] = 'none';
       $display['settings']['backgroundColor'] = '';
    
      // theme function to display player + playlist
      $output = theme('jplayer', array('player_id' => 'jplayer-'. $fieldname . '-' . str_replace('_', '-', $instance['field_name']), 'items' => $newitem, 'settings' => $display['settings']));
      return $output; 
    
  • Go to the manage display page of your media-field-containing content type, and under the field format dropdown, select the new one you just created, save, then view a node!

There may be an easier way to do this, but I couldn't find one--and there are likely things that could be done better in the above code, but it works for now. I've attached a screenshot of the working formatter (it looks like the regular non-multivalued playlist).

Also, it occurs to me that you could do a count to see whether there are multiple audio files or not in order to dynamically switch between "single" and "playlist" (even though I know this isn't clean/good coding):

 if($count > 1){
  $mode = 'playlist';
} else {
  $mode = 'single';
}
 $display['settings']['mode'] = $mode;

I hope this helps someone else until the module gets updated/patched!

dellis’s picture

small tweak to the "out of the box" statement... I had 2 fields, an audio_file (using jplayer) and a video_file (using something else because of youtube/remote oembed files) on the same content type.

When viewing a node created this way, this module seems to look at all available media "files" and consider them fair game for rendering or at least processing. I had errors related to missing player_type and filename and still had a problem with the $object->fid (or nid) in line 96. Likely because the videos were remote URLs without file extensions or "filenames" in the strict sense.

So... in jplayer.theme.inc:
- I added to line 108:
$player_type = '';

- and to line 127 (just before setting $item['label'] = $item['filename']):
$item['label'] = '';

- and for good measure, added a line after 128 to clean up some html spaces issues I was having in filenames:
$item['label'] = str_replace("%20"," ",$item['label']);

I also ended up changing the jplayer.module's player div's id to (line 96):
'player_id' => 'jplayer-' . $instance['field_name'] . '-' . str_replace('_', '-', $instance['field_name']),

where $instance['field_name'] replaced $object->nid or $object->fid

I realize that "hacking" a module's files is not a good idea, these are some changes that may not be "correct" but they do work for me so far (especially since it has been 6 months since the last update).

deviantintegral’s picture

Category: support » feature
rob c’s picture

I got Media: Soundcloud 7.x-2.x 'tracks' to work with jPlayer. (and it's awesome!)

I added a bit more then $wrapper = file_stream_wrapper_get_instance_by_uri($item['uri']); but that is where the magic happens. I'll upload everything to my github, for everybody to test. At this moment it's not yet a real patch or even close to it, but it might help a bit. You need to register for an api key (app) at Soundcloud before it will work and set the display to the jPlayer and disable the normal rendering.

https://github.com/ClusterFCK/jplayer
https://github.com/ClusterFCK/media_soundcloud
See https://github.com/ClusterFCK/jplayer/blob/master/includes/jplayer.theme... for more details.

candelas’s picture

I am looking for an audio player for the media 7-2.x module. I don't find an issue that is from last months, so I ask here for support. Thanks for any tip :)