I am trying to setup jplayer in views, I set it up as a block and on page and I get:

Notice: Undefined index: extension in jplayer_sort_files() (line 119 of PATHTO/modules/jplayer/includes/jplayer.theme.inc).
Notice: Undefined index: type in jplayer_sort_files() (line 164 of PATHTO/modules/jplayer/includes/jplayer.theme.inc).
Notice: Undefined index: type in jplayer_sort_files() (line 170 of PATHTO/modules/jplayer/includes/jplayer.theme.inc).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dreadlocks1221’s picture

I managed to get the above error fixed by setting the field style to jplayer and the format to unformatted list, however the player doesnt work in opera 11.01

vinsabus’s picture

Not sure if this is the same error. I have a content type where I have assigned a file field to use jplayer. There is no problem on nodes where there is data in the field, but if the field is blank then I get this notice:

Notice: Undefined variable: player_type in jplayer_sort_files() (line 188 of /Volumes/Data/Users/vinsab/Sites/feral/sites/all/modules/jplayer/includes/jplayer.theme.inc).

At line 150 of includes/jplayer.theme.inc, Adding the following made the error disappear.

$player_type = '';
prakash.yerneni’s picture

Assigned: Unassigned » prakash.yerneni
prakash.yerneni’s picture

Notice: Undefined index: type in jplayer_sort_files()

prakash.yerneni’s picture

Issue tags: +jplayer
prakash.yerneni’s picture

yugongtian’s picture

+1 same error
Notice: Undefined index: type in jplayer_sort_files() (line 164 of E:\wamp\www\test17\sites\all\modules\jplayer\includes\jplayer.theme.inc).
Notice: Undefined index: type in jplayer_sort_files() (line 170 of E:\wamp\www\test17\sites\all\modules\jplayer\includes\jplayer.theme.inc).

yugongtian’s picture

Find the error .

The field have png or jpg type image file.
can't know type 164 line "audio" or 170 "video" file type index.

How to fix it? I try it like this

Edit the views Filter criteria ,add file - name - contains -{ (file) file: name (contains mp3)}

It works.

But it can only show *mp3 name file ,
I do not know how to add other m4a (AAC), m4v (H.264), ogv*, oga*, wav*, webm* type
work together .....

So any idea ?
Thanks.

Sorry for my English.

dreadlocks1221’s picture

this seems like a separate issue, please don't hijack the thread

dr. gubó’s picture

Got the same error, added $player_type = ''; just before line 180 in modules/includes/jplayer.theme.inc made the error disappear.

dr. gubó’s picture

Sorry, I just discovered the "fix" I mentioned breaks the player display.

batje’s picture

Status: Active » Reviewed & tested by the community

The solution from comment #2 worked for me.

ajm8372’s picture

Solution from comment #2 seems to work for me as well.

rengomez’s picture

Hi - if you follow comment #2 then where do you add $player_type = '';. Is it before or after:
$num = 0;
foreach ($media as $file) {
if ($videos == TRUE && $type != 'playlist') {
if ($file['type'] == 'audio') {
unset($file);
}
$player_type = 'video';
}
else if ($videos == TRUE && $type == 'playlist') {
$player_type = 'video';
}
else {
$player_type = 'audio';
}

Also, solution / comment #1 worked fine for me.

Thanks

VM’s picture

#14 according to #2 you add it "At line 150"

deviantintegral’s picture

Title: Jplayer Error » Undefined index in jplayer_sort_files()
Assigned: prakash.yerneni » Unassigned
Status: Reviewed & tested by the community » Needs work
Issue tags: -jplayer

This issue needs a patch.

brycesenz’s picture

The patch is #2 is appropriate, but does not address the issue in all cases (at least, it didn't resolve the issue for me). I've come across two common uses for jPlayer + Views:

Use Case 1) Create a view of content nodes (each of which has an mp3 as a filefield), with the intention of turning each node's filefield into a jPlayer instance.

