Vastxml.java
Overview
`Vastxml.java` is a utility class in the `com.tubitv.media.demo.vpaid_model` package that provides the raw VAST (Video Ad Serving Template) XML string used for VPAID (Video Player Ad-Serving Interface Definition) video ad playback within the media player system. The class contains a single static method that returns a hardcoded VAST XML document representing an ad configuration.
This XML data is essential for initializing and playing VPAID-compliant video ads inside an Android WebView, enabling interactive and trackable ad experiences. The class acts as a centralized source of VAST XML content, which is injected into the WebView-based VPAID player via JavaScript interfaces.
Class: Vastxml
Description
Contains a static VAST XML string representing a sample video ad.
Provides a method to retrieve this XML string safely.
Serves as the VAST ad data source for VPAID ad playback components.
Package
package com.tubitv.media.demo.vpaid_model;
Fields
Field Name | Type | Description |
|---|---|---|
adXmlBody | String | Private static final field containing the VAST XML ad as a string literal. |
The
adXmlBodyfield is initialized with a placeholder string"dsfsdf". However, it is not directly used in the current implementation ofgetAdXmlBody()except for an emptiness check.
Methods
public static String getAdXmlBody()
public static String getAdXmlBody()
Purpose:
Returns the full VAST XML document as aStringwhich describes the video ad to be played.Behavior:
Checks if the
adXmlBodyis empty using Android'sTextUtils.isEmpty()method.If empty, returns an empty string.
Otherwise, returns a hardcoded, large VAST XML string literal embedded directly in the method.
Parameters: None
Returns:
String— The complete VAST XML document as a string.Usage Example:
String vastXml = Vastxml.getAdXmlBody();
// vastXml now contains the full VAST XML document for the ad
Notes:
There is commented-out code suggesting a future or alternative implementation where
adXmlBodycould be a Base64-encoded string that is decoded to UTF-8. This is currently disabled.The method currently returns a static XML string that includes ad metadata, creatives, tracking URLs, media files, and extensions conforming to VAST 3.0 specification.
The XML data is extensive and includes multiple nested elements such as
<Ad>,<InLine>,<Creatives>,<MediaFiles>, and<Extensions>.
Important Implementation Details
Static VAST XML String:
The class embeds a large VAST XML document directly as a string literal inside thegetAdXmlBody()method. This XML contains detailed ad metadata such as ad system, creative files, impression tracking, and event tracking URLs.Commented-out Base64 Decoding:
The code contains commented-out logic to decodeadXmlBodyfrom Base64, which would allow storing the XML in encoded form. This is currently unused but indicates a potential future enhancement to load XML dynamically or securely.Use of Android's
TextUtils:
The method usesTextUtils.isEmpty()to check if theadXmlBodyfield is empty, ensuring robustness against null or empty values.No Dynamic Fetching:
The XML is static and hardcoded, making this class suitable for demo, testing, or fallback scenarios. In production, VAST XML would typically be retrieved from an ad server.
Interaction with Other System Components
VPAID WebView Client (
TubiVPAID):
TheTubiVPAIDclass, which manages the WebView-based playback of VPAID ads, callsVastxml.getAdXmlBody()to retrieve the VAST XML data. This XML is then injected into the WebView's JavaScript environment so that the VPAID JavaScript player can parse and execute the ad.Finite State Machine (FSM) Player:
The FSM player controls ad playback states and relies on VPAID clients to handle interactive ads. The static XML provided by this class acts as the source ad data for these playback states.JavaScript Interface:
The WebView hosting the VPAID player accesses this XML through a JavaScript interface method exposed by the native code. This method returns the XML string obtained fromVastxml.Ad Tracking and Reporting:
The extensive tracking URLs in the VAST XML enable the system to monitor ad impressions, quartile completions, clicks, errors, and other ad events, facilitating accurate reporting and analytics.
Example Usage in System
// Within the VPAID client managing WebView:
@JavascriptInterface
public String getVastXml() {
return Vastxml.getAdXmlBody();
}
This method is called by JavaScript running inside the WebView to retrieve the VAST XML ad data for initializing the ad playback.
Visual Diagram: Class Structure
classDiagram
class Vastxml {
-adXmlBody: String
+getAdXmlBody(): String
}
Summary
Vastxmlis a simple utility class providing a static VAST XML ad payload.It encapsulates the ad data logic separately from the VPAID playback logic.
The class currently returns a hardcoded VAST XML string representing a fully defined video ad with tracking and media file information.
It plays a critical role in supplying the ad metadata needed by the VPAID WebView client to execute interactive video ads.
While minimalistic, it supports extensibility for future dynamic or encoded XML handling.
Appendix: About VAST XML in This Class
VAST 3.0 Format:
The XML complies with VAST 3.0 specification, which structures the ad data including<Ad>,<InLine>,<Creatives>,<MediaFiles>, and<TrackingEvents>.Media Files:
The XML references JavaScript VPAID media files necessary for interactive ad playback.Tracking URLs:
Multiple tracking URLs are embedded to cover events like start, firstQuartile, midpoint, thirdQuartile, complete, impression, click, mute/unmute, pause/resume, fullscreen, etc.Ad Parameters:
JSON-encoded ad parameters are included within CDATA sections, providing metadata for ad identification and targeting.
This concludes the detailed documentation for `Vastxml.java`.