SandboxedPlayer

public class SandboxedPlayer implements PlayerInterface

This class handles video rendering on a SurfaceView and provides control over playback, audio, events, and readiness state.

Initializes the player with the provided Context and SurfaceView, setting up the necessary resources for rendering video output. The Context is used to access system services or resources, while the SurfaceView serves as the rendering surface for video playback.

Important for Integration Partners: The SurfaceView must be attached to the window (i.e., added to the view hierarchy and laid out) before the player can be considered fully ready, as indicated by getReady. Ensure the SurfaceView is part of your layout and has completed its attachment process before calling methods like loadVideoSource. Use setObserver or check getReady to confirm readiness.

Example usage:

SurfaceView surfaceView = findViewById(R.id.surface_view);
Player player = new SandboxedPlayer(context, surfaceView);
// Wait for SurfaceView attachment and player readiness
player.setObserver(activity, isReady -> {
    if (isReady) {
        player.loadVideoSource("http://example.com/video.mp4", null);
    } else {
        Log.d("Client", "Player not ready yet, waiting for SurfaceView attachment");
    }
});

Constructors

Link copied to clipboard
public void SandboxedPlayer(Context context, SurfaceView surfaceView)
Constructs a new Player instance for media playback.

Functions

Link copied to clipboard
public void addEventListener(PlayerEventListener listener)
Registers an event listener to receive playback and state updates.
Link copied to clipboard
public boolean getAudioRendering()
Checks if audio rendering is currently enabled.
Link copied to clipboard
Retrieves detailed audio track information for this player instance.
Link copied to clipboard
public boolean getBlank()
Checks whether the video output is currently blanked.
Link copied to clipboard
Retrieves decoder statistics for the current playback session.
Link copied to clipboard
Retrieves detailed playback information for this player instance.
Link copied to clipboard
public float getPlaybackSpeed()
Gets the current playback speed.
Link copied to clipboard
public int getPlayerId()
Retrieves the unique identifier for this player instance.
Link copied to clipboard
public boolean getReady()
Checks if the player is ready for use.
Link copied to clipboard
Retrieves detailed text track information for this player instance.
Link copied to clipboard
Retrieves the current video source URI.
Link copied to clipboard
Retrieves detailed video track information for this player instance.
Link copied to clipboard
public float getVolume()
Gets the current audio volume level.
Link copied to clipboard
public boolean isLiveStream()
Checks whether the current video source is a live stream.
Link copied to clipboard
public boolean isMuted()
Checks if the audio is muted.
Link copied to clipboard
public void loadVideoSource(String uri, Bundle config)
Loads a video source for playback.
Link copied to clipboard
public void mute(boolean shouldMute)
Mutes or unmutes the audio.
Link copied to clipboard
public void release()
Releases the player instance and associated resources.
Link copied to clipboard
Unregisters an event listener to stop receiving updates.
Link copied to clipboard
public void removeObserver(Observer<Boolean> observer)
Removes a previously registered observer from monitoring the player's readiness state.
Link copied to clipboard
public void reset()
Ends the current playback session, clearing the video source.
Link copied to clipboard
public void resizeVideo(int width, int height)
Resizes the video output to the specified dimensions.
Link copied to clipboard
public void rotate(float degrees)
Rotates the video output around its center in the virtual 1920x1080 space.
Link copied to clipboard
public void scaleAndTranslate(float scaleX, float scaleY, float translateX, float translateY)
Applies a scale and translation transform to the video output relative to a fixed logical coordinate space of 1920x1080.
Link copied to clipboard
public void seekTo(long position)
Seeks to a specific position in the media.
Link copied to clipboard
public boolean setAudioPreference(Bundle preference)
Applies user preferences for audio playback based on language or other criteria.
Link copied to clipboard
public void setAudioRendering(boolean enabled)
Enables or disables audio rendering.
Link copied to clipboard
public boolean setAudioTrack(int index)
Link copied to clipboard
public void setBlank(boolean blank)
Blanks or unblanks the video output.
Link copied to clipboard
public boolean setCaptionStylePreference(Bundle preference)
Applies user-specified caption styling preferences to the subtitle view.
Link copied to clipboard
public void setObserver(LifecycleOwner owner, Observer<Boolean> observer)
Registers an observer to monitor the player's readiness state.
Link copied to clipboard
public void setPlaybackSpeed(float speed)
Sets the playback speed for this player instance.
Link copied to clipboard
public void setResizeMode(int mode)
Sets the video resize mode.
Link copied to clipboard
public boolean setTextPreference(Bundle preference)
Applies user preferences for subtitle (text) tracks.
Link copied to clipboard
public boolean setTextTrack(int index)
Link copied to clipboard
public boolean setVideoTrack(int index)
Link copied to clipboard
public void setVolume(float level)
Sets the audio volume level.