Examples

General example

All examples below differs only in sample BradmaxPlayerDemo.onCreate() method. Sample XML view and general configuration for Activity are the same. Below is presented complete example with full file content, but for next examples only changes in BradmaxPlayerDemo.onCreate() are present.

BradmaxPlayer class extends WebView component, so can be threaded as WebView with additional interface for player control.

Android app Activity class.

package bradmax.com.bradmaxsdk;

import android.content.pm.ApplicationInfo;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;

import bradmax.com.bradmaxsdk.BradmaxPlayer;
import bradmax.com.bradmaxsdk.model.AdMedia;
import bradmax.com.bradmaxsdk.model.Advertisement;
import bradmax.com.bradmaxsdk.model.Media;
import bradmax.com.bradmaxsdk.model.MediaPlaybackState;
import bradmax.com.bradmaxsdk.model.SubtitlesFile;

class BradmaxPlayerDemo extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bradmax_player_full_screen);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            if (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE))
            { WebView.setWebContentsDebuggingEnabled(true); }
        }

        // Adding player with minimal API.
        BradmaxPlayer bp = (BradmaxPlayer) findViewById(R.id.bradmax_player_full_screen_webview);
        bp.loadVideoByUrl("https://bradmax.com/static/video/tos/big_buck_bunny.m3u8", "https://bradmax.com/static/images/startsplash.jpg");
    }
}

Activity view as XML file.

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".BradmaxPlayerDemo">

    <bradmax.com.bradmaxsdk.BradmaxPlayer
        android:id="@+id/bradmax_player_full_screen_webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

</android.support.constraint.ConstraintLayout>

Sample app manifest (AndroidManifest.xml) with configuration for not “re-creating” view on devicde orientation change.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="bradmax.com.bradmaxsdk">
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".BradmaxPlayerDemo" android:configChanges="orientation|screenSize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Player loaded from file.

This example shows how to use custom configured and generated bradmax JavaScript player from bradmax playform. For using it:

  1. You have to download player build from https://bradmax.com/client/panel/ ,
  2. Extract bradmax_player.js file from downloaded ZIP file ,
  3. Save bradmax_player.js file in your app assets path (see: where find assets folder)
  4. Pass relative (relative to assets dir) path to your player into BradmaxPlayer.setLocalBradmaxPlayerAssetPath(String path) method.
BradmaxPlayer bp = (BradmaxPlayer) findViewById(R.id.bradmax_player_full_screen_webview);
bp.setLocalBradmaxPlayerAssetPath("bradmax_player.js");
bp.loadVideoByUrl("https://bradmax.com/static/video/tos/big_buck_bunny.m3u8", "https://bradmax.com/static/images/startsplash.jpg");

Player loaded remotely from bradmax

In this example player is always loading from bradmax platform. If player didn’t change on bradmax platform since last load then it is loaded from WebView cache. When player view or configuration is changed on bradmax platform (eg. adding custom colours and logo for holidays), then new view will be downloaded next time player is opened.

For using remotly loaded player “embed Id” is needed. For obraining it please:

  1. Open https://bradmax.com/client/panel/ and and sign-in.
  2. Open players list page: https://bradmax.com/client/panel/admin/player/list
  3. Click “get embed code” button on selected player.
  4. Check iframe embed code. It should looks like
<iframe src="https://bradmax.com/client/embed-player/6e6040e800a877db910c71d42e95980e7787eceb_4023?mediaUrl=https%3A%2F%2Fbradmax.com%2Fstatic%2Fvideo%2Ftears_of_steel.mp4&title=Tears%20of%20steel&duration=734.097415&splashImgUrl=https%3A%2F%2Fbradmax.com%2Fstatic%2Fimages%2Fstartsplash.jpg" width="600" height="400" frameBorder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>

In iframe src attribute contain URL. Search there for "embed id", which is placed "https://bradmax.com/client/embed-player/[EMBED_ID]?mediaUrl=…". It is just after “/embed-player/” and before "?mediaUrl=".

  1. Use “embed id” in BradmaxPlayer.setRemoteBradmaxPlayerEmbedId() method.

Example:

BradmaxPlayer bp = (BradmaxPlayer) findViewById(R.id.bradmax_player_full_screen_webview);
bp.setRemoteBradmaxPlayerEmbedId("6e6040e800a877db910c71d42e95980e7787eceb_4023");
bp.loadVideoByUrl("https://bradmax.com/static/video/tos/big_buck_bunny.m3u8", "https://bradmax.com/static/images/startsplash.jpg");

