Data Source Configuration
The PlayerDataSource class defines all necessary information for a single video source within your application.
Source Types
Better Player supports three primary source types:
- Network: Streams video from an external URL.
- File: Plays a video file stored locally on the device.
- Memory: Plays a video from a byte array.
Factory Methods
We recommend using the provided factory methods for initialization:
PlayerDataSource.network(url, ...)PlayerDataSource.file(url, ...)PlayerDataSource.memory(bytes, ...)
Configuration Parameters
Core Parameters
type: TheDataSourceType(Network, File, or Memory).url: The path or URL of the video source.subtitles: A list ofPlayerSubtitlesSourceobjects.headers: A map of custom HTTP headers for network requests.bytes: The byte array for memory sources.
When using PlayerDataSource.memory, providing a videoExtension (e.g., "mp4") is highly recommended. It helps the underlying player engine correctly identify the media type when the byte stream is processed.
Adaptive Streaming (ASMS)
useAsmsSubtitles: Enables HLS/DASH manifest-based subtitles.useAsmsTracks: Enables HLS/DASH manifest-based video tracks.useAsmsAudioTracks: Enables HLS/DASH manifest-based audio tracks.asmsTrackNames: Custom names for HLS/DASH tracks.
[!NOTE] Adaptive streaming formats (HLS and DASH) are fully supported on the Web platform via the embedded Shaka Player.
You can programmatically control adaptive tracks. Use controller.betterPlayerAsmsTracks to retrieve available qualities and controller.setTrack(track) to force a specific one. For multi-language content, use controller.betterPlayerAsmsAudioTracks and controller.setAudioTrack(audioTrack).
Features & Metadata
liveStream: Flag indicating the source is a live stream.resolutions: Alternative resolutions for standard video files.cacheConfiguration: Caching settings for network sources.notificationConfiguration: Settings for native platform notifications.overriddenDuration: A custom duration to return instead of the actual video length.videoFormat: A hint for the video format (e.g.,.m3u8,.mp4).videoExtension: The extension of the video without the dot (useful for memory sources).drmConfiguration: Digital Rights Management settings.bufferingConfiguration: Configuration for video buffering (currently supported on Android).placeholder: A source-specific placeholder widget.