Hey guys

I am trying to use Jplayer with link fields. I want people to be able to link to audio files outside of my own website for audio previews however jplayer always defaults the base of the link back to the base of my files folder, I get the link but drupal thinks its a file in my files folder.

eg.

/files/http://www.archive.org/download/Various-NetlabelCoalitionVolume1/02.DrSj...

Is there anyway around this?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jimajamma’s picture

I've been looking at doing this, it's both trivial and nontrivial wrapped up in one, but I should have something in the next week or so. In the meantime, you might want to take a look at the emfield module (drupal.org/project/emfield) that embeds all kinds of external media files.

Jim

dww’s picture

Title: Default source directory for Jplayer » Support emfield and/or other off-site source locations
Category: bug » feature

Yeah, but it'd be nice to be able to use jPlayer with an emfield. I'm definitely interested in this, although I haven't started looking into the code yet (and probably won't have time in the near future).

dww’s picture

Assigned: Unassigned » dww
Status: Active » Needs review
FileSize
6.39 KB

This works fine for me with an emaudio field. I haven't tried with a regular filefield, but I'm pretty sure I didn't break anything. ;) I'm not much of a CCK hacker yet, so it's possible there are better/cleaner ways to do this. For example, inside jplayer_get_source_url() it didn't seem like it was possible to get the underlying field type of the element (e.g. filefield vs. emaudio) so it's a bit of a heuristic hack to find the right URL. Also, I'm not 100% sure of the security implications of using the raw URL from emaudio like this, I'd want to ponder that a bit more before I really advocated this should be committed. But, it's a start. I'd love to get feedback on this approach from the maintainers.

Thanks!
-Derek

jimajamma’s picture

I'm even more of a newb, but was looking at adding different handlers per field type to the jplayer_field_formatter_info() array, eg, setting 'field_types' to emaudio only and then calling a specific function for that, another for links, etc. But certainly checking things out internally the way you did it works great, too.

dww’s picture

Yeah, it seemed like it'd be a lot of duplicate code (and potentially more confusing UI) to have separate formatters. I thought it'd be better to just have a single formatter that was smart enough to figure out where your audio file lives, since 95% of the code is the same in all cases. But, I also assumed that the formatter would get more metadata about the field its formatting so it'd be cleaner and easier to figure out the right URL based on the field type. Maybe it does, and I just didn't see it in my various debugging explorations...

plach’s picture

Status: Needs review » Reviewed & tested by the community

The patch works flawlessly: I test it in "mixed mode" having an embedded audio and a file field in the same content type and everything behaved as expected. If we don't want to go on with design considerations I'd say this is good to go.

ju.ri’s picture

I have the same problem after trying to move audiofiles to Amazon S3, using the media mover module. After applying the above patch I still get wrong URLs.

andrewfn’s picture

This looks like a very valuable feature. The code looks good on an initial review but I will go through it again more carefully and do some testing.

deviantintegral’s picture

Version: 6.x-1.0-beta2 » 7.x-2.x-dev
Status: Reviewed & tested by the community » Needs work

Unfortunately this patch no longer applies to 6.x-1.x. Lets see about porting this to the D7 version and getting them both committed.

dww’s picture

Assigned: dww » Unassigned

Sadly, I have no time to re-write this now -- unassigning myself so no one gets the mistaken impression I'm working on this. ;)

That said, I'm still using this patch on a site I maintain, so I'm still keenly interested in seeing this make it in upstream. At some point I'll circle back to needing to spend more time with that site, and perhaps at that point I'll be able to port this. Meanwhile, if anyone else can get it done sooner, hurray for that.

Cheers,
-Derek

pwaterz’s picture

Assigned: Unassigned » pwaterz
Status: Needs work » Needs review
FileSize
3.81 KB

Here is the patch for drupal 7 jplayer. This patch adds support for use of a textfield or a link field.

deviantintegral’s picture

Status: Needs review » Needs work
+++ b/includes/jplayer.theme.inc
@@ -8,14 +8,15 @@
-  // Determine a unique player ID.
+   // Determine a unique player ID.

Extra change not needed.

+++ b/includes/jplayer.theme.inc
@@ -8,14 +8,15 @@
+  //Get the field info so we can figure out what type it is

Fix comment style.

+++ b/includes/jplayer.theme.inc
@@ -38,6 +39,7 @@ function template_preprocess_jplayer(&$vars) {
+

No-op change.

+++ b/includes/jplayer.theme.inc
@@ -96,7 +98,7 @@ function theme_jplayer_item_list($variables) {
+function jplayer_sort_files($raw_files = array(), $player_id, $type = 'single', $fiele_type = 'file') {

"fiele_type" should be "file_type". Perhaps a better name would be item type, since a url is not a file by definition? Also, good opportunity to add phpdoc @param and @return comments to this function.

+++ b/includes/jplayer.theme.inc
@@ -114,7 +116,17 @@ function jplayer_sort_files($raw_files = array(), $player_id, $type = 'single')
+        case 'link_field':
+          $item['url'] = $item['url'];

Why is this required, this assignment doesn't change the variable?

pwaterz’s picture

Here is a new patch. It may not be super perfect, but pretty close.

pwaterz’s picture

Status: Needs work » Needs review
pwaterz’s picture

Status: Needs review » Closed (fixed)