Android SDK reference

Players android SDK reference

This SDK aims at easily embedding Brid videos on your Android application. It's based on ExoPlayer and supports Android 4.1 (API level 16) and later.

Add the SDK to your project

The easiest way to get started using Brid Player is to add it as a gradle dependency. First, you need to add maven repository to the build.gradle file in the root of your project:

repositories {
    mavenCentral()
}

Next, add a gradle compile dependency to the build.gradle file of your app module:

implementation 'tv.brid.sdk:bridsdk:1.0.21'

Edit your AndroidManifest.xml file

Add the following directives to the application tag:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Use in your Activity or Fragment

First, add the FrameLayout holder in your layout where you want player to show.

<FrameLayout
        android:id="@+id/videoHolder"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

Then in your Activity code just instantiate new Brid Player in that layout:

FrameLayout videoHolder = findViewById(R.id.videoHolder);
BridPlayer  bridPlayer = BridPlayerBuilder(this, videoHolder).build();

And load video or playlist:

bridPlayer.loadVideo(playerId, videoId);
bridPlayer.loadPlaylist(playerId, playlistId);

Handling activity/fragment lifecycles

Your activity/fragment should take care of resources on pausing/resuming/destroying:

@Override
    public void onResume() {
        super.onResume();
        bridPlayer.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
        bridPlayer.onPause();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        bridPlayer.release();
    }

Handle screen rotation

For the screen rotation to be handled correctly, you need to add:

    android:configChanges="orientation|screenSize"

to any activity using BridPlayer (in your AndroidManifest.xml)

View debug toast messages

To view debug messages, call the following method after creating BridPlayer object:

    bridPlayer.setDebug(BridPlayer.DEBUG_ALL);

You can set debug level using the following constants: BridPlayer.DEBUG_LOG, BridPlayer.DEBUG_ERRORS, BridPlayer.DEBUG_ADS, BridPlayer.DEBUG_ANALYTICS, BridPlayer.DEBUG_ALL. For example:

    bridPlayer.setDebug(BridPlayer.DEBUG_ADS | BridPlayer.DEBUG_ANALYTICS);

Setting listeners

To monitor player events you can set listener:

    bridPlayer.setListener(new BridPlayer.BridPlayerListener() {
        @Override
        public void onEvent(String status) {
            Log.d("PLAYER EVENT", status);
        }
    });

Example methods

Force autoplay:

    bridPlayer.setAutoPlay(true);

Get index of video currently playing:

    bridPlayer.getCurrentVideo();

Get position in the video:

    bridPlayer.getCurrentPosition();

Other methods:

    bridPlayer.play();
    bridPlayer.togglePlay();
    bridPlayer.pause();
    bridPlayer.previous();
    bridPlayer.next();
    bridPlayer.setFullscreen(<true|false>);
    bridPlayer.seekTo(<seek_position_milliseconds>);
    bridPlayer.setLoadingIndicator(<true|false>);

Serving VPAID video ads

Since Google IMA only supports VAST ad tags, in order to serve other ad tag formats(VPAID) , you need to implement the following code:

bridPlayer = new BridPlayerBuilder(this, videoHolder).build;
bridPlayer.useVPAIDSupport(true);

BridPoster

This class can be used if you want to show fake player (poster image with play button and video title). You might find it useful in situations when you plan to launch video in a new activity, and don't need full featured player there. Consider using this approach when you need to show several players in the same activity or fragment.

BridPoster bridPoster = new BridPoster(this, videoHolder);
bridPoster.loadVideo(335, 186483);
bridPoster.setListener(new BridPoster.BridPosterListener() {
    if (event.equals(BridPoster.EVENT_PLAY_CLICKED)) {
        int playerId = data.getInt("playerId");
        int videoId = data.getInt("videoId");
        int playlistId = data.getInt("playlistId");
    }
});

Specify callback on specific event

You can specify callback function which will be executed when specific event occured in the player.
Here is the complete list of supported callbacks:

Specify callback when loadVideo function is executed

public void loadVideo(int playerId, int videoId, FetchData callback)

Specify callback when loadPlaylist function is executed

public void loadPlaylist(int playerId, int playlistId, FetchData callback)

Specify callback when loadPlaylistForChannel function is executed

public void loadPlaylistForChannel(int playerId, int channelId, int page, int item, FetchData callback)

Specify callback when loadLatestPlaylists function is executed

public void loadLatestPlaylists(int playerId, int page, int item, FetchData callback)

Specify callback when loadPlaylistForTag function is executed

public void loadPlaylistForTag(int playerId, String tagType, int page, int item, FetchData callback)