Sample App

You can download the whole sample app from here.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@android:color/darker_gray"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<com.adorilabs.sdk.ui.UI.AdoriTagsView
    android:id="@+id/tagsView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.adorilabs.samples.adori;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.adorilabs.sdk.ui.UI.AdoriTagsView;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.ProgressiveMediaSource;


public class MainActivity extends AppCompatActivity{

    AdoriTagsView adoriTagsView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //Set the adoriTagsView to the tagsUI object
        adoriTagsView = findViewById(R.id.tagsView);

        // Do not re-initiate player for orientation changes
        if (savedInstanceState == null) {
            MediaSource audioSource = new ProgressiveMediaSource.Factory(Player.getInstance(this).dataSourceFactory)
                    .createMediaSource(MediaItem.fromUri(
                            "https://static.adorilabs.com/audiotracks/v1/1117-IRATvhWXzWyt3kT4_adorified.mp3"));
            Player.getInstance(this).player.setMediaSource(audioSource);
            Player.getInstance(this).player.prepare();
            Player.getInstance(this).player.setPlayWhenReady(true);
        }

    }

    @Override
    public void onResume() {
        super.onResume();
        adoriTagsView.setTagService(Player.getInstance(this).adoriTagsService);
    }

    @Override
    public void onPause() {
        super.onPause();
        adoriTagsView.release();
    }

}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.adorilabs.samples.adori;

import android.content.Context;

import com.adorilabs.sdk.player.AdoriMediaCodecAudioRendererFactory;
import com.adorilabs.sdk.ui.AdoriTagsService;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
import com.google.android.exoplayer2.util.Util;

class Player {

    private static Player ourInstance;
    AdoriTagsService adoriTagsService;
    SimpleExoPlayer player;
    DataSource.Factory dataSourceFactory;

    static Player getInstance(Context context) {
        if (ourInstance == null) {
            ourInstance = new Player(context.getApplicationContext());
        }
        return ourInstance;
    }

    private Player(Context context) {
        dataSourceFactory = new DefaultDataSourceFactory(context,
                null,
                new DefaultHttpDataSourceFactory(Util.getUserAgent(
                        context, "Adori"),
                        null,
                        DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
                        DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS,
                        true));

        //Create AdoriMediaCodecRendererFactory
        AdoriMediaCodecAudioRendererFactory adoriMediaCodecAudioRendererFactory
                = new AdoriMediaCodecAudioRendererFactory(context);

        //Use the AdoriMediaCodecRenderFactory with the Exoplayer builder
        player = new SimpleExoPlayer.Builder(context,
                adoriMediaCodecAudioRendererFactory).build();

        //Create the AdoriTagsService object
        adoriTagsService = new AdoriTagsService(context);

        /*Connect the AdoriMediaCodecRendererFactory
        and Player to the TagsService */
        adoriTagsService.setPlayer(player);
        adoriTagsService.setAdoriMediaCodecAudioRendererFactory(
                adoriMediaCodecAudioRendererFactory);
    }

}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
package com.adorilabs.samples.adori;

import android.app.Application;
import android.content.Context;

import com.adorilabs.sdk.ui.AdoriSDKClient;

public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        AdoriSDKClient.setup(this);

        // If the user is already logged in set the user id
        // AdoriSDKClient.setUserId(<user_id>);
    }

}