Cómo usar el Android SDK

Anterior Siguiente

Configure su región

Cuando se carga el SDK, obtiene su configuración de emisora de nuestros servicios de aprovisionamiento. Para acelerar el proceso, contamos con servidores de aprovisionamiento en diversas regiones, incluidas América del Norte, Europa y Asia. Para la obtención de mejores resultados, utilice los servidores de aprovisionamiento que se encuentran más cerca de sus estaciones.

La región de aprovisionamiento predeterminada es América del Norte; para usar una de las otras regiones, especifíquela según se observa en el siguiente ejemplo, en el que se utiliza "AP" (Asia).

// Cree las configuraciones del reproductor.
Bundle settings = new Bundle();
settings.putString(TritonPlayer.SETTINGS_STATION_BROADCASTER, "Triton Digital");
settings.putString(TritonPlayer.SETTINGS_STATION_NAME,        "MOBILEFM");
settings.putString(TritonPlayer.SETTINGS_STATION_MOUNT,       "MOBILEFM_AACV2");
settings.putString(TritonPlayer.SettingsPlayerServicesRegion, "AP"); // AP = Asia | EU = Europe | Omit this configuration option for North America

// Create the player.
TritonPlayer player = new TritonPlayer(this, settings);
player.play();

Autoplay

For measurement reasons, as well as user experience, the use of auto-play is strongly discouraged. Autoplay is defined as the station/stream playing without any user interaction to initiate the play. If you do implement an auto-play strategy, you need to add the autoplay = 1 value to the targetingParams object when calling the play function on the SDK.

// Cree las configuraciones del reproductor.
Bundle settings = new Bundle();
settings.putString(TritonPlayer.SETTINGS_STATION_BROADCASTER, "Triton Digital");
settings.putString(TritonPlayer.SETTINGS_STATION_NAME,        "MOBILEFM");
settings.putString(TritonPlayer.SETTINGS_STATION_MOUNT,       "MOBILEFM_AACV2");
settings.putString(TritonPlayer.SettingsPlayerServicesRegion, "AP"); // AP = Asia | EU = Europe | Omit this configuration option for North America

// Create the player.
TritonPlayer player = new TritonPlayer(this, settings);
player.play();

Audio Focus

Use TritonPlayer.SETTINGS_HANDLE_AUDIO_FOCUS to enable or disable the automatic handling of the device audio focus. In case you want to control the audio focus manually, you can set this option to false. The default is true.

Required: No.

Options (Boolean):
  • Automatic (TritonPlayer will handle any audio focus change automatically): true

  • Manual (TritonPlayer will ignore audio focus changes): false

// Cree las configuraciones del reproductor.

Bundle settings = new Bundle();
settings.putString(TritonPlayer.SETTINGS_STATION_BROADCASTER, "Triton Digital");
settings.putString(TritonPlayer.SETTINGS_STATION_NAME,        "MOBILEFM");
settings.putString(TritonPlayer.SETTINGS_STATION_MOUNT,       "MOBILEFM_AACV2");
settings.putBoolean(TritonPlayer.SETTINGS_HANDLE_AUDIO_FOCUS, false); // Audio Focus handled manually

// Create the player.

TritonPlayer player = new TritonPlayer(this, settings);
player.play();

Reproducir una estación

// Cree las configuraciones del reproductor.
Bundle settings = new Bundle();
settings.putString(TritonPlayer.SETTINGS_STATION_BROADCASTER, "Triton Digital");
settings.putString(TritonPlayer.SETTINGS_STATION_NAME,        "MOBILEFM");
settings.putString(TritonPlayer.SETTINGS_STATION_MOUNT,       "MOBILEFM_AACV2"); 

// Create the player.

TritonPlayer player = new TritonPlayer(this, settings);
player.play();

Reproducir un montaje HLS específico

