// Path: app/src/main/java/com/commonslab/commonslab/Activities/MainActivity.java
// public static final String PAUSE_OPUS = "org.wikimedia.commons.wikimedia.PAUSE_OPUS";
// 
// Path: app/src/main/java/com/commonslab/commonslab/Activities/MainActivity.java
// public static final String PLAY_OPUS = "org.wikimedia.commons.wikimedia.PLAY_OPUS";
// 
// Path: app/src/main/java/com/commonslab/commonslab/Activities/MainActivity.java
// public static final String SEEKBAR_UPDATE_OPUS = "org.wikimedia.commons.wikimedia.SEEKBAR_UPDATE_OPUS";
// 
// Path: app/src/main/java/com/commonslab/commonslab/Activities/MainActivity.java
// public static final String STOP_OPUS = "org.wikimedia.commons.wikimedia.STOP_OPUS";


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.Toast;
import com.audionowdigital.android.openplayer.Player;
import com.audionowdigital.android.openplayer.PlayerEvents;
import com.commonslab.commonslab.R;
import static com.commonslab.commonslab.Activities.MainActivity.PAUSE_OPUS;
import static com.commonslab.commonslab.Activities.MainActivity.PLAY_OPUS;
import static com.commonslab.commonslab.Activities.MainActivity.SEEKBAR_UPDATE_OPUS;
import static com.commonslab.commonslab.Activities.MainActivity.STOP_OPUS;
    public OpusPlayer(Context context, int LENGTH, String mediaURL) {
        this.LENGTH = LENGTH;
        this.mediaURL = mediaURL;
        this.context = context;
        init();
    }

    private void init() {

        playbackHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case PlayerEvents.PLAYING_FAILED:
                        showToastMessage(context.getString(R.string.the_decoder_failed_to_playback_the_file));
                        context.sendBroadcast(broadcastIntent);

                        Log.d(TAG, "The decoder failed to playback the file, check logs for more details");
                        break;
                    case PlayerEvents.PLAYING_FINISHED:
                        Log.d(TAG, "The decoder finished successfully");
                        context.sendBroadcast(broadcastIntent);
                        break;
                    case PlayerEvents.READING_HEADER:
                        Log.d(TAG, "Starting to read header");
                        break;
                    case PlayerEvents.READY_TO_PLAY:
                        Log.d(TAG, "READY to play - press play :)");
                        if (player != null && player.isReadyToPlay()) {
                            player.play();
// Path: app/src/main/java/com/commonslab/commonslab/Activities/MainActivity.java
// public static final String PAUSE_OPUS = "org.wikimedia.commons.wikimedia.PAUSE_OPUS";
// 
// Path: app/src/main/java/com/commonslab/commonslab/Activities/MainActivity.java
// public static final String PLAY_OPUS = "org.wikimedia.commons.wikimedia.PLAY_OPUS";
// 
// Path: app/src/main/java/com/commonslab/commonslab/Activities/MainActivity.java
// public static final String SEEKBAR_UPDATE_OPUS = "org.wikimedia.commons.wikimedia.SEEKBAR_UPDATE_OPUS";
// 
// Path: app/src/main/java/com/commonslab/commonslab/Activities/MainActivity.java
// public static final String STOP_OPUS = "org.wikimedia.commons.wikimedia.STOP_OPUS";


// Path: app/src/main/java/com/commonslab/commonslab/AudioPlayer/OpusPlayer.java
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.Toast;
import com.audionowdigital.android.openplayer.Player;
import com.audionowdigital.android.openplayer.PlayerEvents;
import com.commonslab.commonslab.R;
import static com.commonslab.commonslab.Activities.MainActivity.PAUSE_OPUS;
import static com.commonslab.commonslab.Activities.MainActivity.PLAY_OPUS;
import static com.commonslab.commonslab.Activities.MainActivity.SEEKBAR_UPDATE_OPUS;
import static com.commonslab.commonslab.Activities.MainActivity.STOP_OPUS;

    public OpusPlayer(Context context, int LENGTH, String mediaURL) {
        this.LENGTH = LENGTH;
        this.mediaURL = mediaURL;
        this.context = context;
        init();
    }

    private void init() {

        playbackHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case PlayerEvents.PLAYING_FAILED:
                        showToastMessage(context.getString(R.string.the_decoder_failed_to_playback_the_file));
                        context.sendBroadcast(broadcastIntent);

                        Log.d(TAG, "The decoder failed to playback the file, check logs for more details");
                        break;
                    case PlayerEvents.PLAYING_FINISHED:
                        Log.d(TAG, "The decoder finished successfully");
                        context.sendBroadcast(broadcastIntent);
                        break;
                    case PlayerEvents.READING_HEADER:
                        Log.d(TAG, "Starting to read header");
                        break;
                    case PlayerEvents.READY_TO_PLAY:
                        Log.d(TAG, "READY to play - press play :)");
                        if (player != null && player.isReadyToPlay()) {
                            player.play();
                            Intent intent = new Intent(PLAY_OPUS);