Android SDK (Legacy)
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
- The easiest way to integrate the SDK is by adding it to your application
build.gradle
file. - 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 thesetPlayWhenReady(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>
- 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 theinitialize()
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.
Parameter | Info | Type |
---|---|---|
autoplay | Automatically attempt to start playback with sound, if it is blocked by the browser, the player will force the video mute | Boolean |
controls | Whether to display the player controls, true by default | Boolean |
id | ID of the player unique to the page to be passed back with all API messages | String |
mute | Whether to mute the video | Boolean |
quality | Specify the suggested playback quality for the video | Number |
sharing-enable | Whether to display the sharing button | Boolean |
start | Specify the time (in seconds) from which the video should start playing | Number |
subtitles-default | Specify the default selected subtitles language | String |
syndication | Pass your syndication key to the player | String |
ui-highlight | Change the default highlight color used in the controls (hex value without the leading #). Color set in the Dailymotion Studio will override this param | String |
ui-start-screen-info | Whether to show video information (title and owner) on the start screen | Boolean |
playlist | Specify a playlist ID to populate the Up Next Queue with videos from a playlist | String |
fullscreen | Whether to display the fullscreen button | Boolean |
scaleMode | Specify 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 |
loop | Whether 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 finished | Boolean |
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.
dailyMotionVideoPlayer.pause();
Name | Info |
---|---|
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.
Name | Info |
---|---|
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.
Event | Info | Payload method |
---|---|---|
ApiReadyEvent | Sent when the player is ready to accept API commands. Do not try to call functions before receiving this event | |
StartEvent | Sent the first time the player attempts to start the playback | |
VideoChangeEvent | Sent when a new video has been loaded in the player | getPayload() returns video id & video title |
LoadedMetaDataEvent | Sent when the video’s metadata is loaded | |
AdStartEvent | Sent when the player starts to play an ad media resource | |
AdTimeUpdateEvent | Sent when the playback position of an ad changes | |
AdPlayEvent | Sent when the player starts the playback of an ad | |
AdPauseEvent | Sent when the player pauses an ad resource | |
AdEndEvent | Sent when the player reaches the end of an ad media resource | |
VideoStartEvent | Sent when the player starts to play the media resource | |
TimeUpdateEvent | Sent when the playback position changes | |
SeekingEvent | Sent when the player is starting to seek to another position in the video | getPayLoad() will return the position at which the seek method was triggered |
SeekedEvent | Sent when the player has completed a seeking operation | getPayLoad() will return the position at which the seek method seeks to |
ProgressEvent | Sent when the browser is fetching the media data | |
DurationChangeEvent | Sent when the duration property of the video becomes available or changes after a new video load | getPayload() returns the duration property of the video |
PlayingEvent | Sent when the content media resource playback has started | |
PauseEvent | Sent when the content media resource playback has paused | |
VideoEndEvent | Sent when the player reaches the end of the content media resource | |
PlaybackReadyEvent | Sent when playback starts after the play method returns | |
QualitiesAvailableEvent | Sent when qualities are available | getPayload() returns qualities which are available |
QualityChangeEvent | Sent when the video quality changes | getPayload() returns the quality value |
VolumeChangeEvent | Sent when the volume or mute state changes | getPayload() returns volume state and muted state |
FullScreenToggleRequestedEvent | Sent when the fullscreen toggle button is requested | |
ControlChangeEvent | Sent when the UI controls appear or disappear | getPayload() 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
Enum | Description |
---|---|
MINIMIZED | The 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 |
COLLAPSED | The player has been reduced from its original size. The video is still potentially visible |
NORMAL | The player’s default playback size |
EXPANDED | The player has expanded from its original size |
FULLSCREEN | The player has entered fullscreen mode |