Last active
September 18, 2018 18:42
-
-
Save brol1dev/5caa3c09414f12abee28e7aec2c69ac8 to your computer and use it in GitHub Desktop.
[Android] Shows how to add custom query parameters to the SAS authorization request with the OoyalaPlayer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ooyala.sample.players; | |
import android.util.Base64; | |
import com.ooyala.android.DefaultPlayerInfo; | |
import com.ooyala.android.OoyalaPlayer; | |
import com.ooyala.android.OoyalaPlayerLayout; | |
import com.ooyala.android.PlayerDomain; | |
import com.ooyala.android.configuration.Options; | |
import com.ooyala.android.item.Stream; | |
import com.ooyala.android.ui.OoyalaPlayerLayoutController; | |
import com.telstra.android.media.capabilities.CapabilityUtils; | |
import com.ooyala.sample.R; | |
import java.io.UnsupportedEncodingException; | |
import java.util.HashMap; | |
import java.util.HashSet; | |
import java.util.Map; | |
import java.util.Set; | |
public class AdditionalSASQueryParamsActivity extends Activity { | |
class MyPlayerInfo extends DefaultPlayerInfo { | |
Map<String, String> additionalParams; | |
Set<String> supportedFormats = new HashSet<String>(); | |
public MyPlayerInfo() { | |
super(null, null); | |
supportedFormats.add(Stream.DELIVERY_TYPE_DASH); | |
supportedFormats.add(Stream.DELIVERY_TYPE_HLS); | |
supportedFormats.add(Stream.DELIVERY_TYPE_AKAMAI_HD2_VOD_HLS); | |
supportedFormats.add(Stream.DELIVERY_TYPE_AKAMAI_HD2_HLS); | |
supportedFormats.add(Stream.DELIVERY_TYPE_M3U8); | |
supportedFormats.add(Stream.DELIVERY_TYPE_MP4); | |
} | |
public void setAdditionalParams(Map<String, String> additionalParams) { | |
this.additionalParams = additionalParams; | |
} | |
@Override | |
public Map<String, String> getAdditionalParams() { | |
return additionalParams; | |
} | |
@Override | |
public Set<String> getSupportedFormats() { | |
return supportedFormats; | |
} | |
} | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.player_simple_layout); | |
// Example using Telstra library. We'll build a b64 string passed as a query param value | |
CapabilityUtils.hasTelstraSIM(this); | |
String myCapabilities = CapabilityUtils.capabilitesToJson(CapabilityUtils.getCapabilities(this)); | |
String capabilities64 = null; | |
try { | |
byte[] capabilitiesData = myCapabilities.getBytes("UTF-8"); | |
capabilities64 = Base64.encodeToString(capabilitiesData, Base64.NO_WRAP); | |
} catch (UnsupportedEncodingException e) { | |
} | |
// this map will contain the query params appended to the SAS request | |
Map<String, String> myQueryParams = new HashMap<>(); | |
if (capabilities64 != null) { | |
myQueryParams.put("ddmm_device_param", capabilities64); | |
} | |
MyPlayerInfo playerInfo = new MyPlayerInfo(); | |
playerInfo.setAdditionalParams(myQueryParams); | |
Options options = new Options.Builder().setPlayerInfo(playerInfo).build(); | |
player = new OoyalaPlayer(pcode, new PlayerDomain(domain), options); | |
playerLayout = (OoyalaPlayerLayout) findViewById(R.id.ooyalaPlayer); | |
playerLayoutController = new OoyalaPlayerLayoutController(playerLayout, player); | |
if (player.setEmbedCode(embedCode)) { | |
player.play(); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment