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

Should unload method set src to empty string? #80

Closed
JobaDiniz opened this issue May 13, 2015 · 19 comments
Closed

Should unload method set src to empty string? #80

JobaDiniz opened this issue May 13, 2015 · 19 comments
Assignees
Labels
status: archived Archived and locked; will not be updated type: question A question from the community

Comments

@JobaDiniz
Copy link

Is it ok to set the video src attribute to an empty string?
When I call unload method, html5 video player throws an error: MEDIA_ERR_SRC_NOT_SUPPORTED

This line of code sets src to empty string, but according to W3 this shouldn't be done:

The attribute, if present, must contain a valid non-empty URL potentially surrounded by spaces - attr-media-src

A string is a valid non-empty URL potentially surrounded by spaces if, after stripping leading and trailing whitespace from it, it is a valid non-empty URL - valid-non-empty-url-potentially-surrounded-by-spaces

A string is a valid non-empty URL if it is a valid URL but it is not the empty string. - valid-non-empty-url

@tdrews
Copy link
Contributor

tdrews commented May 13, 2015

Good catch and thanks for the report. We'll take a look.

@tdrews tdrews added this to the v1.3.1 milestone May 13, 2015
@joeyparrish joeyparrish added type: bug Something isn't working correctly flag: good first issue This might be a relatively easy issue; good for new contributors labels May 21, 2015
@joeyparrish
Copy link
Member

@JobaDiniz , what browser and version are you using when it throws that error? I'm unable to reproduce in Chrome 43.

@joeyparrish
Copy link
Member

Still don't have repro, but FWIW, I tried these ways as alternatives:

delete video.src; // has no effect.

video.src = null; // cast to a string, causes src to become a relative url to "null"

video.removeAttribute('src'); // makes src attribute a blank string, but does not unload the original source

@JobaDiniz
Copy link
Author

