Player Settings for Android
Once you’ve created a player instance, you can make changes to its settings:
- In Kaltura Player the same settings API below are integrated inside
PlayerInitOptions
object
Example:
setContentRequestAdapter
setLicenseRequestAdapter
setCea608CaptionsEnabled
setMpgaAudioFormatEnabled
useTextureView
setAllowCrossProtocolRedirect
allowClearLead
setSecureSurface
setAdAutoPlayOnResume
setPlayerBuffers
setVRPlayerEnabled
setPreferredAudioTrack
setPreferredTextTrack
setPreferredMediaFormat
setSubtitleStyle
Creating A Player
Apply Player Settings if required:
Enable crossProtocolRedirect
Example:
Enable DRM Clear Lead Playback
Example:
Enable Secure Surface
In case App wants to block ability to take screen capture
Example:
Configure Player’s PreferredMediaFormat.
In the case where the Media Entry contains multiple sources, the player will attempt to use formats in this priority order:
- DASH (mpd)
- HLS
- WVM
- MP4
- MP3
In order to force a Media Format that is different than the priority list, use setPreferredMediaFormat
with the desired type:
Making this call, for example, would move MP4 format to the top of the priority list.
Configure Player Load Control
Using builder API you can create LoadControl Buffers with the default ExoPlayer values
then it is possible configure any parameter from the LoadControlBuffers Object.
Defaults can be found here:
Defaults
Example:
Configure if to use TextureView instead of surface view
Example:
Enable Cea608Captions
Example:
Configure KalturaPlaybackRequestAdapter
Example:
Configure KalturaUDRMLicenseRequestAdapter
Example:
Enable - Ad will auto play on resume
In some cases where app does not expose play pause API on ads this API will do the auto play after resume from background
Example:
setVRPlayerEnabled(boolean vrPlayerEnabled);
If case 360 media should be played on VR player or default player - default is true
Example:
Configure preferred TEXT TRACKS – Default is no captions displayed.
Example:
Set Preferred Audio/Text Track
The player allows you to set the preferred language audio/text by instantiating the PKTrackConfig
, which is created via the builder method.
Language options are:
- Explicitly setting the language code
- Auto, which sets the language based on location, if available.
- Default, which contains no text and uses the first available audio track.
Once we have the PKTrackConfig
object we can use it as parameter for the API.
Tracks Configuration possibilities
There are 3 modes available:
OFF
- for Text tracks it will cancel text tracks display for audio it will select the default from the manifestAUTO
- SDK will check if the stream has audio/text track that matches the device locale and will select it else it will take stream defaultSELECTION
- this mode requires to set the language explicitly (2 or 3 letters) if this language does not exist SDK will take the streams
default Audio/Text track
NOTE!!!
The languages that are expected by the player to match the SO 639-X codes definition
Subtitle Sideloading for Player
Since Playkit version 3.9.0
To load Subtitle from external source for the player, need to create a List
of PKExternalSubtitle
and then pass it to PKMediaEntry
object.
Use setDefault()
while creating PKExternalSubtitle
to make it default subtitle.
TEXT_VTT
and APPLICATION_SUBRIP
mime-types are supported for subtitles.
Subtitle Styles for Player
To configure Subtitles to the player, first need to set the Subtitles using settings
from player
object.
While creating SubtitleStyleSettings
object, need to pass subtitleStyleName
param in constructor.
To update the Subtitles call updateSubtitleStyle()
using only player
object. Use updated subtitleStyleSettings
object.
Using builder pattern for setters in subtitleStyleSettings
, Following Styles can be applied,
setTextColor
- Change subtitle text colorsetBackgroundColor
- Change subtitle background colorsetEdgeColor
- Change subtitle text edge color-
setWindowColor
- Change subtitle window color setEdgeType
- Change subtitle Edge types usingenum SubtitleStyleEdgeType
with the values
setTextSizeFraction
- Change subtitle text size fraction usingenum SubtitleTextSizeFraction
with the values
setTypeface
- Change subtitle typeface usingenum SubtitleStyleTypeface
with the values
Example:
To set the Subtitles,
To update the existing Subtitles:
Set ABR Settings
To enable track selection to select subset of tracks that participate in the ABR values are expected in bits
Example:
In order to reset these values in Change Media if needed:
Set Surface Aspect Ratio Resize Mode
To configure Full screen Fit/Fill/Zoom support for devices with special resolution like 18:9 in order to prevent letter-boxing of video playback
New enum added to support this functionality
Example for updating the ratio resize mode for playback start time:
Example for updating the ratio settings during the playback:
Force Single Player Engine
Use forceSinglePlayerEngine for Ads playback to achieve preperContentAfterAd behaviour
To can tell the player not to prepare the content player when Ad starts(if exists);
instead content player will be prepared when content_resume_requested is called.
so low end devices with lack of enough decoders will be able to play ads + content separately.
Default value for this configuration is set to ‘false’.
Example:
Set Hide Video Views
Used to enable video thumbnail to be displayed for Audio Entries
This config enable apps to hide the video surface to for audio only medias it will be able to put behind the player thumbnail and still captions will be available.
Note: player.getSettings().setHideVideoViews(true)
should be called before calling player prepare.
In case there is change media between audio and video, app should call player.getSettings().setHideVideoViews(false)
in order to make the video surface visible again.
Default value for this API is false and player.getSettings().setHideVideoViews(false)
should be called again if changing media between audio only and video.
Example:
AudioOnlyBasicSetupSample Sample can be found in the samples repository
Note: It is application’s responsibility for hiding/showing the artwork by its own logic.
Set VR Settings
For VR and 360 medias, PKMediaEntry
has now new member isVRMediaType
that signs media as VR media
In case media provider is used, PKMediaEntry
will be populated automatically on the MediaEntry which is returned from the callback.
if VRsettings
is not configured, default values will be used (only touch will be available)
take in account that not all devices support motion so make sure you verify that motion is supported using hte API VRUtil.isModeSupported
Example:
Example
For more VR settings and it defaults explore VRSettings
APIs
Set Custom Load Control Strategy
To change the LoadControl and the Bandwidth Meter that is being used by ExoPlayer
ExoPlayerWrapper.LoadControlStrategy
interface has to be implemented and to be passed to the setCustomLoadControlStrategy
API
Example:
The class code
package com.kaltura.playkitdemo;
import android.content.Context;
import android.os.Handler;
import com.kaltura.android.exoplayer2.DefaultLoadControl;
import com.kaltura.android.exoplayer2.LoadControl;
import com.kaltura.android.exoplayer2.upstream.BandwidthMeter;
import com.kaltura.android.exoplayer2.upstream.DataSource;
import com.kaltura.android.exoplayer2.upstream.DataSpec;
import com.kaltura.android.exoplayer2.upstream.DefaultBandwidthMeter;
import com.kaltura.android.exoplayer2.upstream.TransferListener;
import com.kaltura.playkit.player.ExoPlayerWrapper;
import androidx.annotation.Nullable;
public class PlaykitLoadControlStrategy implements ExoPlayerWrapper.LoadControlStrategy {
private Context context;
public PlaykitLoadControlStrategy(Context context) {
this.context = context;
}
@Override
public LoadControl getCustomLoadControl() {
return new DefaultLoadControl();
}
@Override
public BandwidthMeter getCustomBandwidthMeter() {
//return new DefaultBandwidthMeter.Builder(context).build();
TransferListener tl = new TransferListener() {
@Override
public void onTransferInitializing(DataSource source, DataSpec dataSpec, boolean isNetwork) {
}
@Override
public void onTransferStart(DataSource source, DataSpec dataSpec, boolean isNetwork) {
}
@Override
public void onBytesTransferred(DataSource source, DataSpec dataSpec, boolean isNetwork, int bytesTransferred) {
}
@Override
public void onTransferEnd(DataSource source, DataSpec dataSpec, boolean isNetwork) {
}
};
return new BandwidthMeter() {
private EventListener listener;
@Override
public long getBitrateEstimate() {
return 1500000;
}
@Nullable
@Override
public TransferListener getTransferListener() {
return tl;
}
@Override
public void addEventListener(Handler eventHandler, EventListener eventListener) {
this.listener = eventListener;
eventHandler.post(new Runnable() {
@Override
public void run() {
eventListener.onBandwidthSample(1000, 1000000/8, 1500000);
eventHandler.postDelayed(this, 1000);
}
});
}
@Override
public void removeEventListener(EventListener eventListener) {
this.listener = null;
}
};
}
}
Set Tunneled Audio Playback
Used to enable/disable audio tunneling.
Example:
Handle Audio Becoming Noisy
Sets whether the player should pause automatically
when audio is rerouted from a headset to device speakers.
default=false
Example:
Set Max Video Size
Sets the maximum allowed video width and height.
to set the maximum allowed video bitrate to sd resolution call:
setMaxVideoSize(new PKMaxVideoSize().setMaxVideoWidth(1279).setMaxVideoHeight(719)
to reset call:
setMaxVideoSize(new PKMaxVideoSize().setMaxVideoWidth(Integer.MAX_VALUE).setMaxVideoHeight(Integer.MAX_VALUE)
Example:
Set Max Audio Bitrate
Sets the maximum allowed Audio bitrate
Example:
Set Max Audio Channel Count
Sets maximum allowed audio channel count. default max = Integer.MAX_VALUE