Hey All,
First off, let me STRESS that I am a big big newb here, akin to a monkey with a stick, banging at code until it works, but when I started looking at using jPlayer with views this morning, I noticed some odd behavior.
I created a quick and dirty view, the usual filtering on published and node type, putting in an mp3 field (as generic files), selecting jPlayer as the style, and sure enough, a playlist box showed up in live preview.
But...no dice, looked pretty, didn't work. Instead of yada/yada/yada.mp3, it was href'ing MYHOST/sites/default/files/##.
I dug into jplayer_style_plugin.inc and banged at it with that aforementioned stick for a while and found that it was putting a plain old fid into $filepath, which file_create_url() was then turning into MYHOST/sites/default/file/##, so I googled and grep'ed around trying to figure out how it lost the filename in the first place--couldn't figure that part out--so then how to get a filename from a fid in drupal and came up with this:
$jf = field_file_load($filepath);
and then using that when the url is created a couple lines later:
'url' => file_create_url($jf[filepath]),
And, voila, all works. My description shows up in the player and the mp3 file is played. I can change my field display format from Generic Files to Path to File or URL to file, and they work, too, just a bit uglier in presentation in my humble opinion.
Now.... while this does appear to have the added benefit of priming drupal's cache with your yet to be played mp3 files, I can't imagine this is the right way to do this. Or that something on my system fat fingered something else that caused this oddity in the first place...
Thoughts?
Jim
Comment | File | Size | Author |
---|---|---|---|
#8 | 919700.7-views-file-id.patch | 2.61 KB | deviantintegral |
#2 | jplayer_style_plugin.inc_.patch | 1.36 KB | heshanlk |
Comments
Comment #2
heshanlkHope this worked to fix that. I got the same issue when I create views and managed to fix using this patch.
Comment #3
davebv CreditAttribution: davebv commentedThanks @heshan.lk. The patch is working great.
Comment #4
jimajamma CreditAttribution: jimajamma commentedD'oh! I forgot to reply to my own question. I did similar but used field_file_load() instead of doing the db_query directly.
Jim
Comment #5
design.er CreditAttribution: design.er commentedThis patch works great. Thank you so much for fixing this bug! :)
Comment #6
stevetweeddale CreditAttribution: stevetweeddale commentedViews integration was broken for me too - I used jimjamma's field_file_load approach. There was also a couple of lines at the top of the
template_preprocess_jplayer_view_playlist
that looked like they were be breaking things.Anyway, as I was changing things a fair bit in the style plugin I included these fixes in a patch over at #981982: How to display other links/fields along with the actual mp3 link?.
Comment #7
deviantintegral CreditAttribution: deviantintegral commentedHere's a rerolled patch that also fixes a few style issues. I can't test this due to the issues I'm running into over at #961058: Jplayer not working with views for me, so I'm marking this as postponed.
Comment #8
deviantintegral CreditAttribution: deviantintegral commentedTurns out this was a pretty simple fix to get the Views style working again. I've committed a rebased version of this patch (that I missed uploading in #7).