Defining playlist with one video with subtitles

Sample below show how to define playlist. Playlist below contains two videos. First use minimal settings - just defining duration, so before starting playback it will be displayed correctly on player start splash screen. Second use single external file for subtitles in Czech language (“cz” - language code).

BradmaxPlayer bp = (BradmaxPlayer) findViewById(R.id.bradmax_player_full_screen_webview);

Media m1 = new Media("https://bradmax.com/static/video/tos/big_buck_bunny.m3u8", "https://bradmax.com/static/images/startsplash.jpg");
m1.duration = 596.0;
bp.addMediaToPlayback(m1);

Media m2 = new Media("https://bradmax.com/static/video/tos/tesla/tesla.m3u8");
m2.duration = 266.0;
m2.subtitlesSets = new SubtitlesFile[1];
m2.subtitlesSets[0] = new SubtitlesFile("cz", "https://bradmax.com/static/video/tos/tesla/tesla_cz.srt");
bp.addMediaToPlayback(m2);

bp.getPlayerConfig().subtitles = "cz";
bp.load();

Setting

bp.getPlayerConfig().subtitles = "cz";

choose Czech (“cz” - ISO language code) language as default. If any media got Czech subtitles, then by default they will be enabled and displayed during media playback.

Implementing player listener

Example below shows how to implement player listener, which will perform some action on player playback event.

BradmaxPlayer bp = (BradmaxPlayer) findViewById(R.id.bradmax_player_full_screen_webview);
bp.setRemoteBradmaxPlayerEmbedId("6e6040e800a877db910c71d42e95980e7787eceb_4023");
Media m1 = new Media("https://bradmax.com/static/video/tos/big_buck_bunny.m3u8", "https://bradmax.com/static/images/startsplash.jpg");
m1.id = "MEDIA_ID_1";
m1.title = "MEDIA_TITLE_1";
m1.duration = 596.0;
bp.addMediaToPlayback(m1);

Media m2 = new Media("https://bradmax.com/static/video/tos/tesla/tesla.m3u8");
m2.id = "MEDIA_ID_2";
m2.title = "MEDIA_TITLE_2";
m2.duration = 266.0;
m2.subtitlesSets = new SubtitlesFile[1];
m2.subtitlesSets[0] = new SubtitlesFile("cz", "https://bradmax.com/static/video/tos/tesla/tesla_cz.srt");
bp.addMediaToPlayback(m2);

bp.getPlayerConfig().subtitles = "cz";
bp.addBradmaxPlayerListener(new BradmaxPlayerListener(bp) {
    @Override
    public void onPlayerLoad() {
        Log.d("BRADMAX_PLAYER", "Player has loaded. Player version:" + this.bradmaxPlayerInstance.getVersion());
    }

    @Override
    public void onVideoCurrentTimeChange(MediaPlaybackState mediaPlaybackState) {
        Log.d("BRADMAX_PLAYER", "Listener - on video time change. time:" + mediaPlaybackState.currentTime);
    }

    @Override
    public void onVideoPaused(MediaPlaybackState mediaPlaybackState) {
        Log.d("BRADMAX_PLAYER", "Listener - on video paused. time: " + mediaPlaybackState.currentTime);
        if(mediaPlaybackState.media != null && mediaPlaybackState.media.subtitlesSets != null) {
            Log.d("BRADMAX_PLAYER", "Listener - on video paused. langCode: " + mediaPlaybackState.media.subtitlesSets[0].languageCode);
        }
    }

    @Override
    public void onDataProviderMediaMetadataData(Media media) {
        Log.d("BRADMAX_PLAYER", "Listener - on video metadata / next video has loaded from playlist. " +
                "Media.id:" + media.id + " Media.title:" + media.title);
    }
});
bp.load();

For full list for supported events please check BradmaxPlayerListener class methods on https://bradmax.com/static/bradmax-android-sdk/latest/javadoc/ .

Simple Ads example with loading ads from remote VMAP file

IMPORTANT NOTE: Enabling Advertisement plugin is required in player configurator. Advertisement plugin is not available in free plan.

