Implement XML parsing
You can offload XML parsing to the native parser using the following functions.registerNativePlayerUtils()
To use native parsing, the app must register the native functions. The registerNativePlayerUtils() function registers the app and allows it to call the Native XML parser. If the current platform supports native parsing the function returns true, otherwise false.
boolean isNativeXmlParserSupported(playerName: string, playerVersion: string)
playerName: Specifies the name of the player. The supported values is “shaka”.
playerVersion: Version of the player. For Shaka Player, the supported versions are 4.6.18 or 4.3.6.
Apps must check whether native support for XML parsing is available for a specific player and player version.
nativeParseFromString (manifest, expectedRoot)
The following arguments must be passed for shakaPlayer:
manifest: an ArrayBuffer that contains the downloaded manifest.
expectedRoot: The Expected root element of the parsed XML.
The global.nativeParseFromString() function provides the native implementation for XML parsing and the player calls it after registration.
unloadNativeXmlParser()
The unloadNativeXmlParser() function unloads the native parser cache. Call it when the app is done using the player. You typically make this call as part of Player’s unload() function.
Integration Changes
Shaka Player
Versions4.6.18 and 4.3.6 of Shaka Player support the native XML Parser. For information on using the Shaka Player in your app with all the required patches applied, see Play adaptive content (HLS/DASH) with Shaka Player.
To successfully integrate the XML Parser:
- Make sure that the Shaka Player build has Shaka-Player-changes-for-Dash-nativization.patch that enables the hook to register the XML parsing function.
- As part of the nativization release drop, we are also making a polyfill addition:
DOMParserPolyfill. Make sure that you pick DOMParserPolyfill.ts as part of your app polyfills. - Make sure that you pick the updated release of the MiscPolyfill.ts file as part of your app polyfills. This polyfill has updates to remove reliance on the base
DomParserobject.
- ShakaPlayer v4.6.18: shaka-rel-v4.6.18-r2.11.tar.gz
- ShakaPlayer v4.3.6: shaka-rel-v4.3.6-r2.4.tar.gz
-
If not already defined, define the Shaka Player name and version in src/shakaplayer/ShakaPlayer.ts:
-
Optionally, you can define a flag to enable and disable native XML parsing. As an example, the fifth step to enable native parsing use the following flag.
-
Import and install
DOMParserPolyfill. -
Call
nativeParseFromString(). -
In your ShakaPlayer.ts file, add a
load()function to validate whether the required functionality is available for native XML parsing. After it validates the functionality, it callssetNativeFunctions()to pass the implementation from Shaka Player to the native XML parser by callingnativeParseFromString(). ThesetNativeFunctions()accepts a function as an argument that Shaka Player calls during XML Parsing. -
In your ShakaPlayer.ts file, add an
unload()function to check whether native XML parsing is enabled. If it is, callunloadNativeXmlParserto unload the parser.