In this case, if a node does not have content attached, you may see the errors described here, and the fix in #2 resolves the issue. For this to work, I think you also need the field's display to be set as 'jPlayer' but the views display set as 'Unformatted Content'. In this use case, the views items go through the function "template_preprocess_jplayer()", and everything then works well when that function calls "jplayer_sort_files()"

Use Case 2) Create a view of content nodes (each of which has an mp3 as a filefield), with the intention of creating one jPlayer instance to play all of the files as a playlist.

In this case, due to a difference in the fields of the $raw_files variable compared to case #1, errors abound. The fields that you've select are passed to "jplayer_sort_files()" through the function "template_preprocess_jplayer_view_playlist()", and the arrays passed are in an unexpected format.

I'm not 100% sure that use case 2 was ever intended to be supported by this module, but it seems like a feature many would want. I'm trying to figure out how to fix the module to support this, and I'll post back when I have a patch.

brycesenz’s picture

Status: Needs work » Needs review

Ok, I fixed the issue for my second use case, but it required changing some code whose initial setup I don't quite understand.

Original Code (jplayer_style_plugin.inc, line 104):

    foreach ($sets as $title => $records) {
      foreach ($records as $row_index => $row) {
        $filepath = NULL;
        foreach ($this->options['path_field'] as $field_name) {
          if (isset($row->{$fields[$field_name]->field_alias})) {
            $filepath = $row->{$fields[$field_name]->field_alias};
            break;
          }
        }

        $this->view->row_index = $row_index;
        $label = trim(strip_tags($this->row_plugin->render($row)));
        if (empty($label)) {
          $label = basename($filepath);
        }

        $items[] = $row->{$full_field_name}[0]['raw'];        
      }
    }

Code With My Edits

    foreach ($sets as $title => $records) {
      foreach ($records as $row_index => $row) {
        $filepath = NULL;
        foreach ($this->options['path_field'] as $field_name) {
          if (isset($row->{$fields[$field_name]->field_alias})) {
            $filepath = $row->{$fields[$field_name]->field_alias};
            //My Addition
            $full_field_name = 'field_' . $field_name;
            break;
          }
        }

        $this->view->row_index = $row_index;
        $label = trim(strip_tags($this->row_plugin->render($row)));
        if (empty($label)) {
          $label = basename($filepath);
        }

//        $items[] = array(
//          'url' => file_create_url($filepath),
//          'label' => $label,
//        );
        //My Addition
        $items[] = $row->{$full_field_name}[0]['raw'];
      }
    }

With this change, the $items array stores content fields in a format that the jPlayer views style plugin can read as a playlist. But I still don't know if the original $items array format (with 'url' and 'label') existed for another use case. If that is true, my changes would break one use for the sake of another.


Can one of the committers comment on this? I need more context in order to provide a patch which I know won't break existing functionality.

deviantintegral’s picture

Status: Needs review » Needs work

jplayer_sort_files() looks to be expecting a few keys in $raw_files, including 'uri', and 'description'. So, I'm a little surprised your changes are working for you.

Part of the confusion is that jplayer_sort_files() isn't really documented well. It'd also be useful to have an exported feature that contains a few views for testing.

brycesenz’s picture

@deviantintegral -

The problem is the jplayer_sort_files is expecting those keys in $raw_files, but they aren't there when using jPlayer as a views format (trying to display an entire view as a single jPlayer). That's why my code fixes, though I'm not sure at what expense.

For debugging purposes and to recreate the issue, do the following:

- Install and enable the Devel module, so we can print arrays easily
- Create 2-3 demo nodes with a filefield set to display as a jPlayer instance
- Create a demo view (view_1) that displays the above nodes as an unformatted list with each node's filefield displayed as a jPlayer
- Create a demo view (view_2) that displays each node's filefield as a Generic file, but uses the views format jPlayer.
- On line 108 of jplayer.theme.inc (before the loop in jplayer_sort_files()), add the line dpm($raw_files);

In the first two cases, the node view and view_1, the $raw_files array contains all of the information we need from the file - fid, uri, filename, description, etc. In these cases, jplayer_sort_files() is being called from 'template_preprocess_jplayer()', which I believe runs before a single field instance is viewd as a jPlayer.

