Audio codec detection

Share your advanced knowledge/code with the community.
User avatar
MrTAToad
Posts: 291
Joined: Sun Apr 20, 2014 11:43 am
Location: Chichester, England
Contact:

Audio codec detection

Post by MrTAToad »

This is an example of detecting what codecs should be able to be used in a browser :

Code: Select all

Declare.b canPlay(vidType.s,codType.s)

Debug "MP3 : "+canPlay("audio/mp3","")
Debug "OGG : "+canPlay("audio/ogg","vorbis")

Procedure.b canPlay(vidType.s,codType.s)
  Define text.s
  Define result.b
  
  text=vidType+";codecs="+Chr(34)+codType+Chr(34)
  
  !var obj = document.createElement('audio');
  !if (obj.canPlayType(v_text)=="")
  !  v_result=false
  !else
  !  v_result=true
  
  ProcedureReturn result
EndProcedure
Produces 1 and 0 on Internet Explorer (and Edge), whilst it results in 1 and 1 for Chrome