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

Proposal: canPlay(a local file) api #196

Open
hanguokai opened this issue May 27, 2022 · 0 comments
Open

Proposal: canPlay(a local file) api #196

hanguokai opened this issue May 27, 2022 · 0 comments

Comments

@hanguokai
Copy link
Member

Hi, I created a web video player that focus on playing local video files (not online streaming media).

I want to know whether a video element can play a local file. Currently, I use try-catch statement to detect it. But sometimes it can play audio track but can't play video track, and don't throw error.

The problem is isTypeSupported(), canPlayType() and decodingInfo() asking for a (MIME type + codec) string as a parameter. But for local files scene, I don't know this info in advance. To get this info, I need to analyze the file content, for example use mp4box.js or mediainfo.js library.

So I would like to propose a new method canPlay(file). The parameter is a file object URL or a file. If Media Capabilities API supports whether browser can play a local file, I don't need to know (MIME type + codec) in advance.

Use case is:

if (browser can play this file) {
   play it
} else {
  prompt user: "cannot play this file"
}
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