as

Settings
Sign out
Notifications
Alexa
Amazon Appstore
AWS
Documentation
Support
Contact Us
My Cases
Get Started
Design and Develop
Publish
Reference
Support

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 application. This impact is particularly 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.

Copied to clipboard.

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 supporter 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.

The native XML parser is currently supported for ShakaPlayer version 4.6.18 and 4.3.6

Copied to clipboard.

#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.

global.nativeParseFromString() provides the native implementation for XML parsing and is called by the player after registration.

Copied to clipboard.

global.nativeParseFromString(manifest, expectedRoot);

This function must be set as the native function.

unloadNativeXmlParser()

This unloadNativeXmlParser() function unloads the native parser cache. Calls it when the app is done using the player. Typically, this is done as part of Player's unload() function.

Copied to clipboard.

global.unloadNativeXmlParser();

Integration Changes

Shaka Player

The native XML Parser is supported for versions 4.6.18 and 4.3.6 of Shaka player. 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 DOMParserPolyfill.ts is picked as part of your application polyfills.
  • Make sure that the updated release of the MiscPolyfill.ts file is picked as part of your application polyfills. This polyfill has updates to remove reliance on the base DomParser object.

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 the you need to make in src/shakaplayer/ShakaPlayer.ts of your app:

  1. If not already defined, define the shaka player name and version in src/shakaplayer/ShakaPlayer.ts:

Copied to clipboard.

  const playerName: string = "shaka";
  const playerVersion: string = "4.6.18";
  1. Optionally, you can define a flag to enable and disable native XML parsing. As an example, the following flag is used in the fifth step to enable native parsing.

    Copied to clipboard.

     static readonly enableNativeXmlParsing = true;
    
  2. Import and install DOMParserPolyfill.

    Copied to clipboard.

     import DOMParserPolyfill from '../polyfills/DOMParserPolyfill';
    
     // install DOMParser polyfills
     DOMParserPolyfill.install();
    
  3. Call nativeParseFromString().

    Copied to clipboard.

         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;
         }
    
    
  4. In your ShakaPlayer.ts file add a load() function to validate whether the required functionality is available for native XML parsing. After all checks are validated, it calls setNativeFunctions() to pass the implementation from Shakaplayer to the native XML parser by calling nativeParseFromString(). The setNativeFunctions() accepts a function as an argument that is called by Shakaplayer during XML Parsing.

    Copied to clipboard.

       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`);
         }
         ....  
       }
    
  5. In your ShakaPlayer.ts file add an unload() function to check whether native XML parsing is enabled. If it is, call unloadNativeXmlParser to unload the parser.

    Copied to clipboard.

       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 externalized release tarball provides these changes as a reference.


Last updated: Sep 30, 2025