package com.nexstreaming.app.util;


import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.os.Build;

import com.nexstreaming.nexplayerengine.NexPlayer;
import com.nexstreaming.nexplayerengine.NexSystemInfo;

import java.lang.reflect.Field;

public class Util {

    public static String formatTime(final int timeMs) {
        if (timeMs < 1000) {
            return "00:00";
        }
        String result = "";
        final int totalSec = timeMs / 1000;
        final int hours = totalSec / 3600;
        final int minutes = (totalSec / 60) % 60;
        final int seconds = totalSec % 60;

        if (hours > 0) {
            result += hours + ":";
        }
        if (minutes >= 10) {
            result += minutes + ":";
        } else {
            result += "0" + minutes + ":";
        }
        if (seconds >= 10) {
            result += seconds;
        } else {
            result += "0" + seconds;
        }
        return result;
    }

    public static String getEnginePath(Context context) {
        String engine = "libnexplayerengine.so";

        Context iContext = context.getApplicationContext();
        String strPath = iContext.getFilesDir().getAbsolutePath();

        String strLibPath = "";

        int iPackageNameLength = iContext.getPackageName().length();
        int iStartIndex = strPath.indexOf(iContext.getPackageName());

        strLibPath = strPath.substring(0, iStartIndex + iPackageNameLength) + "/";
        final ApplicationInfo applicationInfo = context.getApplicationInfo();
        String strNativePath = strLibPath;
        try
        {
            if(Build.VERSION.SDK_INT >= 9)
            {
                Field f = ApplicationInfo.class.getField("nativeLibraryDir");
                strNativePath = (String) f.get(applicationInfo) + "/";
            }
        }
        catch (Exception e)
        {

        }

        String ret = strNativePath + engine;
        return ret;
    }

}