Veeplay Android SDK 3.2.0-rc1 API reference

Veeplay Player for Android Reference

About


The Veeplay Media Player allows you to:

  • Create playlists of synchronized videos and overlays
  • Configure a playlist from an external JSON file, an equivalent HashMap structure or directly via code attributes
  • Create custom, native overlays
  • Automatically configure ad linear inserts (pre, mid and post rolls) as well as nonlinear inserts (banner overlays), VAST 1.0, 2.0, 3.0 and VMAP 1.0 compliant
  • Create custom player skins, brand player with logo, insert overlay bugs, customize player controls
  • Track video and overlay lifecycle events in real-time, as rendered

Requirements

Veeplay 3.2.0 needs:

  • compileSdk 36 or higher and Android Gradle Plugin 8.6.0 or higher
  • minSdk 24 or higher
  • Core library desugaring enabled
  • Java 11 source and target compatibility
  • Kotlin standard library 2.2.10 (comes in at compile scope)

Upgrading from 3.1.26? See MIGRATION-3.2.md and CHANGELOG.md in the repository.


Android Studio Project Integration

    
        repositories {
            mavenCentral()
            maven {
            url "https://s3-eu-west-1.amazonaws.com/android.veeplay.com/releases"
            }
        }
    
    
        android {
            compileSdk 36
            defaultConfig {
                minSdk 24
            }
            compileOptions {
                sourceCompatibility JavaVersion.VERSION_11
                targetCompatibility JavaVersion.VERSION_11
                coreLibraryDesugaringEnabled true
            }
        }
    
    
        dependencies {
            implementation 'com.veeplay:veeplay-player-android:3.2.0'
            coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.5'
            // optional, only for Google Cast:
            implementation 'com.veeplay:veeplay-player-android-cast:3.2.0'
        }
    

Simple Usage Example


Import the Player, Media Builder and media event classes:
    
import com.appscend.media.APSMediaBuilder;
import com.appscend.media.APSMediaPlayer;
import com.appscend.media.events.APSMediaEvent;
    
Create a new APSMediaBuilder instance and configure it from remote JSON. The callback runs on the main thread when the configuration has loaded. mediaUnits() fetches the VMAP when the configuration has ads.vmap, and mediaUnits(true) also loads the preroll ads, so do not call it on the main thread in either case: build the playlist on a background executor (buildExecutor) and post playMediaUnits() to a Handler on the main Looper (main):
    
final APSMediaBuilder builder = new APSMediaBuilder();
try {
        builder.configureFromURL(new
URL("http://domain.tld/player.json"), ok -> {
                if (!ok) return;
                buildExecutor.execute(() -> {
                        ArrayList<APSMediaEvent> units = builder.mediaUnits();
                        main.post(() -> {
                                if (!isFinishing() && !isDestroyed() && APSMediaPlayer.isInitialized())
                                        APSMediaPlayer.getInstance().playMediaUnits(units);
                        });
                });
        });
        }
catch (MalformedURLException e) {
e.printStackTrace();
}
    
Optionally, set the debugMode flag to true to enable logCat logging:
    
builder.debugMode=true;
    
Create a new APSMediaPlayer instance and set the size of the video player. If your app uses Google Cast, call setGoogleCastEnabled() as well:
    
APSMediaPlayer.getInstance().init(this, false);
APSMediaPlayer.getInstance().setSize(720, 1280);
    
Add the media player to a layout and add the layout to the current Activity:
    
RelativeLayout layout = new RelativeLayout(this);
layout.setBackgroundColor(Color.WHITE);
layout.addView(APSMediaPlayer.getInstance().viewController());
setContentView(layout);
    
Play content as configured. This is the call posted to the main thread above, with the playlist built off the main thread:
    
APSMediaPlayer.getInstance().playMediaUnits(units);
    
You will also probably want to link activity events (onPause, onResume) to player events. The below examples will pause and start the player when existing, entering the activity and will cancel the current running units list when the back button is pressed.
Also, when the device is rotated, the player will resize accordingly.
If the Activity can be recreated while a playlist is still processing, check APSMediaPlayer.isInitialized() && APSMediaPlayer.getInstance().isProcessing() in onCreate(): call init() and re-attach viewController(), but do not play the playlist again.
    
@Override
protected void onPause() {
        super.onPause();
        APSMediaPlayer.getInstance().onActivityPaused();
}
@Override
protected void onResume() {
        super.onResume();
        APSMediaPlayer.getInstance().onActivityResumed();
}
// in onCreate():
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
        @Override
        public void handleOnBackPressed() {
                APSMediaPlayer.getInstance().finish();
                MyActivity.this.finish();
        }
});
@Override
public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        APSMediaPlayer.getInstance().computeSurfaceSize();
        APSMediaPlayer.getInstance().orientationWillChange();
}
    
You do not need to declare any permissions for the player: INTERNET and the other permissions its dependencies need are added to your merged manifest automatically. The player's fullscreen mode can switch to landscape; to keep your app available on devices without a landscape screen, mark the feature as optional:
    
<uses-feature android:name="android.hardware.screen.landscape" android:required="false" />
    
The activity that handles clickthroughs (com.appscend.utilities.WebBrowser) is declared in the SDK manifest. You do not need to declare it.
If you use Google Cast, add the Cast options provider to your application element:
    
<meta-data
android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME"
android:value="androidx.media3.cast.DefaultCastOptionsProvider" />