Skip to main content
Android Player SDK
Updated over 6 months ago

Prerequires

The minimum deployment version for the player is Android SDK 21+.

Download the Build

Note

Ask your account manager for a link to download the SDK zip file.

Setup

  1. Add library archive to the libs directory in your app module

  2. In your app gradle file add the following code

    dependencies {
    implementation fileTree(dir: 'libs', include: ['*.aar'])
    }

Usage

Add permissions to AndroidManifest.xml:

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

In the AndroidManifest.xml, you'll need to add/merge the configChanges property to every activity that uses the AnyClipPlayer class. This property is required for the AnyClip player to work in fullscreen mode, control keyboard visibility, etc.

<activity android:configChanges="keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout"> ... </activity>

If you want AnyClipPlayer to support picture-in-picture mode, you should set `launchMode` to `singleInstance` and enable PIP in your manifest in your `activity` tag

<activity android:launchMode="singleInstance" android:supportsPictureInPicture="true">...</activity>

and override next methods:

override fun onPictureInPictureModeChanged( isInPictureInPictureMode: Boolean, newConfig: Configuration ) { anyClipPlayer.onPictureInPictureModeChanged(isInPictureInPictureMode) super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig) } override fun onUserLeaveHint() { super.onUserLeaveHint() anyClipPlayer.onUserLeaveHint() }

Adding the AnyClipPlayer view to the layout:

//Add the AnyClip player view to the layout &lt;com.anyclip.sdk.player.AnyClipPlayer android:id="@+id/anyClipPlayer" android:layout_width="match_parent" //or any other size android:layout_height="250dp" /&gt; //or any other size

Setting up the AnyClip player:

This is the parent window, publisherId and widgetId as provided to you by your AnyClip rep.

This function should be used only once with each application run.

anyClipPlayer.setup(this, publisherId, widgetId) Set
//this - parent window, publisherId and widgetId as provided to you by your AnyClip Customer Success Manager
//or
//if you want to setup player in full-page mode
anyClipPlayer.setup(this, publisherId, widgetId){
//Do something when user leaves full-page mode
}

Navigate back from full-page mode:

anyClipPlayer.setup(this, publisherId, widgetId){
//Navigate back
}

Registering the AnyClip player for scroll views.

If the AnyClip player is placed in ScrollView or NestedScrollView, you'll need to register it so it can identify user scrolling and act accordingly:

anyClipPlayer.registerInScrollView(scrollView)

Setting the playlist ID, playlist URL or GUID:

This function is used to set the video or playlist to be played.

anyClipPlayer.playlistId = videoId //for playback of a single video (use the video distribution id) //or anyClipPlayer.playlistId = playlistId //for playback of an entire playlist //or anyClipPlayer.playlistUrl = playlistUrl //for playback of an automatically generated playlist which is based on the content of the webpage in the “playlistUrl”

playerView.videoGUIDs = videoGUIDs // Receives array of GUID strings

Note

Only one of the above parameters (playerView.playlistID / playerView.videoGUIDs) can be supported at once.

Overriding activity/fragment lifecycle methods:

The SDK offers the ability to override 4 functions with a custom functionality of your application.

//Activity lifecycle override fun onResume() { super.onResume() anyClipPlayer.onResume() } override fun onPause() { super.onPause() anyClipPlayer.onPause() } override fun onStop() { super.onStop() anyClipPlayer.onStop() } override fun onDestroy() { super.onDestroy() anyClipPlayer.onDestroy() }

If the AnyClip player is placed in ScrollView or NestedScrollView, you'll need to register it:

anyClipPlayer.registerInScrollView(scrollView)

Adding play and pause functions

To add play and pause functions, use the following:

anyClipPlayer.play() anyClipPlayer.pause()

Handling error events

To handle AnyClip player error events, set the onError callback:

