XML Parser for DASH Content
Media Source Extensions (MSE) players such as Shaka Player and Bitmovin perform CPU-intensive tasks in JavaScript such as parsing multiple Dash media manifests, which can impact UI responsiveness and fluidity of the app. This impact is noticeable during Live TV playback with large DVR windows that has large manifest sizes. This documentation explains how to optimize performance by leveraging the native implementation of XML Parser.
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.
global.registerNativePlayerUtils();
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.
#Shaka Player
if(global.isNativeXmlParserSupported("shaka", "4.6.18")) {
console.log('platform supports native Xml parser for this version of shaka player');
}
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.
global.nativeParseFromString(manifest, expectedRoot);
You must set the function as the native function.
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.
global.unloadNativeXmlParser();
Integration Changes
Shaka Player
Versions 4.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.
These changes are included starting with the following versions of the Shaka Player:
- 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
Changes that you must make in src/shakaplayer/ShakaPlayer.ts of your app:
-
If not already defined, define the Shaka Player name and version in src/shakaplayer/ShakaPlayer.ts:
const playerName: string = "shaka"; const playerVersion: string = "4.6.18"; -
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.
static readonly enableNativeXmlParsing = true; -
Import and install
DOMParserPolyfill.import DOMParserPolyfill from '../polyfills/DOMParserPolyfill'; // install DOMParser polyfills DOMParserPolyfill.install(); -
Call
nativeParseFromString().nativeParseFromString(manifest: ArrayBuffer, expectedRoot: string) :Array<shaka.hls.Playlist> { console.log('shaka: nativeParseFromString+'); console.log('shaka: nativeParseFromString: expectedRoot ', expectedRoot); const playlist = global.nativeParseFromString(manifest, expectedRoot); console.log('shaka: nativeParseFromString-'); return playlist; } -
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.load(content: any, autoplay: boolean): void { .... // Add below code snippet in load() if (ShakaPlayer.enableNativeXmlParsing) { // For Dash content if (global.registerNativePlayerUtils && shaka.util.XmlUtils.setNativeFunctions) { if (!global.isNativeXmlParserSupported) { console.log("shaka: isNativeXmlParserSupported not registered."); } if (global.isNativeXmlParserSupported && global.nativeParseFromString) { const isNativeXmlParserSupported = global.isNativeXmlParserSupported(playerName, playerVersion); if (isNativeXmlParserSupported) { console.log('shaka: setting DASH native functions'); shaka.util.XmlUtils.setNativeFunctions(this.nativeParseFromString); } else { console.log('shaka: nativeXMLParser not supported for player version'); } } else { console.log('shaka: native func not set even after register, skipping it'); } } else { console.log(`shakaplayer: DASH native offload not enabled! registerNativePlayerUtils: ${!!global.registerNativePlayerUtils}, DASH::setNativeFunctions: ${!!shaka.util.XmlUtils.setNativeFunctions}`); } } else { console.log(`shaka: native Xml playlist parsing is disabled`); } .... } -
In your ShakaPlayer.ts file, add an
unload()function to check whether native XML parsing is enabled. If it is, callunloadNativeXmlParserto unload the parser.unload() : void { .... // Add below code snippet in unload() if (ShakaPlayer.enableNativeXmlParsing && global.isNativeXmlParserSupported && global.nativeParseFromString && global.unloadNativeXmlParser) { const isNativeXmlParserSupported = global.isNativeXmlParserSupported(playerName, playerVersion); if (isNativeXmlParserSupported) { console.log('shakaplayer: unloading native Xml parser'); global.unloadNativeXmlParser(); console.log('shakaplayer: unloaded native Xml parser'); } } .... }
The ShakaPlayer.ts source file in the externalized release tarball provides these changes as a reference.
Last updated: Feb 12, 2026