// Cree las configuraciones del reproductor.
Bundle settings = new Bundle();
settings.putString(TritonPlayer.SETTINGS_STATION_BROADCASTER, "Triton Digital");
settings.putString(TritonPlayer.SETTINGS_STATION_NAME,        "HLS_PLAYERS");
settings.putString(TritonPlayer.SETTINGS_STATION_MOUNT,       "HLS_PLAYERSAAC");
settings.putString(TritonPlayer.SETTINGS_TRANSPORT,           TritonPlayer.TRANSPORT_HLS);

// Create the player.
TritonPlayer player = new TritonPlayer(this, settings);
player.play();

Change Station

Para reproducir una nueva estación, debe crear un nuevo reproductor.

// Release the current player instance.
if (player != null)
{
    player.release();
}

// Recreate the player with the next station settings.
player = new TritonPlayer(this, nextStationSettings);
player.play();

Audiencia objetivo para anuncios de audio

En este ejemplo, se ha habilitado el rastreo de ubicación. The postal code will only be used if the user has disabled the location access in the O.S. See StreamUrlBuilder in the API reference for more targeting options. For details on the bundle-id, store-id, and store-url parameters, see Device/Player Information.

AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

// Create the targeting parameters
HashMap<String, String> targetingParams = new HashMap();
targetingParams.put("bundle-id", "com.companyname.app"); // Required
targetingParams.put("store-id", "com.companyname.app"); // Required
targetingParams.put("store-url", "https://play.google.com/store/apps/details?id=com.companyname.app"); // Required
targetingParams.put(StreamUrlBuilder.COUNTRY_CODE,  "US");
targetingParams.put(StreamUrlBuilder.POSTAL_CODE,   "12345");
targetingParams.put(StreamUrlBuilder.GENDER,        "m");
targetingParams.put(StreamUrlBuilder.YEAR_OF_BIRTH, "1990"); 

// Create the player settings.
Bundle settings = new Bundle();
settings.putBoolean(TritonPlayer.SETTINGS_TARGETING_LOCATION_TRACKING_ENABLED, true);
settings.putSerializable(TritonPlayer.SETTINGS_TARGETING_PARAMS, targetingParams);
settings.putString(TritonPlayer.SETTINGS_STATION_BROADCASTER,    "Triton Digital");
settings.putString(TritonPlayer.SETTINGS_STATION_NAME,           "MOBILEFM");
settings.putString(TritonPlayer.SETTINGS_STATION_MOUNT,          "MOBILEFM_AACV2");

// Create the player.
TritonPlayer player = new TritonPlayer(this, settings);
player.play();

Example using DMP Segments:

//Add DMP SEGMENTS
HashMap<String, List<Integer>> dmpSegments = new HashMap();
dmpSegments.put("permutive", Arrays.asList(1234,5769));
dmpSegments.put("adobe", Arrays.asList(4321,8765));

// Create the player settings.
Bundle settings = new Bundle();
settings.putBoolean(TritonPlayer.SETTINGS_TARGETING_LOCATION_TRACKING_ENABLED, true);
settings.putSerializable(TritonPlayer.SETTINGS_TARGETING_PARAMS, targetingParams);
settings.putSerializable(TritonPlayer.SETTINGS_DMP_SEGMENTS, dmpSegments);
settings.putString(TritonPlayer.SETTINGS_STATION_BROADCASTER,    "Triton Digital");
settings.putString(TritonPlayer.SETTINGS_STATION_NAME,           "MOBILEFM");
settings.putString(TritonPlayer.SETTINGS_STATION_MOUNT,          "MOBILEFM_AACV2");

// Create the player.
TritonPlayer player = new TritonPlayer(this, settings);
player.play();

Change Playback Speed

To change the playback speed of a podcast, use changeSpeed with a float value as the speed argument. This example changes the playback to 1,50 times the original speed:

tritonPlayer.changeSpeed(1,50f)

Token Authorization (Self-Signed)

