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

Better error message when audio element has no source, or permit audio element to have source inserted dynamically. #13

Closed
sampsyo opened this issue Aug 9, 2011 · 4 comments

Comments

@sampsyo
Copy link

sampsyo commented Aug 9, 2011

I realize that this may be an uncommon use, but I'm using a single <audio> element to play multiple tracks. That is, the element starts out with no source (just <audio autoplay></audio>) and, based on the user's interaction, loads a specific file and begins playing it.

html5media appears to assume that the element has at least one source. This document, for instance, raises an error in the latest versions of Safari and Firefox for me:

<html>
    <head>
        <script src="http://api.html5media.info/1.1.4/html5media.min.js"></script>
    </head>
    <body>
        <audio></audio>
    </body>
</html>

The error as reported by Safari is:

TypeError: 'undefined' is not an object (evaluating 'a.match')

Oddly, I can only seem to recreate this in the minified version of the script -- maybe this is fixed in the latest source?

@etianen
Copy link
Owner

etianen commented Aug 9, 2011

Hi,

Thanks for the report. There's certainly a way to accomplish what you're trying to do. Rather than attaching the source elements to the audio tag dynamically, try using a container element that you add complete audio elements too dynamically. Whenever you add an audio tag, call html5media() to kick in the fallback for unsupporting browsers.

Does your code work correctly in all html5-compliant browsers without including the html5media code? The reason I ask, is that I'm a bit unclear on whether an audio tag with no specified source is actually valid HTML. If it is, and your code works without error without html5media, then I'll add in this feature. If an audio tag with no source isn't valid HTML, then I'll adjust it to give a more informative error message.

The trunk version of the script handles loading audio source identically. Are you sure that you're using the complete, compiled version of the script when linking to the trunk?

@sampsyo
Copy link
Author

sampsyo commented Aug 9, 2011

You're absolutely right that it's not clear from the standard whether omitting the source is valid. In my experience, it seems to work in Safari, Firefox, and Chrome, but the documentation is sparse enough that it's difficult to tell whether this is intentional.

Dynamically adding/replacing the audio element does seem like the way to go in the meantime. Thanks for the idea.

@etianen
Copy link
Owner

etianen commented Aug 10, 2011

I've updated the name of this issue.

I'm really not sure whether to make this throw an error, or just ignore media tags with no source. In the latter case, you'd still need to call html5media() to kick in the fallback player when the source has been dynamically inserted.

@etianen
Copy link
Owner

etianen commented Nov 17, 2011

I've updated the code to fail silently if no source element could be found. This allows the code to run without errors, since this markup is probably valid.

Once source elements have been supplied, the programmer can then call html5media() to kick in the fallback;

@etianen etianen closed this as completed Nov 17, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants