Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Can an image field be added to place a preview image prior to play please?
Comment | File | Size | Author |
---|---|---|---|
#47 | jw_player-posterfield-1395584-47.patch | 8.5 KB | Jorrit |
#42 | video thumnail.jpg | 31.61 KB | gavrillich |
#29 | jw_player-posterfield-1395584-29.patch | 8.14 KB | Jorrit |
#25 | jw_player-posterfield-1395584-25.patch | 9.17 KB | Jorrit |
#21 | jw_player-posterfield-1395584-21.patch | 8.46 KB | Jorrit |
Comments
Comment #1
rickvug CreditAttribution: rickvug commented@diskojerk Having a preview image is definitely something that needs to be supported. What makes it a somewhat tricky proposition is that the image could come from many different sources depending on a site's needs. To give an example I'm working on a project that uses File Entity. With File Entity we attach a thumbnail field to files themselves. In other cases you may want a site wide preview image or you may want to grab the image from another field on a node. Because of the multitude of possibilities any image selection logic will need to be pluggable and configurable within a preset.
As a quick start to adding process I've added a $poster variable within the player tpl (commit) allowing developers a way to set their own poster image. However there's no logic within the module for setting the value. To give an idea of one particular implementation here's the pre-process code I'm using right now to pull the image in from a field attached to video files:
I'd be very happy to see someone try to take on the problem.
Comment #2
gtrdriver CreditAttribution: gtrdriver commentedHello
i just posted a new request regarding this function...
I see this is not possbile jet in drupal because there is no storage Plan for the "Poster Images".
Im not a developer - so i want to ask you what changes i can made that jwplayer allways display the same "Poster Image" in all my Videos at my Drupal Installation ?
I think about to make a "company Poster" Image and i think this will look fine.
Can you help me what modifications i have to do to define a default Poster (preview Picture) for alle jwplayer locations in my drupal site ?
Best regards
Axel
Comment #3
andypostSolution for video module using $poster variable #1398388-2: Using JW Player
probably we could use tokens in formatter settings to point a image field but this would only works for file field + image field
Comment #4
nochiu CreditAttribution: nochiu commentedHello, rickvug
Could you teach me where should I add the your PHP code.
Should I make some custom module ? or add the code in "jw_player.module" ?
I'm new user with Drupal7
sorry but my poor English.
Thank you.
Comment #5
rickvug CreditAttribution: rickvug commented@nochiu The PHP code should either go into a custom module or your own theme. As a general rule never modify modules or Drupal core directly. If you must, submit a patch and then apply that patch (and be sure to document and track its status afterwards). To get this working implement the hook_preprocess_jw_player. If your custom modules name is "mymodule" then the function would be mymodule_preprocess_jw_player(&vars). In this function add a poster to variables array. I hope this points you in the right direction. Drupal development and theming has a fairly high learning curve but you're lucky that there's a lot of documentation out there now. Good luck!
Comment #6
nochiu CreditAttribution: nochiu commentedThank you for replying!
I tried creating the module, but It seems that does not working now.
Could you check my process?
mymodule.info
mymodule.module
It has been black out in the player and Didn't see a preview image(thumbnail).
Were there somthing wrong?
Please, tell me more something what I should do.
Thank you very much.
Comment #7
rickvug CreditAttribution: rickvug commentedI think that the problem is that you've attached the field to the node you're attaching the video to rather than the video file itself. In the example provided the field must be attached to the file via file_entity. It would also be possible to grab the field from the node but the code would be different. In that case you could use menu_get_object() to get the nid, node_load() to get the node, then call field_get_items('node', $node, 'field_name') to extract the image URL for the poster.
Does this make sense?
Comment #8
rickvug CreditAttribution: rickvug commentedNote that I just made a commit that changes the variable from $poster to $image. This is more consistent with JW Player - poster is only used in the HTML5 video tag itself. The same commit also makes it possible to pass the image URL directly to the theme function. So the following should work:
Preprocessing to add the poster is also possible and works with the field formatter integration (no need to call theme('jw_player') manually).
Comment #9
nochiu CreditAttribution: nochiu commentedI made that displayed poster image with File entity module!
Thank you very much.
but I would like to attache a field to node and get poster image from attaching a video node.
Could you teache me how to write defferent corde.
I tried replace the code, but doesn't work.
Thank you.
Comment #10
rickvug CreditAttribution: rickvug commentedTry changing $variables['poster'] to $variables['image'] as the variable being used by JW Player has changed. If that doesn't solve the issue try var_dump() (or dpm() if you're using devel) on the variables to see if you are getting what is expected at each stage.
Comment #11
nochiu CreditAttribution: nochiu commentedThank you, rickvug. I'll try it with devel module.Thanks a lot!
Comment #12
Max_Headroom CreditAttribution: Max_Headroom commentedBased on the tips here I created a small module that will use an image uploaded with the node as poster for player.
You can select the field used for the image in the JW Player settings (/config/media/jw_player/settings). Ideally this setting should be in the presets to make it more content specific, but I am not sure how to alter a ctools form and this way suits my needs.
Comment #13
fugazi CreditAttribution: fugazi commentedHi Max_Headroom,
It works great, many thanks
Comment #14
stevebeck CreditAttribution: stevebeck commentedThanks Max_Headroom, working nicely for me as well.
Comment #15
stevebeck CreditAttribution: stevebeck commentedHi, I am loving this module, one question, is it possible for the poster image to inherit the imagecache style?
Comment #16
Max_Headroom CreditAttribution: Max_Headroom commentedI did not include imagecache, as the poster image scales to the video size set in the preset.
Comment #17
champagne61 CreditAttribution: champagne61 commentedFirst of all, thanks you Max_Headroom, this module proved to be very useful. It's working great with the nodes.
However I cannot get it working when the jw player is inside a view ? Any idea how to do this ?
Comment #18
Screenack CreditAttribution: Screenack commentedMax_Headroom: W00T! That module is buggy yet awesome! I would love to see this merged or whatever to make it live. Then I can file a bug report. ;)
I get the following when this property isn't set:
[23-Aug-2012 02:46:34 UTC] PHP Fatal error: Cannot access empty property in /Volumes/client/public_html-7/modules/field/field.module on line 936
Comment #19
mgifford@Max_Headroom what's happening with this small module? Ideally it would be a nice small module brought into the jw_player module so that it is an easy option for everyone who wants this functionality.
@rickvug any concerns with that approach?
Comment #20
Jorrit CreditAttribution: Jorrit commentedI am the maintainer of the Video.js module, where I implemented a similar feature. I have ported this code to the JW player module. It allows you to select an image field in the Formatter settings. You are able to select image fields that are associated with the same bundle. You can select an image style to be applied to this image.
The patch also contains support for the link_field, in more simple way than suggested in #1494436: Provide a formatter for Link fields. I have not yet tested this patch 100%, I may update it in the coming days.
Comment #21
Jorrit CreditAttribution: Jorrit commentedAs promised, the patch contained a bug. Here is an updated version.
Comment #22
Max_Headroom CreditAttribution: Max_Headroom commented@19 Innitially my module was just a means to an end to get the job done for me. It was never meant (nor good practice) to be an add on module.
I was also tolling with the idea of having the poster image as a formatter, just never got around to it. Glad to see Jorrit came up with something.
Seems like this is a popular request, and I vote that we get the patch tested and rolled out in the main module. Will try to get around to test it (hectic this time of year).
Comment #23
BerdirThanks for working on this, looks quite good, detailed review below.
I don't quit understand the need for that ctools special case and why the mimetype stuff needs custom handling now, if that is required for this patch please add some inline (or in case of ctools to the function docblock that needs to be added anyway).
Comments should end with a ".".
Usually, for links within translatable strings, the tag is directly added and just the url (created with url() is a placeholders. That allows to translate it with a context and also come up with a correct sentence in e.g. right to left languages like russion.
The function should have some basic documentation with a one-line description, @param and @return tags.
The label should be a placeholder here, then check_plain() isn't necessary.
Same.
Should use file_get_mimetype() instead.
Another missing .
Comment #24
Jorrit CreditAttribution: Jorrit commentedThanks for the review.
The ctools part is used when the formatter is used for a Views field. When the formatter is used there, the bundle is not known, so more options need to be available in the field option list. I will update the patch soon with more comments.
Comment #25
Jorrit CreditAttribution: Jorrit commentedThe reason I used
t('Poster image style') . ': ' . t('None');
instead of a placeholder is that in that way, the string 'Poster image style' only needs to be translated once. Now it needs to be translated twice, while the ': @value' part doesn't really add anything to translate.In any case, I updated the patch with all your comments.
Comment #26
BerdirThanks, re-roll looks good.
Maybe some people can confirm that this is working correctly and RTBC this?
Right, it is a bit more work to translate it but it *can* be translated correctly now :)
Comment #27
Max_Headroom CreditAttribution: Max_Headroom commentedI could not apply the patch to the latest dev version, but I think it is possible my IDE, as I did not see any funny things when I applied the patch manually.
You have included another fix inside this patch. That is to add link_field to have a JW_Player formatter:
And:
I also think link_field is a good idea, but it is not related to this issue. Link module is also a contributed module. Please remove and open a separate issue for it.
Other than that, it is working well. I think another test to check the patch, then we can go RTBC.
Comment #28
Jorrit CreditAttribution: Jorrit commentedThat is also what I said in #20. I will remove it.
Comment #29
Jorrit CreditAttribution: Jorrit commentedNew patch
Comment #30
TomSherlock CreditAttribution: TomSherlock commentedFirst, I want to thank everyone on this thread for contributing to the patch in #29.
I've successfully applied the patch to the JW Player. I traced the code in Eclipse. I have been able to set the property when editing my content type.
However, I have not been able to select an image, so I have no image displayed in the JW Player in place of the black screen. Obviously, I'm missing a step. Should I be using the preprocess_jw_player hook to select the image?
Thanks.
Comment #31
TomSherlock CreditAttribution: TomSherlock commentedBased in Max_Headroom's comment from #12, I added an image field to my content type.
Under display management I was then able to set the Poster image field and Poster image style.
For Poster image field I selected the field to which I had uploaded the image.
I also traced the code and saw that this field was selected and it had a legitimate URL associated with it.
Nevertheless the video's black screen is still present; there is no preview or poster image.
I also looked at the tags through the browsers element inspector. I thought I'd might see an img tag
associated with the poster image. I found a div for _jwplayer_display and within that div an img with
the id _jwplayer_display_image whose style included display:none. I wonder if
that might have anything to do with no img displaying? Or is it something else?
The img tag has no src attribute with a url pointing to the image.
I'm using a jw player preset that was created before I added the patch. Should I be creating a new jw player preset?
Does someone have a sample on a public website that I could look at? I'm curious see how the html would look when inspecting the elements.
Thanks.
Comment #32
TomSherlock CreditAttribution: TomSherlock commentedI'm using the field type File and the widget Media file selector and then under display I'm using JW player as Format. Should I be using a different field type?
Comment #33
Jorrit CreditAttribution: Jorrit commentedAn example video is: http://www.domradio.de/video/interview-mit-bundesverteidigungsminister-t...
You should look at the HTML when it is generated. It should be like:
The poster part is important.
Comment #34
TomSherlock CreditAttribution: TomSherlock commentedThanks, Jorrit, for the HTML sample. When I inspect element in Firefox 19.0.2, I see very different HTML:
It seems to be defaulting to flash even though I set the JW Player to try HTML5 first. So I had a look at the jw_player.tpl.php to see if poster was there. It is but the variable $poster is not initialized. And there doesn't seem to be the index counterpart (['poster']) in the preprocess function nor anywhere else.
The jw_player.info file dates my copy at 2012-01-13. It is version 7.x-1.x-dev.
I was looking at version 7.x-1.x-dev with the date 2013-01-26. It looks it has the patch included. However, I still don't see ['poster'] within the $variables.
Could this be an issue because it's defaulting to flash instead of HTML5?
Comment #35
Jorrit CreditAttribution: Jorrit commentedYou are looking at the HTML _after_ the JW Player javascript has processed it. What's important is the HTML that Drupal generates. In most browsers, that's what you see when you press the right mouse button and choose View Source.
My patch was not committed (yet), so you can't look at 7.x-1.x-dev and find it.
Comment #36
TomSherlock CreditAttribution: TomSherlock commentedOk, thanks. When I view source this is what I see:
I do not see poster. I was looking more closely at jw_player.tpl.php and noticed that poster will be initialized only of $image has a value in the 2013-01-26 version:
<?php if(isset($image)) : ?> poster="<?php print $image ?>"<?php endif ?>
The 2012-01-13 version it checks for $poster instead:
<?php if(isset($poster)) : ?> poster="<?php print $poster ?>"<?php endif ?>
In a comment associated with the function template_preprocess_jw_player it says $image is an optional variable that can also be set.
The $image variable comes in unset and is not set in the function. Should I be writing my own preprocess function to set $image?
BTW, Jorrit, I greatly appreciate your responsiveness.
Comment #37
Jorrit CreditAttribution: Jorrit commentedSetting the optional image parameter is exactly what my patch at comment #29 does. Have you applied this patch?
Comment #38
TomSherlock CreditAttribution: TomSherlock commentedThe only time I can see the preview image is in the function jw_player_field_formatter_view.
The $image is associated with the index, '#image' in the array, $element.
But the $image seems to get lost after that. I don't see it being added to $poster.
And yet a few others on this thread seemed to have been successful in displaying the preview.
So should I be writing my own preprocess function?
Is this what they did?
Comment #39
TomSherlock CreditAttribution: TomSherlock commentedYes I applied the patch.
I've applied it to the dev version from 2012-01-13 and the alpha version succesfully.
I was unable to apply the patch to the most recent dev version. I got an error:
Comment #40
TomSherlock CreditAttribution: TomSherlock commentedThe patch says:
So I am able to go to Manage display at admin/structure/types/manage/article/display.
I am able to select JW Player as the Format and configure the Poster image field and the Poster image style:
Preset: jw_present
Description:
mode: html5
width: 640
height: 360
controlbar: over
skin: default
autoplay: default
Poster image field: Preview Image
Poster image style: medium
It would appear to me that the $variables should be set in the preprocess function as indicated by the function's comments. But the variable used in the *.tpl.php is not being initialized. I don't see $variables['poster'] nor $variables['image'] in the module nor the patch, while $poster and $image are referenced in their respective versions of the *.tpl.php.
Comment #41
TomSherlock CreditAttribution: TomSherlock commentedSo back to the function, jw_player_field_formatter_view.
It does a good job of using the $posterimage_field and $posterimage_style to get the poster image.
Then it packs that image into an array and returns it.
If there are no items then the default image found does not get added to the array being returned.
If I can somehow get that poster image into the $variables or somehow pick up the poster image while in the preprocess function
I would be able to set $variable['image'] or $variables['poster'] and then display the image in in the *.tpl.php.
One possibility would be to use variable_set and variable_get. But the downside is that it would require writing to and reading from the
database.
Comment #42
gavrillich CreditAttribution: gavrillich commentedI was able to upload a custom video preview image file with the video module http://drupal.org/project/video. I set the JW player as default player for .flv files in settings. In content type manage fields field type is video ( not file), under manage display format is video player. In the node edit form I had to select bypass auto conversion ( for some reason it was not working) and there is a field to upload video preview below( attached). I still needed JWplayer module - video module uses preset.
Comment #43
TomSherlock CreditAttribution: TomSherlock commentedThanks for this tip, gavrillich. I'll try your recipe.
Comment #44
kingfisher64 CreditAttribution: kingfisher64 commentedThe patch on #29 outputs the following when applied the latest dev, 26th Jan 2013.
Comment #45
TomSherlock CreditAttribution: TomSherlock commentedI got that same failure as noted in comment #39.
Comment #46
BerdirIf a patch doesn't apply anymore, set it needs work and/or try to re-roll it.
Comment #47
Jorrit CreditAttribution: Jorrit commentedRerolled the patch.
Comment #48
kingfisher64 CreditAttribution: kingfisher64 commentedIs the outcome when jw_player-inputfilter.patch from http://drupal.org/node/1816928 is applied first.
I tried again with dev from 26th Jan and patch works fine.
Comment #49
Jorrit CreditAttribution: Jorrit commentedI think patches are always intended to be applied against a clean git version. I can't take into account any other patches you have applied.
Comment #50
nyl_auster CreditAttribution: nyl_auster commentedWow, this last patch works like a charm and this is very handy to have this option in the field formatter. No bug for me for now. thanks !
Comment #51
kingfisher64 CreditAttribution: kingfisher64 commented@Jorrit - you are right. The problem is when a module has more than one patch that needs applying. Can we commit this into the project asap since it's working fine. :)
Comment #52
RobKoberg CreditAttribution: RobKoberg commentedHere is a preprocess function that works for me. Note the line with
$variables['config']['image'] = $poster_url;
which is necessary.Comment #53
Nikit CreditAttribution: Nikit commentedI remade RobKoberg code for safety and now itsn't depend on node full-page viewing, so it can used on views or teasers, replace all uppercase text, so you should:
1. have video (media) field on node;
2. have image field for poster, that attached to the same node where media field - IMAGE_FIELD_NAME;
3. add image style for filling poster in video: IMAGE_STYLE_FOR_VIDEO - sizes should be the same as video widget size (scale & crop will useful).
4. Add next code to your template.php and rename THEMENAME to your theme name;
5. Clear cache;
p.s. Code refixed, since in some case in node full page viewing node reference doesn't loaded.
p.p.s ref.variables refixed due to julescone comment
Comment #54
julescone CreditAttribution: julescone commentedThanks Nikit, that is exactly what I needed.
One heads up on your code I was getting a PHP warning:
"Deprecated function: Call-time pass-by-reference has been deprecated in phptemplate_init()"
This comment set me on the right track. https://drupal.org/node/1293776
Essentially the & on the template_preprocess_jw_player line isn't required under PHP 5.x+ , and is the cause of the warning.
template_preprocess_jw_player(&$variables); // Let's pass via jw player preprocess.
Should be:
template_preprocess_jw_player($variables); // Let's pass via jw player preprocess.
Note you need to leave the "pass by reference" & parameter on &$variables in the function declaration though.
Cheers, Jules
Comment #56
pbuyle CreditAttribution: pbuyle commentedAs far as I can tell, both the 7.x-1.x and 7.x-2.x branch support the usage of a poster image via
hook_preprocess_jw_player
.The patch in #47 add a solution to allow usage of an image field on the entity. This is a nice solution, but only cover some use cases of poster image. Rather than being in the main jw_player module, it should be on in its separated module (that could still be part of the JW Player project). This way, users (like myself) who have no need for the feature and implement their own custom solution won't have to ensure both solution does not create any conflict.
Comment #57
pbuyle CreditAttribution: pbuyle commentedComment #58
ron_s CreditAttribution: ron_s commented@Berdir, given that you recently committed preview image functionality for 7.x and 8.x, what are your thoughts on this point?
Comment #59
ron_s CreditAttribution: ron_s commentedThis functionality is in 7.x-2.x, and probably makes sense to just close the ticket for now. Someone can re-open or post a new one for 7.x-2.x if there are further issues or items to be discussed.