In order for re-creation of the tokens on reconnect to work, either of the following parameters are required:

  • TritonPlayer.SETTINGS_AUTH_SECRET_KEY

  • TritonPlayer.SETTINGS_AUTH_KEY_ID

If all of the parameters are filled in, then you don't have to generate the token yourself (although you can if you want to).

// Create the targeting parameters
HashMap<String, String> targetingParams = new HashMap();
targetingParams.put(StreamUrlBuilder.COUNTRY_CODE,  "US");
targetingParams.put(StreamUrlBuilder.POSTAL_CODE,   "12345");
targetingParams.put(StreamUrlBuilder.GENDER,        "m");
targetingParams.put(StreamUrlBuilder.YEAR_OF_BIRTH, "1990");

// Create the authorization token
String token = AuthUtil.createJwtToken("MySecretKey", "MySecretKeyId", true, "foo@bar.com", targetingParams); 

// Create the player settings.
Bundle settings = new Bundle();
settings.putSerializable(TritonPlayer.SETTINGS_TARGETING_PARAMS, targetingParams);
settings.putString(TritonPlayer.SETTINGS_AUTH_TOKEN,             token);
settings.putString(TritonPlayer.SETTINGS_STATION_BROADCASTER,    "Triton Digital");
settings.putString(TritonPlayer.SETTINGS_STATION_NAME,           "MOBILEFM");
settings.putString(TritonPlayer.SETTINGS_STATION_MOUNT,          "MOBILEFM_AACV2");
settings.putString(TritonPlayer.SETTINGS_AUTH_SECRET_KEY,        "1234566");
settings.putString(TritonPlayer.SETTINGS_AUTH_KEY_ID,            "ABCDEF");
settings.putBoolean(TritonPlayer.SETTINGS_AUTH_REGISTERED_USER,  true/false);
settings.putString(TritonPlayer.SETTINGS_AUTH_USER_ID,           null);

// Create the player.
TritonPlayer player = new TritonPlayer(this, settings);
player.play();

Recibir metadatos de stream (puntos de referencia)

// Cree a un oyente como punto de referencia.
OnCuePointReceivedListener listener = new OnCuePointReceivedListener() {
    @Override
    public void onCuePointReceived(MediaPlayer player, Bundle cuePoint) {
        // Handle the cue points here.
    }
};

// Create the player.
TritonPlayer player = new TritonPlayer(this, settings);
player.setOnCuePointReceivedListener(listener);
player.play();

Mostrar banners de sincronización

private SyncBannerView mSyncBannerView; 

@Override
protected void onPause() {
    mSyncBannerView.onPause();
    super.onPause();
} 

@Override
protected void onResume() {
    super.onResume();
    mSyncBannerView.onResume();
} 

@Override
protected void onDestroy() {
    mSyncBannerView.release();
    super.onDestroy();
} 

@Override
public void onCuePointReceived(MediaPlayer player, Bundle cuePoint) {
    // Update the banner. See previous example on how to get cue points.
    mSyncBannerView.loadCuePoint(cuePoint);
} 

private void initBanner() {
    // Get the banner from the layout and set its size.
    mSyncBannerView = (SyncBannerView)findViewById(mySyncBannerId);
    mSyncBannerView.setBannerSize(320, 50);
}

Reproducir un stream a demanda

// Cree las configuraciones del reproductor.
Bundle settings = new Bundle();
settings.putString(TritonPlayer.SETTINGS_STREAM_URL, "https://storage.googleapis.com/automotive-media/Jazz_In_Paris.mp3"); 

// Create the player.
TritonPlayer player = new TritonPlayer(this, settings);
player.play();

Reproducir en dispositivos Google Cast

The Triton Digital Mobile SDK supports Google Cast devices for both live and on-demand streams, but not on-demand advertising. Hay unos pocos dispositivos que son compatibles con el protocolo Google Cast, como el reproductor Chromecast y el reproductor Nexus.