In the last case, view_2, the preprocess function is 'template_preprocess_jplayer_view_playlist()'. This function calls jplayer_sort_files() as well, but when it does, the rendered array only contains two fields - url and label, so we get a bunch of errors.

In jplayer_style_plugin.inc, you created the render() function that only returns these two fields ('url' and 'label'), but I don't know why. My code above changes the return values to create the array that jplayer_sort_files() is looking for, but I don't know what else it might break. My question is - why did you want render() to only return those fields?

I haven't run into problems with my altered code, but since I don't know the logic behind your render() function, I don't know what problems I might have created.

vladimir_e’s picture

Ran into this when trying to make a single player instance playlist out of node fields.

Change in #18 fixes the issue for me.

flypp’s picture

@brycesenz, thanks for your code.Works perfectly but i was getting a lot of "Undefinet offset" and "Undefined index" messages.

I'm using jplayer-7.x-2.x-f8e7f32 (snapshot), and I added a little modifications:

jplayer.theme.inc

  // Look through all the files provided and see what we have
  foreach ($raw_files as $delta => $item) {

    // Get file URL
    if (!isset($item['url'])) {
      $item['url'] = file_create_url($item['uri']);
    }

    // Get file extension
    if (!isset($item['ext'])) {

      $fileinfo = pathinfo($item['url']);
      $item['ext'] = $fileinfo['extension'];
      
    }

    // Get file label
    if (!isset($item['label'])) {
    	// Must check if descrition is set 
    	if (isset($item['description'])) {
      if (empty($item['description'])) {

        $item['label'] = $item['filename'];
      }
      else {
        $item['label'] = $item['description'];
      }
    }
    }

    // Add file into correct group
    if (in_array($item['ext'], $video_extensions)) {
      $videos = TRUE;
      $item['type'] = 'audio';
    }
    elseif (in_array($item['ext'], $audio_extensions)) {
      $audio = TRUE;
      $item['type'] = 'video';
    }
    elseif (in_array($item['ext'], $poster_extensions)) {
      $poster = $item['url'];
      $item['type'] = 'poster';
    }

	// it looks like this line adds to $media elements of $item.
	// Problem: $item contains items with "filename" empty
	// If "filename" is not set, $item must not be added to $media
	if (isset($item['filename'])) {
    	$media[] = $item;
    }
  }

