83283

Is it possible to check which video/audio `codec` supported by which browser using JS?

More precisely, I would like to check which codecs I can use in a browser for video/audio elements in HTML5. (e.g. Safari supports H.264, but I also would like to know which codecs I can use)

Since specification changes over-time I would like to do it somehow automaticaly, not based on browser-codec tables.

I think, it can be written as a function in JS(if it is not written, yet). I have tried to Google it, but wasn't even close to find an answer.

Answer1:

Reference link : https://www.nomensa.com/blog/2011/detecting-browser-compatibility-html5-video-and-audio You can do something like this :

// Define the get_mime function var get_mime = function(filetype){ var mimetype = ''; var media_container = 'video'; switch(filetype){ case 'mp4': mimetype = 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"'; break; case 'ogg': mimetype = 'video/ogg; codecs="theora, vorbis"'; break; case 'webm': mimetype = 'video/webm; codecs="vp8, vorbis"'; break; case 'mp3': mimetype = 'audio/mpeg'; media_container = 'audio'; break; } return {'mimetype':mimetype,'container':media_container}; }; // Check to see if the browser can render the file type // using HTML5 var supports_media = function(mimetype, container) { var elem = document.createElement(container); if(typeof elem.canPlayType == ‘function’){ var playable = elem.canPlayType(mimetype); if((playable.toLowerCase() == 'maybe')||(playable.toLowerCase() == 'probably')){ return true; } } return false; }; // When the DOM has loaded check the file extension of each media link // and serve up appropriate media player $(document).ready(function(){ $(‘a.youtube-links’).each(function(){ var path = $(this).attr(‘href’); var extension = path.substring(path.lastIndexOf('.') + 1); var extension_info = get_mime(extension); if(supports_media(extension_info.mimetype, extension_info.container)){ // Serve up an HTML5 Media Player and controls serve_html5(); }else{ // Serve up a flash based video for browsers that //will not play the file using HTML5 serve_flash(); } }); });

Recommend

  • Jquery Make Array Key To Be Var
  • Validate a Boolean expression with brackets in javascript regex
  • c3js - having the X axis in the middle of the chart
  • How to join array of strings in Javascript
  • iphone/ipad web video only plays over 3g not Wifi
  • How to debug problems with the javafx native bundle for Windows?
  • Wordpress header external php file - change title?
  • Creating A New App For Page
  • Will jQuery ever leverage HTML5 technologies?
  • Is there any way to center certain columns in table?
  • Nginx raises 404 when using format => 'js'
  • white-space: pre-wrap not working in IE
  • Perl keyword say is not working in version 5.14.4
  • How to read JSON-LD data from HTML in Objective-C?
  • Multilingual set up of codeigniter
  • FragmentActivity with a Fragment Containing a MapView
  • Use neo4j server instead of embedded mode
  • Need a consistent TimePicker gizmo for mobile web site
  • Detection of framework usage on Mac system?
  • How to discover Font Type?
  • back button function for phonegap windows phone 7
  • BeautifulSoup difference between findAll and findChildren
  • Loading .coffee files via a view in Rails
  • java inputstream
  • Sencha Touch 2.0 Controller refs attribute not working?
  • Jquery UI tool tip close icon
  • NHibernate Validation Localization with S#arp Architecture
  • When to use `image` and when to use `Matrix` in Emgu CV?
  • What is the “return” in scheme?
  • Optimizing database types to compact database (SQLite)
  • Cross-Platform Protobuf Serialization
  • Which linear programming package should I use for high numbers of constraints and “warm starts” [clo
  • Do I've to free mysql result after storing it?
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • Traverse Array and Display in markup
  • Revoking OAuth Access Token Results in 404 Not Found
  • Turn off referential integrity in Derby? is it possible?
  • Qt: Run a script BEFORE make
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • JaxB to read class hierarchy