Receptor básico de medios

La aplicación de muestra en el archivo ZIP detalla cómo hacer una implementación básica.

Receptor de medios con estilo

Más complejo de implementar que el receptor básico de medios.

Enlaces útiles:

Obtener el historial de canciones de una emisora

public class SongHistoryExample extends Activity implements CuePointHistory.CuePointHistoryListener
{
    private CuePointHistory mCuePointHistory;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 
        // Init the cue point history object
        mCuePointHistory = new CuePointHistory();
        mCuePointHistory.setListener(this);
        mCuePointHistory.setCueTypeFilter(CuePoint.CUE_TYPE_VALUE_TRACK);
        mCuePointHistory.setMaxItems(10);
        mCuePointHistory.setMount("MOBILEFM");
 
        // Request the track history
        mCuePointHistory.request();
    }
 
    @Override
    public void onCuePointHistoryReceived(CuePointHistory src, List<Bundle> cuePoints) {
        // Handle history here
    }
 
    @Override
    public void onCuePointHistoryFailed(CuePointHistory src, int errorCode) {
        // Handle errors here
    }
}

Mostrar anuncios a demanda a través de la aplicación

Los anuncios intersticiales pueden ser de video o audio.

AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
 
<activity
    android:name="com.tritondigital.ads.InterstitialActivity"
    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

MyActivity.java

AdRequestBuilder adRequestBuilder = new AdRequestBuilder(this)
        .enableLocationTracking(true)
        .setHost("https://cmod-world.live.streamtheworld.com")
        .addQueryParameter(AdRequestBuilder.YEAR_OF_BIRTH, 1990)
        .addQueryParameter(AdRequestBuilder.GENDER, 'm')
        .addQueryParameter(AdRequestBuilder.STATION_ID, "23193");
 
// Create the interstitial instance
Interstitial interstitial = new Interstitial(this);
 
//Optional if you want to display the ad countdown timer:
interstitial.setEnableCountDownDisplay(true);
 
// Display an interstitial ad
interstitial.showAd(adRequestBuilder);
 
// When exiting your activity
interstitial.release();

You can also specify bundle-id, store-id, and store-url to On-Demand Ads as follows:

AdRequestBuilder adRequestBuilder = new AdRequestBuilder(this)
        .setHost("https://cmod-world.live.streamtheworld.com")
        .addQueryParameter(AdRequestBuilder.STATION_ID, "12345")
        .addQueryParameter(AdRequestBuilder.ASSET_TYPE, AdRequestBuilder.ASSET_TYPE_VALUE_VIDEO)
        .addQueryParameter(AdRequestBuilder.TYPE, AdRequestBuilder.TYPE_VALUE_MIDROLL)
        // Add bundle-id, store-id and store-url
        .addQueryParameter(AdRequestBuilder.BUNDLE_ID, "com.tritondigital.tritonradio")
        .addQueryParameter(AdRequestBuilder.STORE_ID, "1234567890")
        .addQueryParameter(AdRequestBuilder.STORE_URL, URLEncoder.encode("https://play.google.com/store/apps/details?id=com.tritondigital.tritonradio", "UTF-8"));
 
// Create the interstitial instance
Interstitial interstitial = new Interstitial(this);
 
// Display an interstitial ad
interstitial.showAd(adRequestBuilder);

Mostrar anuncios a demanda con UI personalizada

Esto es mucho más complejo que el uso de la clase intersticial. Hay un ejemplo en la aplicación de muestra en el archivo ZIP.

TTags personalizadas - Reproductor

Custom TTags (e.g., mobile:ford) can be applied to streaming URLs by adding an array to the settings parameter SETTINGS_TTAGS.

Ejemplo de TTags personalizadas - Reproductor