jplayer_style_plugin.inc

   foreach ($sets as $title => $records) {
      foreach ($records as $row_index => $row) {
        $filepath = NULL;
        foreach ($this->options['path_field'] as $field_name) {
          if (isset($row->{$fields[$field_name]->field_alias})) {
            $filepath = $row->{$fields[$field_name]->field_alias};
            // http://drupal.org/node/1111510
            $full_field_name = 'field_' . $field_name;
            break;
          }
        }

        $this->view->row_index = $row_index;
        $label = trim(strip_tags($this->row_plugin->render($row)));
        if (empty($label)) {
          $label = basename($filepath);
        }

		//comented
        //$items[] = array(
        //  'url' => file_create_url($filepath),
        //  'label' => $label,
        //);

        // added
        // Must check first if raw is set
        if (isset($row->{$full_field_name}[0]['raw'])) {
        	$items[] = $row->{$full_field_name}[0]['raw'];
        	}

      }
    }

    $output = theme('jplayer_view_playlist', array('view' => $view, 'items' => $items));

    // If doing a live preview, add the JavaScript directly to the output.
    if (isset($view->live_preview) && $view->live_preview) {
      $js = drupal_add_js(JS_DEFAULT);
      $settings = array();

      // ($js['setting'] -> Added an "s" 
      foreach ($js['settings'] as $js_settings) {
        if (isset($js_settings['jPlayer'])) {
          $settings = $js_settings['jPlayer'];
          break;
        }
      }
b.one’s picture

thanks brycesenz for your patch @ #18, it works perfectly on Chrome and Internet Explorer, but not on Firefox...

anyone knows how to fix this issue ?

dreadlocks1221’s picture

if it doesn't work in firefox, path to swf isnt set properly

drew reece’s picture

I'm seeing this issue with a view showing multiple items with a file field, the goal is to show one jPlayer using multiple fields.
#18 didn't work - I got repeated undefined index errors as mentioned by flypp in #22

#22 worked but the audio fields without descriptions threw errors because of undefined labels.
I tweaked flypp's logic to set the description to the filename & now it works for my view.

This patch is for the 7.x-2.x it is flypp's code with the description fix.

brycesenz’s picture

@drew reece -

100 points for providing a patch, but the real issue here is that a bunch of us are trying to use the module in slightly different ways and each use case requires its own patches so far.

My patch in #18 for example solved my problem perfectly. The patch in #22 actually broke functionality for me, but it seems to have fixed the problem for others. I'm sure still many are using the module fine without any patch at all, due to other implementations.

My worry is that without direction from the module owner, we'll all keep submitting patches that work for us but break the module for others.

drew reece’s picture

@brycesenz,

Cheers, I agree with you I was just happy to find a fix & #22 seems to be the one for my use case. I couldn't get #18 working since the latest code is different to the example replacement part.

I also find that Firefox (3.3 Mac) doesn't work with the multi-field views based player, I get the html themed player with no request errors. The play button doesn't start the tracks & the file link connects to the track to get the built in media player on a new page.

I think there is a fair way to go with this module, hopefully the someone is following along.
What are the alternatives for playlists in D7?

brycesenz’s picture

@drew reece -

As of right now, the best I've found for playlists is MediaFront (http://drupal.org/project/mediafront) in conjunction with the media module. There's also a different front end player that looks really nice called JWPlayer (http://drupal.org/project/jw_player), but it doesn't have great playlist functionality at this point.

drew reece’s picture

Cheers,

That is the conclusion I was coming to. MediaFront didn't work for me a few months ago, but now it seems fine. I'll go with it until this gets resolved.

brycesenz’s picture

Sorry, just looking over the code in #22 - does this block of code seem wrong to anyone else?

    // Add file into correct group
    if (in_array($item['ext'], $video_extensions)) {
      $videos = TRUE;
      $item['type'] = 'audio';
    }
    elseif (in_array($item['ext'], $audio_extensions)) {
      $audio = TRUE;
      $item['type'] = 'video';
    }

Why would we check and array called '$video_extensions' and then set the type to 'audio' and vice versa?

drzraf’s picture

gardy’s picture

This code works for me, but it handels only one file per node. Here is the solution for this problem.

Use this:

	for ($i=0; $i<=sizeof($row->{$full_field_name}); $i++){
		        if (isset($row->{$full_field_name}[$i]['raw'])) {
			 	$items[] = $row->{$full_field_name}[$i]['raw'];
		        }		
	}

Instead of this:

+        if (isset($row->{$full_field_name}[0]['raw'])) {
+          $items[] = $row->{$full_field_name}[0]['raw'];
+        }
nordex’s picture

For me this error accured when i tried to upload a file type that was not recognised by the jplayer module.

in the fieldtype i had added mp4, flv but the jplayer script under the jplayer_sort_files() function of modules/jplayer/includes/jplayer.theme.inc this is what i found in the file.
$video_extensions = array('m4v', 'mp4', 'ogv', 'webmv');

Thus it errored on me becaus it did not know of flv files. So i added flv to that list on that so it looks like this.
$video_extensions = array('m4v', 'mp4', 'ogv', 'webmv', 'flv');

After that i got the player working with a playlist of videos i had uploaded.

I hope this helps someone.

BDaggerhart’s picture

I'm getting the same error:

Notice: Undefined index: extension in jplayer_sort_files() (line 123 of /var/www/devsite/sites/all/modules/jplayer/includes/jplayer.theme.inc).
Notice: Undefined index: extension in jplayer_sort_files() (line 123 of /var/www/devsite/sites/all/modules/jplayer/includes/jplayer.theme.inc).
Notice: Undefined index: type in jplayer_sort_files() (line 169 of /var/www/devsite/sites/all/modules/jplayer/includes/jplayer.theme.inc).
Notice: Undefined index: type in jplayer_sort_files() (line 175 of /var/www/devsite/sites/all/modules/jplayer/includes/jplayer.theme.inc).
Notice: Undefined index: type in jplayer_sort_files() (line 169 of /var/www/devsite/sites/all/modules/jplayer/includes/jplayer.theme.inc).
Notice: Undefined index: type in jplayer_sort_files() (line 175 of /var/www/devsite/sites/all/modules/jplayer/includes/jplayer.theme.inc).

The files work perfectly fine when I create the node for the audio files, but when I try to create the jplayer playlist view, I get the errors above. I've read through the entire thread here and tried several of the patches, but nothing seems to work. Is there any sort of fix for this yet?

BDaggerhart’s picture

Is anything happening with this, or should we be looking for other options for playlists?

Jonathan Lauer’s picture

I'm getting the same error too !

Notice : Undefined index: type dans jplayer_sort_files() (ligne 170 dans /mysitename/sites/all/modules/jplayer/includes/jplayer.theme.inc).

For the same version of jplayer module (7.x-2.0-beta1) on 2 differing sites, only one of them works fine ! It's ok on my experimental site, but on the real site it doesn't work !!! why ?

No help from maintainer since march ?
Anyone have a solution? new Ishmayl ?

phrequency’s picture

I was getting the same error with this set up:
Content Type with CCK File Field.
Created node of this type with MP3 in the file field.
WHAT WAS WRONG:
Created a BLOCK view with:
Format: JPlayer | Show: Fields
Fields: Audio Field (The name of my field, yours will be the cck field you created)
Filters: My content type (yours will be different), NID: The id of this one node which I needed for my set up and of course Published: Yes

Saved all this, added the block to my page and got the above referenced error from OP.

THE FIX:
When creating my view, I assumed I wanted Format: JPlayer but in reality you just need to set Format to Unformatted or Formatted Lists.
Then in the fields, add your audio field but this time choose JPLayer as the format for the field itself.
This outputs a nice little jplayer with no errors.

I am not sure if this addresses the other issues being discussed here but after I did this, it made more sense that this was the correct set up.

tuananh3988’s picture

i same error, i use extension MP3.
i change extension to mp3 and use version 7.x-2.x-dev. it work for me

chunty’s picture

I got the same error when trying to use amazon s3 storage with signed URL's because line 144

<?php
 $item['ext'] = $fileinfo['extension'];
?>

gives something like "mp3?AWSAccessKeyId=AKIAJVCQPWR7GUONIMXQ&Expires=1387294109&Signature=FDCq4WGF07cLLQ6PJZPVNrUafbQ%3D" as the extension of the file type

kraigory’s picture

Issue summary: View changes
FileSize
941 bytes

I also have this error and it is caused by using the all-caps extension MP3. Rather than trying to enforce lowercase "mp3" usage, I created a patch that will allow both. Note, the patch is off the 7.x-2.x branch. It simply performs a strtolower on the extension before trying to assign a "file type".

stefan_seefeld’s picture

What is the status of this issue ? The last release of the jplayer module is still 7.x-2.0-beta1 from 2012-05-25. Does this incorporate any of the above patches ?
I do observe the "Undefined index..." error trying use-case 2 above, i.e. a playlist of audio files displayed through a single jplayer instance, and would *really* like to get this working, even if I have to apply a few patches manually.

Many thanks for any help,
Stefan

VM’s picture

None of the patches above have been rolled into any release.

  • kraigory authored 44c1c7f on 7.x-2.x
    Issue #1111510 by drew reece, kraigory: Undefined index in...
markie’s picture

Status: Needs work » Fixed

All
Thanks for your patience on this. I have committed this patch (with a minor change) into the dev branch. Will be creating a beta2 release soon.

markie

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.