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

Improvement: Player should fire an error event when the source cannot be played #746

Closed
ajbogh opened this issue Sep 19, 2013 · 5 comments
Closed

Comments

@ajbogh
Copy link

ajbogh commented Sep 19, 2013

The player.src function should trigger an error event when the source cannot be played. This event will allow a developer to use custom fallbacks or display other messages than the notSupportedMessage.

The code below is an example. Please feel free to code it as you would see fit. It may be useful to use an Error object with additional appropriate information.

player.js (~lines 733-755)

vjs.Player.prototype.src = function(source){
  // Case: Array of source objects to choose from and pick the best to play
  if (source instanceof Array) {

    var sourceTech = this.selectSource(source),
        techName;

    if (sourceTech) {
        ...
    } else { //fire error event here
      this.el_.appendChild(vjs.createEl('p', {
        innerHTML: this.options()['notSupportedMessage']
      }));
      //fire error event here
      var e = new Error("Video not supported. -- [extra detail if necessary]");
      this.trigger("error", e);
    }
@heff
Copy link
Member

heff commented Nov 12, 2013

We need to do some research into the right way to handle this situation according to the spec. Browsers don't appear to throw any errors in this situation, so an error may not be right. But there should be some kind of notification or way to customize this situation.
http://jsbin.com/UCuTuNu/5/edit

@heff
Copy link
Member

heff commented Nov 12, 2013

The resource selection algo should be the first place to look to verity how it should be handled.
http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#concept-media-load-algorithm

@ajbogh
Copy link
Author

ajbogh commented Nov 14, 2013

Item 6 in your link shows that the resource should fire a MediaError with the code attribute MEDIA_ERR_SRC_NOT_SUPPORTED, but I don't know if that's happening.

Another method is to determine the codecs and filetypes of the media files before adding them to the src and perform a quick check against the video element using something like this code:

var canplay = false; //default to false
var codec = "";
var type = "";
if ( video.canPlayType ) {
    for(var i in source){ //we know it's an array
        // Check for support
        if(sources[i].type){
            type = sources[i].type;
        }else{
            type = "video/"+sources[i].src.split(".").pop(); //file extension
        }
        if(sources[i].codec)){ //add codec support to sources!!
            type += '; codecs="'+sources[i].codec+'"';
        }
        canplay = "" !== video.canPlayType(type);
    }
}else {
    //fallback to basic error message or let the system figure it out by setting canplay to true
}

@heff
Copy link
Member

heff commented Dec 9, 2013

Wrapped this up into #869.

@heff heff closed this as completed Dec 9, 2013
@heff
Copy link
Member

heff commented May 13, 2014

This issue should be fixed now as of #1197

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 28, 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

2 participants