binding.demoAnyClipPlayer.onError = { type, throwable -&gt; when (type) {AnyClipErrorType.NETWORK -&gt; { //handle network errors } AnyClipErrorType.PLAYER -&gt; { //handle player errors } AnyClipErrorType.ADS -&gt; { //handle ads errors } } }

Contact your AnyClip Account manager to get the SDK package.

Event Observing

To handle AnyClipPlayer `Player Events` use `setOnPlayerEventListener` method:

binding.demoAnyClipPlayer.setOnPlayerEventListener(PlayerEventType) { params: PlayerEventsParams -> }

To handle AnyClipPlayer `Ad Events` use `setOnAdEventListener` method:

binding.demoAnyClipPlayer.setOnAdEventListener(AdEventType) { params: AdEventsParams -> }

To handle AnyClipPlayer `Playback Events` use `setOnPlaybackEventListener` method:

binding.demoAnyClipPlayer.setOnPlaybackEventListener(PlaybackEventType) { params: PlaybackEventsParams -> }

To handle AnyClipPlayer `Social Events` use `setOnSocialEventListener` method:

binding.demoAnyClipPlayer.setOnSocialEventListener(SocialEventType) { params: SocialEventsParams -> }

Code example for collecting events:

//Listen to player events

//Volume changed
binding.demoAnyClipPlayer.setOnPlayerEventListener(PlayerEventType.TYPE_VOLUME_CHANGE) { params ->
val volumeLevel = params.value
//Extract another data from `params` object and do anything you need(pass it to your backend, proceed on mobile etc.)
Log.d("PLAYER_EVENT", params.toString())
}
//Player was pause or resumed
binding.demoAnyClipPlayer.setOnPlayerEventListener(PlayerEventType.TYPE_PLAYER_PAUSE) { params ->
val isPaused = params.value
//Extract another data from `params` object and do anything you need(pass it to your backend, proceed on mobile etc.)
Log.d("PLAYER_EVENT", params.toString())
}
//Player was muted or unmuted
binding.demoAnyClipPlayer.setOnPlayerEventListener(PlayerEventType.TYPE_ON_MUTE) { params ->
val isMuted = params.value
//Extract another data from `params` object and do anything you need(pass it to your backend, proceed on mobile etc.)
Log.d("PLAYER_EVENT", params.toString())
}
//Fullscreen is opened/closed
binding.demoAnyClipPlayer.setOnPlayerEventListener(PlayerEventType.TYPE_PLAYER_FULL_SCREEN) { params ->
val isInFullScreen = params.value
//Extract another data from `params` object and do anything you need(pass it to your backend, proceed on mobile etc.)
Log.d("PLAYER_EVENT", params.toString())
}
//Captions were enabled/disabled
binding.demoAnyClipPlayer.setOnPlayerEventListener(PlayerEventType.TYPE_CLOSE_CAPTIONS_CHANGED) { params ->
val isCaptionsDisables = params.value
//Extract another data from `params` object and do anything you need(pass it to your backend, proceed on mobile etc.)
Log.d("PLAYER_EVENT", params.toString())
}


//Listen to ad events

//User clicked on ad
binding.demoAnyClipPlayer.setOnAdEventListener(AdEventType.TYPE_AD_CLICK) { params ->
val adType = params.adType
val isAdMuted = params.isAdMuted
val mediaId = params.clipId
val adIndex = params.adIndex
//Extract another data from `params` object and do anything you need(pass it to your backend, proceed on mobile etc.)
Log.d("PLAYER_EVENT", params.toString())

}
//User skipped an ad
binding.demoAnyClipPlayer.setOnAdEventListener(AdEventType.TYPE_AD_SKIPPED) { params ->
//Get info about ad
val adType = params.adType
val isAdMuted = params.isAdMuted
val mediaId = params.clipId
val adIndex = params.adIndex
//Extract another data from `params` object and do anything you need(pass it to your backend, proceed on mobile etc.)
Log.d("PLAYER_EVENT", params.toString())

}

//25% of ad has passed
binding.demoAnyClipPlayer.setOnAdEventListener(AdEventType.TYPE_AD_Q1) { params ->
val adType = params.adType
val isAdMuted = params.isAdMuted
val mediaId = params.clipId
val adIndex = params.adIndex
//Extract another data from `params` object and do anything you need(pass it to your backend, proceed on mobile etc.)
Log.d("PLAYER_EVENT", params.toString())

}

//50% of ad has passed
binding.demoAnyClipPlayer.setOnAdEventListener(AdEventType.TYPE_AD_Q2) { params ->
val adType = params.adType
val isAdMuted = params.isAdMuted
val mediaId = params.clipId
val adIndex = params.adIndex
//Extract another data from `params` object and do anything you need(pass it to your backend, proceed on mobile etc.)
Log.d("PLAYER_EVENT", params.toString())

}

//75% of ad has passed
binding.demoAnyClipPlayer.setOnAdEventListener(AdEventType.TYPE_AD_Q3) { params ->
val adType = params.adType
val isAdMuted = params.isAdMuted
val mediaId = params.clipId
val adIndex = params.adIndex
//Extract another data from `params` object and do anything you need(pass it to your backend, proceed on mobile etc.)
Log.d("PLAYER_EVENT", params.toString())

}

//Ad was completed
binding.demoAnyClipPlayer.setOnAdEventListener(AdEventType.TYPE_AD_COMPLETE) { params ->
val adType = params.adType
val isAdMuted = params.isAdMuted
val mediaId = params.clipId
val adIndex = params.adIndex
//Extract another data from `params` object and do anything you need(pass it to your backend, proceed on mobile etc.)
Log.d("PLAYER_EVENT", params.toString())

}

Customization

AnyClip player layout customization are available either via xml or programmatically.

XML layout customizations

Attribute

Description

playPauseBtnColor

Sets play/pause button color

fullscreenBtnColor

Sets fullscreen button color

muteBtnColor

ccBtnColor

Sets mute/unmute button color

Sets enable/disable subtitles button color

nextBtnColor

Sets next video button color

trackTitleColor

Sets track title text color

brandLeftTextAppearance

Sets brand left text view appearance

likeBtnColor

Sets like button color

brandRightTextAppearance

Sets brand left text view appearance

forceCCHideButton

Sets force visibility for subtitles button

forceNextHideButton

Sets force visibility for Next button

forceLikeHideButton

Sets force visibility for Like button

Programmatic customizations

/**
* Sets track title color
*
* @param color The color to set for the track title
*/
fun setTrackTitleColor(@ColorInt color: Int)

/**
* Sets play/pause button color
*
* @param color The color to set for the play/pause button
*/
fun setPlayPauseBtnColor(@ColorInt color: Int)

/**
* Sets next button color
*
* @param color The color to set for the next button
*/
fun setNextBtnColor(@ColorInt color: Int)

/**
* Sets mute button color
*
* @param color The color to set for the mute button
*/
fun setMuteBtnColor(@ColorInt color: Int)

/**
* Sets subtitles button color
*
* @param color The color to set for the subtitles button
*/
fun setSubtitlesBtnColor(@ColorInt color: Int)

/**
* Sets fullscreen button color
*
* @param color The color to set for the fullscreen button
*/
fun setFullscreenBtnColor(@ColorInt color: Int)

/**
* Sets brand left textview text appearance
*
* @param resId The resource ID of TextAppearance for brand left textview
*/
fun setBrandLeftTextAppearance(resId: Int)

/**
* Sets brand right textview text appearance
*
* @param resId The resource ID of TextAppearance for brand right textview
*/
fun setBrandRightTextAppearance(resId: Int)

/**
* Sets subtitles fractional text size
*
* @param size The size in percent of full player size for subtitles text
*/
fun setSubtitleFractionalTextSize(size: Float)

/**
* Sets subtitles text style
*
* @param style The style of subtitle text to set
*/
fun setSubtitlesTextStyle(style: CaptionStyleCompat)

/**
* Sets like button color
*
* @param color The color to set for the like button
*/
fun setLikeBtnColor(@ColorInt color: Int)

/**
* Sets force visibility for Captions
* If value is true - CCBtn will be hidden
* if value is false - CCBtn visibility will be set from config
*
* @param forceHideButton True to force hide the Captions button, false to use config settings
*/
fun setForceCcHideButton(forceHideButton: Boolean)

/**
* Sets force visibility for Next button
* If value is true - NextBtn will be hidden
* if value is false - NextBtn visibility will be set from config
*
* @param forceHideButton True to force hide the Next button, false to use config settings
*/
fun setForceNextHideButton(forceHideButton: Boolean)

/**
* Sets force visibility for Like button
* If value is true - LikeBtn will be hidden
* if value is false - LikeBtn visibility will be set from config
*
* @param forceHideButton True to force hide the Like button, false to use config settings
*/
fun setForceLikeHideButton(forceHideButton: Boolean)
Did this answer your question?