Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No way to set poster image after initialization #525

Closed
tomsaffell opened this issue May 22, 2013 · 13 comments
Closed

No way to set poster image after initialization #525

tomsaffell opened this issue May 22, 2013 · 13 comments

Comments

@tomsaffell
Copy link

After initialization, there is no way to set the poster image.
The player does have a .poster(src) function, but it doesnt change have any effect on the poster image src after initialization.

There are two possible fixes:

  1. improve the .poster() function to handle changes to the poster at any time

  2. allow a poster attribute to be passed with src, eg.

    .src({src: 'http://foo.com/foo.mp4', poster: 'http://foo.com/foo.jpg'});
    

Does anyone have a preference?

@rhues
Copy link

rhues commented May 22, 2013

The first option would be helpful to me. Thanks.

@SergiDiaz
Copy link

Both options would be good, I'm having the same problem.

@heff
Copy link
Member

heff commented Jun 3, 2013

The first option looks best to me. The best approach would probably be to trigger a 'posterchange' event any time poster(src) is set, and then have the poster component listen for that event and update the poster source depending on how it was originally set. https://github.com/videojs/video.js/blob/master/src/js/poster.js#L31

@tomsaffell
Copy link
Author

@heff Yeah, that sounds like a good solution.

@jwlms
Copy link

jwlms commented Jul 26, 2013

What's the purpose of having a separate poster image rather than using the <video poster="poster_url">?

Posters don't seem to be displayed on iOS devices in the current implementation, and trying to append the poster attribute after initialization doesn't seem to work (which I think is the topic of this post). Would love to chip in here, but not sure why the poster attribute isn't being used in the first place.

@heff
Copy link
Member

heff commented Jul 29, 2013

Trying to remember all the details, but I know there are/were a few reasons for creating a custom one.

  • Older versions of Safari Desktop/iPad would break the video if you used the native poster. Also mentioned here: http://camendesign.com/code/video_for_everybody
  • With Flash you run into security issues when you load an external image from a URL.
    So with those issues it was easier to be consistent and use the same poster across all platforms.

The older versions of Safari probably aren't a concern anymore, but I wouldn't want to kill the poster component because of Flash and potential other future techs that may not support a poster image, e.g. Quicktime or Divx.

@tomsaffell
Copy link
Author

With Flash you run into security issues when you load an external image from a URL

I dont think that's quite accurate. When you load an image 'as data' (i.e. in a way that allows you to read pixel values) then you're subject to cross-origin restrictions and policies. When you load it merely to put it on the stage, there is no cross-origin restriction, or other security restriction that i know of.

Of course, that doesnt mean it isnt best to have a separate html element, I'd have to think about that.

Given that the controls have already established an html-over-flash pattern, it seems fine to continue that way to me.

@heff
Copy link
Member

heff commented Jul 29, 2013

Here's the last conversation I was able to find on the matter with @alemay. I don't think we ever moved to bytes, and not clear on why Andy wanted to avoid that.

Either way, I'm not seeing a strong need to kill the poster image yet.

Okay, I think I've figured out the problem: oddly enough, it's the poster image. Flash chokes when you try to "manipulate" bytes in an loaded asset without having explicit authority to do so. Since there's no crossdomain.xml on the domain that the poster frame is being loaded from, Flash will load it, but attempting to do anything to it will throw an error and freeze the call stack. Apparently, this behavior is invoked when attempting to do two of the things that I need to do:

  1. Set smoothing on the loaded image, so that it doesn't look like shit when it's resized.

  2. Resize the poster frame when the player size changes.

I'm researching options right now. One person suggested loading the image asset as bytes, then running those bytes through an image parser to create a bitmap and then display it. I'd really like to avoid that.

@tomsaffell
Copy link
Author

AFAIK, resizing would not cause that. There's a couple of different classes that can be used to load and display images, perhaps @alemay's comments refer to a more restrictive one.

But maybe this is a red herring - maybe it should be an html element anyway - isnt that simpler? What's the downside?

@heff
Copy link
Member

heff commented Jul 30, 2013

Yeah, not sure of any yet. But doesn't hurt to document all this either way. :)

dmlap added a commit to dmlap/video.js that referenced this issue Aug 25, 2013
When poster() is called with a URL, set it to the PosterImage source and update the video element attribute.
dmlap added a commit to dmlap/video.js that referenced this issue Oct 14, 2013
When poster() is called with a URL, fire a `posterchange` event to update the PosterImage source and update the video element attribute.
dmlap added a commit to dmlap/video.js that referenced this issue Oct 17, 2013
When poster() is called with a URL, fire a `posterchange` event to update the PosterImage source and update the video element attribute.
dmlap added a commit to dmlap/video.js that referenced this issue Nov 11, 2013
When poster() is called with a URL, fire a `posterchange` event to update the PosterImage source and update the video element attribute.
@heff heff closed this as completed in 875fc2f Nov 27, 2013
@alex-bender
Copy link

I found out another way:

  1. get the video
    var video = $('#video_1 video')
  2. change attr
    video.attr('poster', 'http://1x1px.me/000000-0.png')

@faiyazalam
Copy link

My working code:
let player = videojs('videoplayer', options);
player.poster("video_poster_url");
player.src({src: "video_url", type: "video/mp4"});

@gkatsev
Copy link
Member

gkatsev commented Apr 1, 2020

We also have a loadMedia method you can use to do it one operation:

player.loadMedia({
  src:  {
    src: 'video.mp4',
    type: 'video/mp4'
  },
  poster: 'poster.png'
});

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants