I just installed jplayer (Drupal module and jplayer itself), and it is working except that I am getting this error message:

Notice: Undefined variable: player_type in jplayer_sort_files() (line 187 of /var/www/html/dev.thestoryofjesus.org/sites/all/modules/jplayer/includes/jplayer.theme.inc).

Is this a configuration problem on my end or is something actually broken? Thanks for your help.

Bill

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

glass.dimly’s picture

Same problem here. The problem is that the variable $player_type is out of scope and then is not accessible out of the foreach loop.

I've got a patch which fixes which I'm branching with git. First time so let me know how this works for you.

glass.dimly’s picture

Status: Active » Needs review
FileSize
784 bytes

Still figuring out git, I've added the patch to git but I'm also attaching it here. Let me know how I can do this better next time.

Emkas’s picture

In my case this little patch (http://drupal.org/node/1192826#comment-4645450) fixed the problem. Thx.

offal’s picture

Which little patch? The link points to this self-same page?

Edit - oh, I see - the patch above in post #2! Sorry.

So, what do I do with that code? Where do I put it?

bhosmer’s picture

You need to use git to apply the patch.

CD into your modules directory and clone the jplayer repo first.

Depending on your configuration, wget http://drupal.org/files/issues/var_player_type_out_of_scope-1192826-4645...
and then git apply < var_player_type_out_of_scope-1192826-4645428.patch

tbayens’s picture

I am quite new to Drupal, what is this, wget and git apply people are talking about? Is there a way to just apply the patch without that? I did it before with some other module and just edited the code in the inc file, but I did not get that to work here.
Maybe I am missing something? I am working on this website: http:/www.thomasbayens.nl and even if I have the playlist option selected, it gives me an individual player for each song, which obviously isn't what I want...

But when I change the view from an unformatted list to the jplayer it just gives me these errors and messes up the player:

Notice: Undefined index: extension in jplayer_sort_files() (line 119 of /home/tbayen/domains/thomasbayens.nl/public_html/sites/all/modules/jplayer/includes/jplayer.theme.inc).
Notice: Undefined index: extension in jplayer_sort_files() (line 119 of /home/tbayen/domains/thomasbayens.nl/public_html/sites/all/modules/jplayer/includes/jplayer.theme.inc).
Notice: Undefined index: type in jplayer_sort_files() (line 164 of /home/tbayen/domains/thomasbayens.nl/public_html/sites/all/modules/jplayer/includes/jplayer.theme.inc).
Notice: Undefined index: type in jplayer_sort_files() (line 170 of /home/tbayen/domains/thomasbayens.nl/public_html/sites/all/modules/jplayer/includes/jplayer.theme.inc).
Notice: Undefined index: type in jplayer_sort_files() (line 164 of /home/tbayen/domains/thomasbayens.nl/public_html/sites/all/modules/jplayer/includes/jplayer.theme.inc).
Notice: Undefined index: type in jplayer_sort_files() (line 170 of /home/tbayen/domains/thomasbayens.nl/public_html/sites/all/modules/jplayer/includes/jplayer.theme.inc).

What am I supposed to do now :(

bhosmer’s picture

Git is the version control system that Drupal.org uses. It makes it very easy to apply changes and patches to modules and code.

wget is a command-line utility for downloading things like patches and files. It depends on your server configuration. You might have wget or you might have curl, or you may not have access at all to a command-line and you will have to use FTP to get the patch.

This is what you would type from the command-line to get and then apply the patch:

Depending on your configuration, wget http://drupal.org/files/issues/var_player_type_out_of_scope-1192826-4645...
and then git apply < var_player_type_out_of_scope-1192826-4645428.patch

Edit: For git to work, you will need to clone the jplayer git repository first.

Uninstall your current jplayer and delete the directory. Then follow the Git Instructions first to get the git repository in your /modules directory. This copies the jplayer git repository and will add the module for you.

jeremyvanlanda’s picture

Applied patch in #2 and cleared cache but still receive these errors:

Notice: Undefined index: extension in jplayer_sort_files() (line 119 of /public_html/projects/barefoot/sites/all/modules/jplayer/includes/jplayer.theme.inc).
Notice: Undefined index: type in jplayer_sort_files() (line 162 of /public_html/projects/barefoot/sites/all/modules/jplayer/includes/jplayer.theme.inc).
Notice: Undefined index: type in jplayer_sort_files() (line 168 of /public_html/projects/barefoot/sites/all/modules/jplayer/includes/jplayer.theme.inc).

tvilms’s picture

I applied the patch and I'm still having the same errors. I've got a view with a jPlayer format. I'm convinced I'm passing an array of files properly. I've been inspecting the jplayer_sort_files() function. There's something sloppy going on in there. I can't quite tell. I think this is rooted in line 199, can't tell for sure.

rivimey’s picture

I'm having this prob too. Adding $player_type = 'audio'; before the first loop fixed it once I cleared the cache.

I did notice that the code of jplayer_sort_files() just after the comment "Add File into correct group" would appear incorrect: if the file extension appears in the video_extensions array, it's tagged as audio, and if in audio_extensions it's tagged as video.

rivimey’s picture

I attach a patch to 7.x-2.x that adds a few pertinent comments and clarifies the code of the second "foreach" in this function. It also swaps the file type detection code to make sense again.

Hope it's helpful.

deviantintegral’s picture

There were a few issues with comment style and tabs that I fixed from the patch in #11. I haven't actually seen this error myself, so it'd be good if someone could confirm this patch works.

BenStallings’s picture

Status: Needs review » Reviewed & tested by the community

I can confirm that the patch in #12 gets rid of the error.

jh3’s picture

The patch in #12 did the job. The notice is gone.

davapiano’s picture

I applied the patch in #12 but still got the error:

Notice: Undefined index: extension i jplayer_sort_files() (rad 124 av .../jplayer/includes/jplayer.theme.inc).
Notice: Undefined index: type i jplayer_sort_files() (rad 178 av .../jplayer/includes/jplayer.theme.inc).
Notice: Undefined index: type i jplayer_sort_files() (rad 184 av .../jplayer/includes/jplayer.theme.inc).

Beside the error message the player works as expected.

rlmumford’s picture

Can confirm that patch #12 fixes the error however I'm re rolling due to a white space error line 77.

Z2222’s picture

I was having trouble applying the patch. Is this patch better than the simple solution here?
http://drupal.org/node/1294692

The other method worked for me (at least until the module is updated).

scito’s picture

I marked #1294692: Notice: Undefined variable: player_type in jplayer_sort_files() as duplicate.

@J. Cohen: The patch fixes also other problems.

Quick code review:

+++ b/includes/jplayer.theme.inc
@@ -148,19 +149,28 @@ function jplayer_sort_files($raw_files = array(), $player_id, $type = 'single')
+      }
+      else /* single */ {
+	if ($file['type'] == 'audio') {
+	  unset($file);
+	}
+	$player_type = 'video';
       }
-      $player_type = 'video';

Tabs are used instead of spaces.

scito’s picture

I could not apply patch of #16. I've got:
fatal: corrupt patch at line 81

I could not figure out what the problem is.

I've taken patch of #12, fixed whitespace problems and rerolled it.

The error message disappeared with this patch.

amontero’s picture

Same as scito.

Patch #12 gives me the same error.
Applied scito's patch successfully and error has gone.

nikosnikos’s picture

I also applied patch #19 successfully. Thanks.

matthewdolman’s picture

When I apply this patch all of my views of display type page now display an empty player.

beetlewing’s picture

I was having similar issues:

Notice: Undefined index: type in jplayer_sort_files() (line 168 of .../sites/all/modules/jplayer/includes/jplayer.theme.inc).

...and I think the other one was line 172.

Turns out, it was simply because my song's file extension was MP3, not mp3. Appears it's case sensitive.
I tried to add MP3 in the code, but that didn't work. Was just easier to rename my file to lowercase mp3.

Maybe this will help someone else.

deviantintegral’s picture

Status: Reviewed & tested by the community » Needs work

@matthewdolman, can you post an export of your view? I'm not sure how this patch could cause an issue with Views.

Unless we can replicate that issue, the patch from #19 looks good to me.

webadpro’s picture

#19 did the trick for me too.

Roedelhorst’s picture

I got similar Issues:

Notice: Undefined index: type in jplayer_sort_files() (Zeile 168 von C:\xampp\htdocs\duosan\sites\all\modules\jplayer\includes\jplayer.theme.inc).
Notice: Undefined index: type in jplayer_sort_files() (Zeile 174 von C:\xampp\htdocs\duosan\sites\all\modules\jplayer\includes\jplayer.theme.inc).

mp3 files work pretty well, but when uploading .flv and .m4v I got this error message.
When looking at jplayer.theme.inc, I recognized, that in line 159, 162 and 165 $player_type is set, but is not used elsewhere. So I changed

line 168
if (isset($file) && $file['type'] == 'audio') {
to
if (isset($file) && $player_type = 'audio') {

and line 174
elseif (isset($file) && $file['type'] == 'video') {
to
elseif (isset($file) && $player_type = 'video') {

... this worked for me... No further error message.
I'm a real nerd in scripting, and I don't know if I really solved the problem. But since it worked for me, I thought I should post this here...

nickvidal’s picture

#26 worked for me. Thanks!

mrcniceguy’s picture

#26 also worked for me.
i changed $player_type = 'audio' to $player_type == 'audio'
just added the = mark

Anthony Pero’s picture

After applying patch at #19, I still get the following error messages on listing pages (not views, drupal core listing pages, like, the home page):

    Notice: Undefined index: type in jplayer_sort_files() (line 178 of /home8/anthoob7/public_html/paul-long/sites/all/modules/jplayer/includes/jplayer.theme.inc).
    Notice: Undefined index: type in jplayer_sort_files() (line 184 of /home8/anthoob7/public_html/paul-long/sites/all/modules/jplayer/includes/jplayer.theme.inc).
    Notice: Undefined index: type in jplayer_sort_files() (line 178 of /home8/anthoob7/public_html/paul-long/sites/all/modules/jplayer/includes/jplayer.theme.inc).
    Notice: Undefined index: type in jplayer_sort_files() (line 184 of /home8/anthoob7/public_html/paul-long/sites/all/modules/jplayer/includes/jplayer.theme.inc).
    Notice: Undefined index: type in jplayer_sort_files() (line 178 of /home8/anthoob7/public_html/paul-long/sites/all/modules/jplayer/includes/jplayer.theme.inc).
    Notice: Undefined index: type in jplayer_sort_files() (line 184 of /home8/anthoob7/public_html/paul-long/sites/all/modules/jplayer/includes/jplayer.theme.inc).
    Notice: Undefined index: type in jplayer_sort_files() (line 178 of /home8/anthoob7/public_html/paul-long/sites/all/modules/jplayer/includes/jplayer.theme.inc).
    Notice: Undefined index: type in jplayer_sort_files() (line 184 of /home8/anthoob7/public_html/paul-long/sites/all/modules/jplayer/includes/jplayer.theme.inc).
    Notice: Undefined index: type in jplayer_sort_files() (line 178 of /home8/anthoob7/public_html/paul-long/sites/all/modules/jplayer/includes/jplayer.theme.inc).
    Notice: Undefined index: type in jplayer_sort_files() (line 184 of /home8/anthoob7/public_html/paul-long/sites/all/modules/jplayer/includes/jplayer.theme.inc).
    Notice: Undefined index: type in jplayer_sort_files() (line 178 of /home8/anthoob7/public_html/paul-long/sites/all/modules/jplayer/includes/jplayer.theme.inc).
    Notice: Undefined index: type in jplayer_sort_files() (line 184 of /home8/anthoob7/public_html/paul-long/sites/all/modules/jplayer/includes/jplayer.theme.inc).
    Notice: Undefined index: type in jplayer_sort_files() (line 178 of /home8/anthoob7/public_html/paul-long/sites/all/modules/jplayer/includes/jplayer.theme.inc).
    Notice: Undefined index: type in jplayer_sort_files() (line 184 of /home8/anthoob7/public_html/paul-long/sites/all/modules/jplayer/includes/jplayer.theme.inc).
    Notice: Undefined index: type in jplayer_sort_files() (line 178 of /home8/anthoob7/public_html/paul-long/sites/all/modules/jplayer/includes/jplayer.theme.inc).
    Notice: Undefined index: type in jplayer_sort_files() (line 184 of /home8/anthoob7/public_html/paul-long/sites/all/modules/jplayer/includes/jplayer.theme.inc).
    Notice: Undefined index: type in jplayer_sort_files() (line 178 of /home8/anthoob7/public_html/paul-long/sites/all/modules/jplayer/includes/jplayer.theme.inc).
    Notice: Undefined index: type in jplayer_sort_files() (line 184 of /home8/anthoob7/public_html/paul-long/sites/all/modules/jplayer/includes/jplayer.theme.inc).

Any ideas? I'm going to delete the module entirely, reinstall it, and repatch it, and report back.

Anthony Pero’s picture

Actually, now that I'm thinking about, I realize that those nodes were created with the devel module. That's probably the issue. Gonna delete Devel nodes and make a few with real mp3 files.

Anthony Pero’s picture

Yeah, that's the issue, ignore me ;)

Funksmaname’s picture

I can confirm #19 worked for me also.

mrtoner’s picture

The patch in #19 applied, but didn't fix the problem for me. The suggestion in #26 took some of the errors away, but didn't correct the underlying problem in my situation.

As I debugged this, what I found is that jplayer_sort_files() is being provided an incorrect set of data in $raw_files. Each entry in the playlist looks like this:

(Array, 2 elements)
url (String, nn characters ) http://example.com/87
label (String, nn characters ) <title> <path to file> <body>

(I'm using jPlayer in a view, passing those fields in the label to the display. And Views is returning a list of nodes with audio files (mp3s).)

As I see it, that URI is wrong. jplayer_sort_files() is building a $media array and from that a $file array off of not the file, but the node that file belongs to. And even that URI is wrong: for the node it should be http://example.com/node/87

The "Notice: Undefined index: extension" errors are happening because there's no file at that location and no extension could then be set. (BTW, there's no check for incomplete data returned from path info().) And the "Notice: Undefined index: type" errors are happening because no filetype could be derived from the non-existent extension. (As Roedelhorst correctly points out, $player_type is defined but never used. Making the change he suggests eliminates the error but doesn't correct the underlying problem.)

BTW, I just re-read the original post and I see that error reported was for an undefined variable. I missed that earlier because I had searched on the undefined index error and came up with this issue. I'm sorry if my comment is out of context or off-topic.

vordude’s picture

I can confirm the issue.

Notice: Undefined index: type in jplayer_sort_files() (line 170 of /var/www/dev/7/sites/seven.local/modules/jplayer/includes/jplayer.theme.inc).
Notice: Undefined index: type in jplayer_sort_files() (line 176 of /var/www/dev/7/sites/seven.local/modules/jplayer/includes/jplayer.theme.inc).

But only if I upload a filetype that isn't in the audio, video, or poster allowed file extensions. (Which in my case was .ogg)

luco’s picture

FileSize
8.06 KB

here's a version of jplayer.theme.inc with all of the above changes applied.

just rename the file and add water ;)

lukio’s picture

patch #35 against 7.x-2.0-beta1

fdambrosio’s picture

Issue summary: View changes

Convert name file in lowercase fix it!

scurvy’s picture

I don't know what I'm doing, but I ended up with this problem, and the solutions so far didn't seem to be working.

In my investigation, the root of the problem is actually in jplayer_style_plugin.inc, on this line:

$filepath = $row->{$fields[$field_name]->field_alias};

In my case, $field_name was "audio_field" and its field alias was "nid". As a result, rather than a uri, $filepath was set to the node's nid.

This resulted in the Undefined index errors because it was processing a nid as if it were a uri.

I don't know what the right way to fix it is, but I was able to simulate a correct result in my case by changing the above line to:

$filepath = $row->{['field_field_audio_file']['0']}['0']['raw']['uri'];
markie’s picture

Status: Needs work » Closed (outdated)

jplayer-7.x-2.0 has been released. Please verify this is still an issue and open a new issue against that build or update this issue.

saikatewu@gmail.com’s picture

It's still happening. I installed jplayer-7.x-20. I'm trying to embed a video inside a wysiwyg field using media browser.