Implementing EmbedTokenGenerator for Android

To use the Ooyala Player Token for user authorization implement OOEmbedTokenGenerator in the Android app main activity.

Use the following steps to implement an EmbedTokenGenerator in the Android project main activity.

  1. Open the Android app main activity and add the following import statements:
  2. Extend the main activity class with the EmbedTokenGenerator interface. The syntax is shown in the following example:
    public class MainActivity extends Activity implements EmbedTokenGenerator, Observer{
  3. Create an OoyalaPlayerLayoutController instance with the constructor that takes an embedTokenGenerator parameter. Use the player.setEmbedCode and functions. This is shown in the following example:
    public void onCreate(Bundle savedInstanceState) {
        OoyalaPlayerLayout playerLayout = (OoyalaPlayerLayout) findViewById(;
        OoyalaPlayerLayoutController playerLayoutController = new OoyalaPlayerLayoutController(playerLayout, PCODE, new PlayerDomain(DOMAIN), this);
        player = playerLayoutController.getPlayer();
        if (player.setEmbedCode(EMBED)) {
        } else {
          Log.d(this.getClass().getName(), "Something Went Wrong!");
  4. A server-side generated token can only be created by the customer so content is authorized for playback on authorized sites. The client receives it and submits it to EmbedTokenGeneratorCallback(). These tokens should not be created on the client. The API secret should only be on the server and should not be publicly visible. This example is only useful for debugging but should not be used in production. Implement the getTokenForEmbedCodes method with an EmbedTokenGeneratorCallback interface. Add the .setEmbedToken callback, where token is a valid Ooyala player token for the list of embed codes. This is shown in the following example:
      public void getTokenForEmbedCodes(List<String> embedCodes,
          EmbedTokenGeneratorCallback callback) {
        //add embed token/OPT in the setEmbedToken() example below
        // HTTP_SAS + "/embed_token/pcode/embed_code?account_id=account&api_key=apikey&expires=expires&signature=signature"
        callback.setEmbedToken("fill me in");

The Android Mobile SDK Sample Apps folder includes a complete working sample app with EmbedTokenGenerator implemented. From the SDK archive, navigate to: