Class BroadcastPlayer

    • Method Detail

      • setTimeshiftMode

        public void setTimeshiftMode​(boolean enabled)
        Set whether the player should be configured for timeshift mode. Timeshift mode should be enabled only if seeking in a live broadcast is necessary. Timeshift mode allows playback of any part of the broadcast, but involves much higher latency on a live broadcast, and playback performance may suffer on very long broadcasts. In timeshift mode, the player will not repeatedly seek to the live edge. This can only be set before the first call to load().
        Parameters:
        enabled - True to configure the player for timeshift mode, false otherwise.
      • setLatencyMode

        public void setLatencyMode​(BroadcastPlayer.LatencyMode mode)
        Set whether the player should prioritize low latency or playback with less interruptions. In LOW latency mode, the player prioritizes low latency and is quick to start initial playback. In HIGH latency mode, the player uses larger buffers and will buffer slightly more initially, to minimize the risk of playback interruptions due to network fluctuations.

        This option currently only affects live broadcasts. This method can only be used before the first call to load().

        Parameters:
        mode - A BroadcastPlayer.LatencyMode. Default is BroadcastPlayer.LatencyMode.LOW.
      • setSurfaceView

        public void setSurfaceView​(SurfaceView surfaceView)
        Set the SurfaceView where video will be shown. When a SurfaceView is provided, the BroadcastPlayer will attempt to keep the screen on while video is playing. If the provided SurfaceView is a SurfaceViewWithAutoAR and is allowed to set its own dimensions, the BroadcastPlayer will automatically set its aspect ratio.
        Parameters:
        surfaceView - A SurfaceView (preferably a SurfaceViewWithAutoAR) where the video will be shown.
      • setSurface

        public void setSurface​(Surface surface)
        Set the Surface where video should be shown. NOTE: when using this method, you are fully responsible for setting a fully created Surface and clearing it before the Surface is destroyed. You must also keep the screen awake. For most use cases setSurfaceView(SurfaceView) or setTextureView(TextureView) are better.
        Parameters:
        surface - Surface where the video will be shown.
      • load

        public void load()
        Starts loading the requested Bambuser broadcast for playback. This method is only valid when the player is in the PlayerState.CONSTRUCTION state.
      • close

        public void close()
        Immediately stops any playback and frees all related system resources. Make sure to call this when the player instance is no longer needed, or you may experience background playback. Starting new players without closing old ones will eventually deplete all available system resources. After this call, this BroadcastPlayer instance can not be used.
      • isTypeLive

        public boolean isTypeLive()
        Returns the type of the broadcast. Available after the BroadcastPlayer has loaded the initial data (state changed from LOADING to BUFFERING/PLAYING). The value is not updated later.
        Returns:
        true if the loaded broadcast is a live broadcast, false otherwise.
      • getBroadcastId

        public String getBroadcastId()
        Returns the id of the loaded broadcast. Available after the BroadcastPlayer has loaded the initial data (state changed from LOADING to BUFFERING/PLAYING).

        For example when a player is initiated with a virtual resource uri, this method can be used to determine which broadcast the player loaded.

        Returns:
        A broadcast id string when the player has loaded a broadcast. Empty string otherwise.
      • getState

        public PlayerState getState()
        Get the current state
        Returns:
        One of the values defined in PlayerState.
      • getDuration

        public int getDuration()
        Get the duration of the currently playing video. Returns -1 when duration is unknown, for example for live broadcasts without timeshift mode. Duration is always available for archived broadcasts and for live broadcasts viewed in timeshift mode.
        Specified by:
        getDuration in interface MediaController.MediaPlayerControl
        Returns:
        Current video length in milliseconds. -1 if duration is unavailable.
      • getCurrentPosition

        public int getCurrentPosition()
        Get the current play position in a video. The current position is always available for archived broadcasts and for live broadcasts viewed in timeshift mode. It may also be available for live broadcasts, depending on video format.
        Specified by:
        getCurrentPosition in interface MediaController.MediaPlayerControl
        Returns:
        Current position in milliseconds. 0 if position is unavailable.
      • seekTo

        public void seekTo​(int position)
        Seek to desired position. If the player has not loaded an archived seekable video (or a live video in timeshift mode), this method does nothing.
        Specified by:
        seekTo in interface MediaController.MediaPlayerControl
        Parameters:
        position - Desired playback position in milliseconds.
      • getEndToEndLatency

        public LatencyMeasurement getEndToEndLatency()
        Get the current measured end-to-end latency when playing a live broadcast. During a live broadcast, the Broadcaster and BroadcastPlayer can synchronize their clocks with the servers and the player can determine the current end-to-end latency.

        End-to-end latency measurements may take a while before appearing and may not be available for all broadcasts, as it requires successful clock synchronization and needs to be supported by the broadcast source too.

        Returns:
        A LatencyMeasurement object containing the current end-to-end latency and the total uncertainty of the broadcaster and player. null if end-to-end latency measurement is currently unavailable.
      • canPause

        public boolean canPause()
        Implementation for the MediaController.MediaPlayerControl interface, determining whether the broadcast can be paused/resumed.
        Specified by:
        canPause in interface MediaController.MediaPlayerControl
        Returns:
        True if the BroadcastPlayer has loaded an archived broadcast (or a live broadcast in timeshift mode) and is in a state that supports pause/play/seeking, false otherwise.
      • canSeekBackward

        public boolean canSeekBackward()
        Implementation for the MediaController.MediaPlayerControl interface, determining whether the BroadcastPlayer currently supports seeking.
        Specified by:
        canSeekBackward in interface MediaController.MediaPlayerControl
        Returns:
        True if the BroadcastPlayer has loaded an archived broadcast (or a live broadcast in timeshift mode) and is in a state that supports pause/play/seeking, false otherwise.
      • canSeekForward

        public boolean canSeekForward()
        Implementation for the MediaController.MediaPlayerControl interface, determining whether the BroadcastPlayer currently supports seeking.
        Specified by:
        canSeekForward in interface MediaController.MediaPlayerControl
        Returns:
        True if the BroadcastPlayer has loaded an archived broadcast (or a live broadcast in timeshift mode) and is in a state that supports pause/play/seeking, false otherwise.
      • getAudioSessionId

        public int getAudioSessionId()
        Returns the current audio session id if a broadcast has been loaded.
        Specified by:
        getAudioSessionId in interface MediaController.MediaPlayerControl
        Returns:
        The current audio session id. 0 if no broadcast has been loaded or playback has failed.
      • setAudioVolume

        public void setAudioVolume​(float volume)
        Set the desired audio volume for this BroadcastPlayer instance. The gain is linear from 0.0 to 1.0. UI controls should be scaled logarithmically.

        This method can be used at any time, and is suitable for silencing individual player instances, as it does not affect the global audio stream volume.

        Parameters:
        volume - float value between 0.0 and 1.0. The default is 1.0.
      • start

        public void start()
        Resume playback of a PAUSED broadcast, or restart playback of a COMPLETED archived broadcast. This method is only applicable when an archived broadcast (or a live broadcast in timeshift mode) has been loaded.
        Specified by:
        start in interface MediaController.MediaPlayerControl