- Directly using the W3C Media APIs: This is a suitable approach when playing flat (non-ABR) content.
- Building a custom JavaScript player using the W3C Media APIs: Developers can create their own proprietary JavaScript-based media player by directly integrating the relevant W3C Media APIs.
- Integrating existing JavaScript player libraries: There are several popular JavaScript media player libraries available, such as Shaka Player, hls.js, dash.js, and Bitmovin Player. Developers can choose to integrate one of these existing players, which provide abstraction over the underlying W3C Media APIs.
URL mode
URL mode is designed for playing non-adaptive content formats such as MP4 and MP3 files. In this mode, you set the media source directly using theHTMLMediaElement.src attribute.
Audio-only playback example
The following example demonstrates a simple audio-only playback implementation.- Creates a VideoPlayer instance using
useRef() - Initializes the player and sets autoplay to true so playback starts automatically
- Sets the audio source URL using the src attribute
- Renders a simple UI with text indicating audio playback
Video playback example
The following example demonstrates video playback in URL mode.- Creates an instance of
VideoPlayerusinguseRef() - Implements
onSurfaceViewCreatedcallback that:- Initializes the video player
- Connects the player to the surface using
setSurfaceHandle() - Enables autoplay
- Sets the video source URL
- Implements
onSurfaceViewDestroyedcallback that:- Disconnects the surface handle
- Deinitializes the player
- Cleans up the player reference
- Renders the component with lifecycle callbacks
- Surface management: Video playback requires managing the KeplerVideoSurfaceView lifecycle through onSurfaceViewCreated and onSurfaceViewDestroyed callbacks
- Surface handle: Video playback needs to connect the player to the rendering surface using setSurfaceHandle()
- Cleanup: Video playback requires proper cleanup of surface handles and deinitialization when the surface is destroyed
MSE mode
Use the MSE (Media Source Extensions) mode to play adaptive bitrate content, such as HLS or DASH streams. This mode requires integrating a JavaScript-based media player library that handles downloading and managing adaptive media streams.Choosing a media player
Several JavaScript media player libraries support MSE, including:- Open-source: Shaka Player, Dash.js, HLS.js, Bitmovin, Video.js
- Commercial: Bitmovin, and other proprietary solutions
MSE streaming example with Shaka Player
The following example demonstrates streaming DASH content using Shaka Player.- Configures content: Defines the DASH manifest URL and DRM settings (if needed)
- Sets player options: Enables adaptive bitrate (ABR) streaming
- Initializes video player: Creates and initializes the VideoPlayer instance when the surface is created
- Integrates Shaka Player: Creates a ShakaPlayer instance and loads the content
- Manages captions: Sets up the KeplerCaptionsView component for subtitle rendering
- Handles cleanup: Properly unloads the player and deinitializes resources when the surface is destroyed
Building and testing
Use the Vega SDK to build the app and run it on a device or simulator. For detailed instructions, see the following topics:Important: URL mode vs MSE mode
URL mode is not supported for adaptive streaming. While URL mode may work for some basic adaptive content in limited cases, its behavior is not guaranteed and it is not officially supported for adaptive bitrate streaming. Use URL mode only for:- Non-adaptive content (MP4, MP3 files) • Simple playback scenarios
- Adaptive bitrate content (HLS, DASH streams)
- DRM-protected content
- Live streaming
- Advanced playback features
Next steps
When choosing a player, consider factors such as the supported features, performance, community support, and licensing. Review the documentation and examples provided by each player to determine the best fit for your application’s requirements. Once you’ve selected a player, refer to their integration guides to learn how to set it up and use it within your React Native media player app. Some of these players are already ported, please see the following:- Playing Adaptive Streaming Content (HLS/DASH) with Shaka Player
- Play adaptive content using Dash.js Player
- Play adaptive content using Hls.js Player