Activation of Advertisement plugin:

  1. Open players List (https://bradmax.com/client/panel/admin/player/list)
  2. Select your player
  3. Click on “Advertisement plugins”
  4. Click on “VAST/VMAP” switch for changing to "enable".
BradmaxPlayer bp = (BradmaxPlayer) findViewById(R.id.bradmax_player_full_screen_webview);
bp.setRemoteBradmaxPlayerEmbedId("6e6040e800a877db910c71d42e95980e7787eceb_4023");
Media m1 = new Media("https://bradmax.com/static/video/tos/big_buck_bunny.m3u8", "https://bradmax.com/static/images/startsplash.jpg");
m1.id = "MEDIA_ID_1";
m1.title = "MEDIA_TITLE_1";
m1.duration = 596.0;
bp.addMediaToPlayback(m1);

bp.getPlayerConfig().advertisement = new Advertisement();
bp.getPlayerConfig().advertisement.vmap = "https://bradmax.com/static/a/vmap.google.xml";
bp.addBradmaxPlayerListener(new BradmaxPlayerListener(bp) {
    @Override
    public void onPlayerLoad() {
        Log.d("BRADMAX_PLAYER", "Player has loaded. Player version:" + this.bradmaxPlayerInstance.getVersion());
    }

    @Override
    public void onDataProviderAdMetadataData(AdMedia adMedia) {
        Log.d("BRADMAX_PLAYER", "Listener - adMedia info" +
                " AdMedia.adId:" + adMedia.adId +
                " Ad:" + adMedia.currentOrderNumber + "/" + adMedia.totalNumber);
    }
});
bp.load();

Volume control example

Sample below shows how to change player volume. In sample is BradmaxPlayerSampleTimer used, which is available in Bradmax SDK library.

BradmaxPlayer bp = (BradmaxPlayer) findViewById(R.id.bradmax_player_full_screen_webview);
bp.setRemoteBradmaxPlayerEmbedId("6e6040e800a877db910c71d42e95980e7787eceb_4023");
Media m1 = new Media("https://bradmax.com/static/video/tos/big_buck_bunny.m3u8");
m1.id = "MEDIA_ID_1";
m1.title = "MEDIA_TITLE_1";
m1.duration = 596.0;
bp.addMediaToPlayback(m1);

bp.addBradmaxPlayerListener(new BradmaxPlayerListener(bp) {
    @Override
    public void onPlayerLoad() {
        Log.d("BRADMAX_PLAYER", "Player has loaded. Player version:" + this.bradmaxPlayerInstance.getVersion());
    }

    @Override
    public void onControlVolumeChange(float volume) {
        Log.d("BRADMAX_PLAYER", "Listener - onControlVolumeChange volume:" + volume);
    }
});
bp.load();

// Autoplay player - just for demonstration.
bp.play();

// Set 30% of volume after 10 seconds since player creation.
BradmaxPlayerSampleTimer t = new BradmaxPlayerSampleTimer(bp, 10000) {
    public void onFinish() {
        player.setVolume(0.3);
    }
};
t.start();

// Set full volume for player after 15 seconds since player creation.
BradmaxPlayerSampleTimer t2 = new BradmaxPlayerSampleTimer(bp, 15000) {
    public void onFinish() {
        player.setVolume(1.0);
    }
};
t2.start();

Live streaming transmission example

Sample below shows how to setup player for live stream transmission. We recommend to use endDate in LiveStream object settings for suggesting player, when end of transmission is expected. When it is used, then player will try to reconnect to transmission in case of troubles before defined end of stream. In case of any network issue with transmission afted defined endDate player assumes that transmission is over.

If no thankYouImageUrl is defined, then default start splash image is used. We recommend to use custom one, to inform users that transmission is over.

BradmaxPlayer bp = (BradmaxPlayer) findViewById(R.id.bradmax_player_full_screen_webview);

Media m = new Media("https://example.com/index.m3u8", "https://bradmax.com/static/images/startsplash.jpg");

// Setting only custom "thank you" end splash image.
m.liveStream = new LiveStream();
m.liveStream.thankYouImageUrl = "https://bradmax.com/static/images/thankyou_endsplash.jpg";

// Setting end splash image and end of transmission planned time.
//m.liveStream = new LiveStream("2020-06-16T20:00:00Z", "https://bradmax.com/static/images/thankyou_endsplash.jpg");

bp.addMediaToPlayback(m);
bp.load();