Module org.htmlunit
Package org.htmlunit

Class BrowserVersion.MediaResourceType

java.lang.Object
org.htmlunit.BrowserVersion.MediaResourceType
All Implemented Interfaces:
Serializable
Enclosing class:
BrowserVersion

public static class BrowserVersion.MediaResourceType extends Object implements Serializable
Represents a media type that a browser can play, combining a MIME type with an optional set of codecs.

Instances are immutable.

Instances are used as keys in the two lookup sets held by each BrowserVersion (maybeMediaResource_ and probablyMediaResources_) and are queried by BrowserVersion.canPlayType(String) to determine the value returned by the HTMLMediaElement.canPlayType() DOM method:

  • "maybe" — the MIME type alone is in the maybeMediaResource_ set (no codec information given).
  • "probably" — the MIME type together with the specific codec list is in the probablyMediaResources_ set.
  • "" — neither set contains a matching entry.

Equality and hashing are based on both the MIME type string and the normalised codec string, so new MediaResourceType("video/mp4", null) and new MediaResourceType("video/mp4", "avc1.42E01E") are considered distinct entries.

See Also:
  • Constructor Details

    • MediaResourceType

      public MediaResourceType(String mime, String codecs)
      Creates a new MediaResourceType with the given MIME type and optional codec string.
      Parameters:
      mime - the MIME type, e.g. "audio/ogg"; must not be null
      codecs - the normalised codec list, e.g. "opus" or "avc1.42E01E,mp4a.40.2", or null if no codec information is associated with this entry
  • Method Details

    • parse

      public static BrowserVersion.MediaResourceType parse(String mediaResourceType)
      Parses a raw canPlayType() argument string into a MediaResourceType suitable for a set lookup.

      The parsing rules follow the HTML Living Standard:

      1. Blank or whitespace-only input returns null (the caller will map this to "").
      2. If a semicolon (;) is present, everything before it is treated as the MIME type and the remainder is inspected for a codecs parameter.
      3. When a codecs parameter is found its value is normalised: surrounding quotes are stripped, individual codec tokens are trimmed and sorted alphabetically, then re-joined with a comma. This ensures that "vp8, vorbis" and "vorbis,vp8" resolve to the same entry.
      4. A codecs key without a value (e.g. "video/mp4; codecs") is treated as if no codec information were present, yielding a codec of null.
      5. Input without a semicolon is used verbatim as the MIME type with a null codec.
      Parameters:
      mediaResourceType - the raw string passed to HTMLMediaElement.canPlayType(), e.g. "video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\""
      Returns:
      the parsed MediaResourceType, or null if the input is blank (indicating an immediate "" result)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object