Table of content

Android SDK (Legacy)

Deprecated SDK:

This is the legacy Android SDK documentation. If you’re getting started with your integration, please use the Android SDK documentation available in our main Player documentation.

Date: October 2023


The SDK is a thin wrapper around a WebView that allows to easily embed Dailymotion videos into your Android application. We recommend using the SDK rather than the video URL in a standard webView, as it gives you more controls of the player and its better for tracking purposes. Our Android SDK is open source and you can get all the required information plus a sample app on our GitHub.

The SDK supports Android 5.0.x (API level 21+) and it is fully in Kotlin, If your project is still in JAVA, please add the Kotlin dependencies:
https://developer.android.com/kotlin/add-kotlin

How to use

Note:

The SDK requires the `minSdkVersion` of the app to be 21+. Implementation ‘com.dailymotion.dailymotion-sdk-android:sdk:0.2.12’

  1. The easiest way to integrate the SDK is by adding it to your application build.gradle file.
  2. The PlayerWebView is the main SDK component that allows you to load videos easily into your android environment. Add the component to the selected layout which will display the player. To load the video without autoplay, you can use the setPlayWhenReady(false) method
<com.dailymotion.android.player.sdk.PlayerWebView 
android:id="@+id/dm_player_web_view" 
android:layout_width="match_parent" 
android:layout_height="215dp"> 
</com.dailymotion.android.player.sdk.PlayerWebView>
  1. Initialize the player in your selected activity, reference the PlayerWebView and use one of the load methods available. You can use the load() method, which will initialize a default player config, load the player and start playing the selected video. Or it is also possible to use the initialize() method to load the player with a custom config using any available player params.
lateinit var playerWebView: PlayerWebView override fun onCreate(savedInstanceState: Bundle?) { 
super.onCreate(savedInstanceState) setContentView(R.layout.screen_sample); 
playerWebView = findViewById(R.id.playerWebview) 
val params = mapOf("video" to "x84sh87") 
playerWebView.load(loadParams = params);
 } 

Using player parameters

In order to customize the player, pass in player parameters to your player instance. Create a Map interface, add an entry of the chosen player parameters into the map along with its associated value, then pass the Map into the initialize() method. To load multiple videos while keeping the same player instance and config, use the load() method after player initialization.

val params = mapOf(
    "ui-highlight" to "fff",
    "controls" to "false"
)
dailymotionVideoPlayer.initialize("https://www.dailymotion.com/embed/", params = params, emptyMap())

Player Parameters for Android SDK

Use the below parameters to customize your player via the iframe or SDK embed.