Browser: Chrome Version 42.0.2311.152 m
Sorry... in the upcoming weeks I'm not available to help...
I never said this is a bug, that's why I posed the question "Should unload method set src to empty string?". It seems that everybody sets src to an empty string (searching on google how to unload html5 video).
I know how is hard trying to fix something that for you just works. I need to create a repro somehow (don't know how yet) when I have the time to do it.

@joeyparrish joeyparrish removed type: bug Something isn't working correctly flag: good first issue This might be a relatively easy issue; good for new contributors labels May 22, 2015
@joeyparrish
Copy link
Member

Ah, I see. How frequently does this error occur? What OS are you on?

@joeyparrish joeyparrish removed this from the v1.3.1 milestone May 22, 2015
@JobaDiniz
Copy link
Author

OS: windows 8.1
On our environment, this always happened when we changed the current video.
In order to change video, we call shaka load method (which will call unload internally). We found out that is the unload method because we setup a call to unload when user closes our player and that raised MEDIA_ERR_SRC_NOT_SUPPORTED. Our service is telenor mytv. Near future there will be free content and you will be able to test what I'm saying.

@joeyparrish joeyparrish added the type: question A question from the community label May 22, 2015
@donato
Copy link
Contributor

donato commented Jun 11, 2015

I am seeing this same error every time when calling unload()

Error thrown from : https://github.com/google/shaka-player/blob/master/lib/player/player.js#L231
Stream : http://samplescdn.origin.mediaservices.windows.net/e0e820ec-f6a2-4ea2-afe3-1eed4e06ab2c/AzureMediaServices_Overview.ism/manifest(format=mpd-time-csf)
OS : Mac OSX
Chrome : Version 43.0.2357.124 (64-bit)

@joeyparrish
Copy link
Member

@donato, are you getting a MEDIA_ERR_SRC_NOT_SUPPORTED error like @JobaDiniz?

@donato
Copy link
Contributor

donato commented Jun 11, 2015

Yes. There are two versions of the error. I get this one when step debugging during _player.unload() :

{
  MediaError
    code: 4
    __proto__: MediaError
        MEDIA_ERR_ABORTED: 1
        MEDIA_ERR_DECODE: 3
        MEDIA_ERR_NETWORK: 2
        MEDIA_ERR_SRC_NOT_SUPPORTED: 4
}

And this one when following the same steps without debugging

Uncaught (in promise) DOMException: The existing MediaKeys object cannot be removed while a media resource is loaded.

@joeyparrish
Copy link
Member

I'm testing right now with Chrome 43.0.2357.65 on OS X 10.10.3. I'm using the latest Shaka Player test app to load the manifest @donato mentioned. I load the video, let it play for a few seconds, then call app.player_.unload() from the JavaScript console.

I'm unable to reproduce the problem. I've tried in both compiled & uncompiled modes.

@donato, are you seeing the error in the Shaka Player test app? Or only in your own application? Are there other steps involved in repro than just loading a source and then calling unload a few seconds later?

@joeyparrish joeyparrish self-assigned this Jun 11, 2015
@JobaDiniz
Copy link
Author

Hi @joeyparrish, I was able to reproduce the error in http://shaka-player-demo.appspot.com/. Before calling app.player_.unload(), run the following code:

var video = document.getElementById('video');
video.addEventListener('error', function(e){console.error(e)});

After calling app.player_.unload(), you should get

Event {}bubbles: falsecancelBubble: falsecancelable: truecurrentTarget: nulldefaultPrevented: falseeventPhase: 0path: Array[6]returnValue: truesrcElement: video#videotarget: video#videotimeStamp: 1434057371604type: "error"__proto__: Event(anonymous function) @ VM645:3

@joeyparrish
Copy link
Member

@JobaDiniz, what's the value of video.error.code when this happens?

@JobaDiniz
Copy link
Author

4

@joeyparrish
Copy link
Member

@JobaDiniz, @donato, I finally see what's going on.

This error is fired on video, but after Player has stopped listening for events. this.eventManager_.removeAll() runs before the source is unloaded, so the Player does not receive this event.

As far as I can tell, this event is a completely harmless side-effect of the way we unload. Until we (not we=Google, but we=the internet) come up with a better way of unloading a video source to reuse the video tag, my recommendation is not to listen for errors on the video tag directly. Instead, listen for errors on Player.

Listening on the Player will filter out errors you shouldn't have to care about, like this one, and it will allow you to receive lots of important errors that aren't dispatched through the video tag, like DASH-related or network-related errors.

So this brings us back to the original topic: is it correct to unload this way?

My feeling on the matter is that yes, it is okay to unload this way, but I am very open to alternatives. As mentioned in an earlier comment, I tried several alternatives already, to no avail:

delete video.src; // has no effect.
video.src = null; // cast to a string, causes src to become a relative url to "null"
video.removeAttribute('src'); // makes src attribute a blank string, but does not unload the original source

If anyone has any other ideas, or if anyone can find a more canonically correct approach to unloading in a w3c doc somewhere, I would be happy to try it.

@JobaDiniz
Copy link
Author

So how is the correct approach to listen for errors? Is there a code
snippet you can share?
On qui, 11 de jun de 2015 at 20:49 Joey Parrish notifications@github.com
wrote:

@JobaDiniz https://github.com/JobaDiniz, @donato
https://github.com/donato, I finally see what's going on.

This error is fired on video, but after Player has stopped listening for
events. this.eventManager_.removeAll() runs before the source is unloaded,
so the Player does not receive this event.

As far as I can tell, this event is a completely harmless side-effect of
the way we unload. Until we (not we=Google, but we=the internet) come up
with a better way of unloading a video source to reuse the video tag, my
recommendation is not to listen for errors on the video tag directly.
Instead, listen for errors on Player.

Listening on the Player will filter out errors you shouldn't have to care
about, like this one, and it will allow you to receive lots of important
errors that aren't dispatched through the video tag, like DASH-related or
network-related errors.

So this brings us back to the original topic: is it correct to unload this
way?

My feeling on the matter is that yes, it is okay to unload this way, but I
am very open to alternatives. As mentioned in an earlier comment
#80 (comment),
I tried several alternatives already, to no avail:

delete video.src; // has no effect.
video.src = null; // cast to a string, causes src to become a relative url to "null"
video.removeAttribute('src'); // makes src attribute a blank string, but does not unload the original source

If anyone has any other ideas, or if anyone can find a more canonically
correct approach to unloading in a w3c doc somewhere, I would be happy to
try it.


Reply to this email directly or view it on GitHub
#80 (comment).

@donato
Copy link
Contributor

donato commented Jun 12, 2015

Listening to shaka player for errors is demonstrated here

      player.addEventListener('error', function(event) {
        console.error(event);
      });

@joeyparrish
Copy link
Member

It's very simple, and there's an example in app.js:

player.addEventListener('error', function(event) {
  console.error(event);  // or whatever else you need to do with it
});

This pattern can be found in the test app and the samples in the tutorial.

Would it be helpful to call this out more explicitly in the docs somewhere?

@JobaDiniz
Copy link
Author

I think it would.

Thanks for the snippets.

@joeyparrish
Copy link
Member

I'm going to close this for now. I've filed an issue to update the docs as #106.

joeyparrish added a commit that referenced this issue Mar 15, 2016
It was pointed out in #80 that setting video.src='', although common,
is not best practice.  I finally received some advice from
w3c/media-source#53, specifically a pointer to the section "Best
practices for authors using media elements" in the HTML5 spec.
The solution is to use both removeAttribute('src') and load().
As determined during the investigation of #80, removeAttribute('src')
alone is not effective.

Change-Id: If0eb0dd2dc60dee0673dc92dabe9dc3e913457db
@shaka-project shaka-project locked and limited conversation to collaborators Mar 22, 2018
@shaka-bot shaka-bot added the status: archived Archived and locked; will not be updated label Apr 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: archived Archived and locked; will not be updated type: question A question from the community
Projects
None yet
Development

No branches or pull requests

6 participants