// Cree las configuraciones del reproductor.
Bundle settings = new Bundle();
settings.putString(TritonPlayer.SETTINGS_STATION_BROADCASTER,    "Triton Digital");
settings.putString(TritonPlayer.SETTINGS_STATION_NAME,           "MOBILEFM");
settings.putString(TritonPlayer.SETTINGS_STATION_MOUNT,          "MOBILEFM_AACV2");
 
String[] tTags = {"mobile:android","cola:diet"};
settings.putStringArray(TritonPlayer.SETTINGS_TTAGS,tTags);
// Create the player.
TritonPlayer player = new TritonPlayer(this, settings);
player.play();

TTags personalizadas - Anuncios a demanda

Custom TTags (e.g., mobile:ford) can be applied to On Demand URLs by calling addTTags( String[] ) on AdRequestBuilder.

Ejemplo de TTags personalizadas - Anuncios a demanda

// Optional Custom TTags
String[] tTags = { "mobile:android", "car:suv" };
 
AdRequestBuilder adRequestBuilder = new AdRequestBuilder(this)
        .enableLocationTracking(true)
        .setHost("https://cmod-world.live.streamtheworld.com")
        .addQueryParameter(AdRequestBuilder.YEAR_OF_BIRTH, 1990)
        .addQueryParameter(AdRequestBuilder.GENDER, 'm')
        .addQueryParameter(AdRequestBuilder.STATION_ID, "23193")
        .addTtags(tTags);
 
// Create the interstitial instance
Interstitial interstitial = new Interstitial(this);
 
// Display an interstitial ad
interstitial.showAd(adRequestBuilder);
 
// When exiting your activity
interstitial.release();

Multi-listener ID

Provides a way to send multiple user or device identifiers, in addition to the main listener ID (lsid parameter). The latter is still used by Triton for frequency capping, measurement etc., while the other IDs can be provided to third-party demand platforms in order to improve monetization.

The values for the LISTENER_ID_TYPE are:

  • ListenerIdType.PPID

  • ListenerIdType.IDFA

  • ListenerIdType.GAID

  • ListenerIdType.APP

Ejemplo:

Bundle settings = new Bundle();
settings.putString(TritonPlayer.SETTINGS_STATION_BROADCASTER, "Triton Digital");
settings.putString(TritonPlayer.SETTINGS_STATION_NAME,        "MOBILEFM");
settings.putString(TritonPlayer.SETTINGS_STATION_MOUNT,       "MOBILEFM_AACV2");

// Add the targeting parameters
HashMap<String, String> targetingParams = new HashMap();
targetingParams.put(StreamUrlBuilder.DIST, "triton-dist-param");
targetingParams.put(StreamUrlBuilder.LISTENER_ID_TYPE, StreamUrlBuilder.ListenerIdType.PPID.getListenerIdType());
targetingParams.put(StreamUrlBuilder.LISTENER_ID_VALUE, "550e8400-e29b-41d4-a716-446655443658");

settings.putSerializable(TritonPlayer.SETTINGS_TARGETING_PARAMS, targetingParams);
// Create the player.
TritonPlayer player = new TritonPlayer(this, settings);
player.play();

Baja demora con almacenamiento adaptable

When set to -1 / AUTO MODE the SDK uses a small (two second) buffer window on initial connection, reducing the amount of delay between playback and real-time.  (Esto resulta útil para eventos deportivos, concursos en vivo, etc.)

Debido a que la conexión tiene una pequeña ventana de almacenamiento intermedio, si la red se congestiona o el ancho de banda es bajo, el buffer se duplicará si el dispositivo no puede mantener la conexión apropiada.

When set to a value greater than zero (>0) the SDK will buffer that many seconds of audio before beginning playback.

Use SettingsLowDelayKey with an NSNumber object for this feature. Valid values: -1 (AUTO mode), 0 (Disabled) , 2 to 60 seconds.

By default the feature is disabled ( 0 ).

Ejemplo de baja demora en Android