ParameterInfoType
autoplayAutomatically attempt to start playback with sound, if it is blocked by the browser, the player will force the video muteBoolean
controlsWhether to display the player controls, true by defaultBoolean
idID of the player unique to the page to be passed back with all API messagesString
muteWhether to mute the videoBoolean
qualitySpecify the suggested playback quality for the videoNumber
sharing-enableWhether to display the sharing buttonBoolean
startSpecify the time (in seconds) from which the video should start playingNumber
subtitles-defaultSpecify the default selected subtitles languageString
syndicationPass your syndication key to the playerString
ui-highlightChange the default highlight color used in the controls (hex value without the leading #). Color set in the Dailymotion Studio will override this paramString
ui-start-screen-infoWhether to show video information (title and owner) on the start screenBoolean
playlistSpecify a playlist ID to populate the Up Next Queue with videos from a playlistString
fullscreenWhether to display the fullscreen buttonBoolean
scaleModeSpecify the default focus of the player in order to reframe and refocus on a specific area in the video. To be used for scaling and repurposing of videos between different aspect ratios for example landscape to portrait. Values ( ‘fit’, ‘fill’, ‘fillLeft’, ‘fillRight’, ‘fillTop’, ’fillBottom’ )String
loopWhether to loop a video or an entire playlist. A video embed will start over again automatically. A playlist embed will start to play from the first item in the playlist after the entire playlist has finishedBoolean

Methods

Once the SDK and the Player are loaded you can use the Player API to control the player. You have full access to all player methods and there are also methods supplied in the Android SDK that return specific player properties.

Note:

When the player is ready to take API commands it will send ‘ApiReadyEvent’ event.

dailyMotionVideoPlayer.pause();
NameInfo
load(String)Calls the initialize method, loads the player with a video associated with the video id (e.g. x7tgad0)
initialize(String, Map<String, String>, Map<String, String>)Loads the player with base string URL of player’ https://dailymotion.com/embed/‘ accompanied by a MAP interface of required player parameter values
finishedInitialization (String, Map<String, String>, Map<String, String>)Loads the player with a given URL, parameters and advertising ID
play()Starts or resumes video playback
pause()Starts or resumes video playback
setFullScreenButton(Boolean)Enters fullscreen mode when true and controls player fullscreen button state. The method should be utilized in association with the native fullscreen functionality in app
setPlayerEventListener(Eventlistener)Add a listener which will be called when the Android system WebView can an error
unmute()Unmute the player
mute()Mute the player
callPlayermethod(String, Object)Call a method from the Js Player API, if not already exposed in the Android SDK
setPlayWhenReady(Boolean)Set the autoplay behavior of the player when video is loaded. Set to true, for autoplay enabled.
setQuality(String)Set player to play at a specified quality if available [‘240’, ‘380’, ‘480’, ‘720’, ‘1080’, ‘1440’, ‘2160’ ‘default’]
setSubtitle(String)Activate subtitles track to a specified language if available
setVolume(float)Set the player’s volume to the specified level between 0 & 1. ie, 0.5 = 50%
release()Destroy the Player webView
seek(double)Seek to the specified time in video playback in seconds
setIsWebContentDebuggingEnabled()Enable the Android system WebView debug mode
setMinimizeProgress(float)Disable the player UI when set to 0, enables when 1
setWebViewErrorListener(WebViewErrorListener)Add a listener for Android system WebView error
showControls()Enable the display of the player UI
toggleControls()Turn on/off the player’s UI components
togglePlay()Switch between player & pause

In order to make a developer’s life easier, we created methods in our android SDK that will return the value of a specific player property. Not all player properties are returned by a set method, some are returned in the payload sent after the player event. Please see here for more info about events.

NameInfo
getBufferedTime()Returns a Double Number. The part of the media resource that has been downloaded in seconds
getVideoPaused()Returns a boolean value for current pause state of the player
getVolume()Returns a float value for the volume property between 0 and 1
isEnded()Returns a boolean value for whether the media resource has ended
isSeeking()Returns a boolean value for whether the video resource is seeking
getDuration()Returns a double value for the length of a media resource in seconds
getPosition()Returns a long value of the current playback position in seconds

Player events

The player emits specific events about changes in its state. For specific player events, you can add event listeners. For certain events, it’s possible to access the corresponding player property value using the payload method.

EventInfoPayload method
ApiReadyEventSent when the player is ready to accept API commands. Do not try to call functions before receiving this event
StartEventSent the first time the player attempts to start the playback
VideoChangeEventSent when a new video has been loaded in the playergetPayload() returns video id & video title
LoadedMetaDataEventSent when the video’s metadata is loaded
AdStartEventSent when the player starts to play an ad media resource
AdTimeUpdateEventSent when the playback position of an ad changes
AdPlayEventSent when the player starts the playback of an ad
AdPauseEventSent when the player pauses an ad resource
AdEndEventSent when the player reaches the end of an ad media resource
VideoStartEventSent when the player starts to play the media resource
TimeUpdateEventSent when the playback position changes
SeekingEventSent when the player is starting to seek to another position in the videogetPayLoad() will return the position at which the seek method was triggered
SeekedEventSent when the player has completed a seeking operationgetPayLoad() will return the position at which the seek method seeks to
ProgressEventSent when the browser is fetching the media data
DurationChangeEventSent when the duration property of the video becomes available or changes after a new video loadgetPayload() returns the duration property of the video
PlayingEventSent when the content media resource playback has started
PauseEventSent when the content media resource playback has paused
VideoEndEventSent when the player reaches the end of the content media resource
PlaybackReadyEventSent when playback starts after the play method returns
QualitiesAvailableEventSent when qualities are availablegetPayload() returns qualities which are available
QualityChangeEventSent when the video quality changesgetPayload() returns the quality value
VolumeChangeEventSent when the volume or mute state changesgetPayload() returns volume state and muted state
FullScreenToggleRequestedEventSent when the fullscreen toggle button is requested
ControlChangeEventSent when the UI controls appear or disappeargetPayload() returns if player UI controls are visible

Below is an example of adding listeners for multiple events, it is then possible to use the event payload method to get the corresponding events property value.

dailyMotionVideoPlayer.setEventListener { event ->
    when (event) {
        is ApiReadyEvent -> ...
        is StartEvent -> ...
        is LoadedMetaDataEvent -> ...
        is ProgressEvent -> ...
        is DurationChangeEvent -> ...
        /* And many more event */
        else -> {
            /* In case a POJO is not available you can directly access the raw data */
            if (event.name == "_generic_") {
                /* Do some stuff for my event: parse the raw date to extract the event name or values */
                Log.d("Event with payload: ${event.payload}")
            }
        }
    }
}

Best practices

Player Ready Event:
When using the Player with any of our of SDKs, we recommend before you make any API commands, wait till after the API ready event is sent by the player. You can pick this up in your android app using the ApiReadyEvent.

Preload player:
It’s possible to load the player and the video separately. In your application, you can preload the player before the user attempts to play a video. In order to preload the player without a video being displayed. Use the initialize() method and base the baseUrl of just the player with a video not defined, https://www.dailymotion.com/embed/.

Reuse player:
When utilizing the player via our SDKs in an application, you can reuse the same player instance. Use the load() method passing in the video id after initializing the player.

Handle full-screen orientation:
Any activity you are using your player in, you should add the below snippet in your AndroidManifest.XML . The setFullScreenButton() method which is available, doesn’t have complete control of the full-screen functionality in your application. This should be used in parallel with your own native application functionality adjusting the player to take the whole screen space. This method controls the UI fullscreen component and updates the player state.

android:configChanges="orientation|screenSize"

Google player services:
The SDK uses Google Play Services to get the Advertising Id, you may want to override the play-services-ads version to avoid conflicting with other play services artifacts.

dependencies {
    implementation "com.google.android.gms:play-services-ads:[your_play_services_version]"
}

Picture In Picture:
Our flagship Dailymotion app use our Android SDK, although we can’t provide out of the box PiP functionality, it is possible to achieve this like we have done, depending on your software architecture. You can review info on Google’s android Picture-in-Picture support here.

TCF2

Our Android SDK complies with IAB TCF2 standards so it’s easy to access the stored content string and pass it to the Player.

Using a recognized CMP, generate the consent string and store it in the correct location as specified by the TCF2 iAB specification. After generating the consent string then pass it to the Player using the tcf2Handler.loadConsentString(content = this) method.

OM SDK

Open Measurement SDK from IAB is designed to facilitate third party viewability and verification measurement for ads served to web video and mobile app environments. For more details see here.

We have integrated the SDK in our Dailymotion Player SDK and it does more or less everything out of the box :

  • Ad session management
  • Ad main signals (play, buffer_start, buffer_end, pause, resume, quartiles, click)
  • Device and Player volume management
  • Basic Player state handling. NORMAL or FULLSCREEN based on player fullscreen state.

Please note that it is recommended to update at all times the Player state if your app has more Player layout variety, such as mini-player, picture-in-picture, etc. This can be achieved by updating the OMHelper playerState field :

    OMHelper.playerState = PlayerState.COLLAPSED
EnumDescription
MINIMIZEDThe player is collapsed in such a way that the video is hidden. The video may or may not still be progressing in this state, and sound may be audible. This refers to specifically to the video player state on the page, and not the state of the browser window
COLLAPSEDThe player has been reduced from its original size. The video is still potentially visible
NORMALThe player’s default playback size
EXPANDEDThe player has expanded from its original size
FULLSCREENThe player has entered fullscreen mode