// Cree las configuraciones del reproductor.
Bundle settings = new Bundle();
Integer lowDelayValue = 2;
settings.putString(TritonPlayer.SETTINGS_STATION_BROADCASTER,   "Triton Digital");
settings.putString(TritonPlayer.SETTINGS_STATION_NAME,          "MOBILEFM");
settings.putString(TritonPlayer.SETTINGS_STATION_MOUNT,         "MOBILEFM_AACV2");
settings.putInt(TritonPlayer.SETTINGS_LOW_DELAY,                lowDelayValue);
 
// Create the player.
TritonPlayer player = new TritonPlayer(this, settings);
player.play();

Timeshift

For more information about Timeshift Radio, see the Streaming Specification.

For the Timeshift stream to work, use following property:

TritonPlayer.SETTINGS_STATION_MOUNT

Seek Forward or Backward

To seek forward and backward use the seek() function, which takes a value in seconds as a parameter. If the parameter is positive, you seek forward; if it is negative you seek backward. If the value is zero then you seek to the live point.

E.g.: seek(-10), seek(10), seek(0)

// Cree las configuraciones del reproductor.
Bundle settings = new Bundle();
settings.putBoolean(TritonPlayer.SETTINGS_TIMESHIFT_ENABLED, true);
settings.putString(TritonPlayer.SETTINGS_STATION_BROADCASTER,    "Triton Digital");
settings.putString(TritonPlayer.SETTINGS_STATION_NAME,           "MOBILEFM");
settings.putString(TritonPlayer.SETTINGS_STATION_MOUNT,          "MOBILEFM_AACV2");
 
// Create the player.
TritonPlayer player = new TritonPlayer(this, settings);
player.play();
 
...
player.seek(10);

Seek To Live

To return to the live stream use the seekToLive() function. This will stop the Timeshift stream and connect again to the live stream.

Get Cloud Stream

To get the programs associated with the station use the getCloudStreamInfo() function. When the list of programs is received, a notification is sent to the OnCloudStreamInfoReceivedListener in the MediaPlayer class.

The JSON object looks like this:

{
     "maximumRewindTimeSec": 10800,
     "programs": {
           "name": "program",
           "program_episode_id": "99999-1678715517259",
           "properties": {
                 "cue_id": "23337",
                 "cue_time_start": "1678715517259",
                 "cue_title": "ProgramStart",
                 "program_id": "99999",
                 "program_time_start": "1678715517259",
                 "program_title": "Messy Gossip with Blork",
                 "stw_cached": "false",
                 "stw_original_type": "stwcue"
           }
     }
}

Play Program

Use playProgram(String programId) to select a specific program. The programId is the program_episode_id that is in the returned JSON object.

Dist Parameter

To use the dist parameter with Timeshift you need to add both timeshifting parameters:

  • StreamUrlBuilder.DIST : used when the stream is connected in live mode.

  • StreamUrlBuilder.DIST_TIMESHIFT : used when the stream is in Timeshift mode.

Example of how to add the parameters:

// Create the targeting parameters
HashMap<String, String> targetingParams = new HashMap();
targetingParams.put(StreamUrlBuilder.DIST_TIMESHIFT, "timeshift-dist-param");
targetingParams.put(StreamUrlBuilder.DIST, "triton-dist-param");

// Create the player settings.
Bundle settings = new Bundle();
settings.putSerializable(TritonPlayer.SETTINGS_TARGETING_PARAMS, targetingParams);
settings.putString(TritonPlayer.SETTINGS_STATION_BROADCASTER,    "Triton Digital");
settings.putString(TritonPlayer.SETTINGS_STATION_NAME,           "MOBILEFM");
settings.putString(TritonPlayer.SETTINGS_STATION_MOUNT,          "MOBILEFM_AACV2");

// Create the player.
TritonPlayer player = new TritonPlayer(this, settings);
player.play();


© 2026 Triton Digital. Todos los derechos reservados.