导航菜单

页面标题

页面副标题

Vi App v10.18.0 - ChromeCastUtils.java 源代码

正在查看: Vi App v10.18.0 应用的 ChromeCastUtils.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.yupptv.ott.utils;

import android.content.Context;
import android.net.Uri;
import com.google.android.gms.cast.MediaInfo;
import com.google.android.gms.cast.MediaMetadata;
import com.google.android.gms.cast.MediaQueueItem;
import com.google.android.gms.cast.framework.CastSession;
import com.google.android.gms.cast.framework.media.RemoteMediaClient;
import com.google.android.gms.common.images.WebImage;
import com.google.gson.Gson;
import com.yupptv.ott.FusionViliteMainActivity;
import com.yupptv.ottsdk.model.ContentPage;
import java.util.ArrayList;
import org.json.JSONException;
import org.json.JSONObject;

public class ChromeCastUtils {
    public static Context activity;
    public static ChromeCastUtils mChromeCastUtils;

    public static MediaInfo buildMediaInfo(String str, String str2, String str3, String str4, int i2, String str5, Object obj, String str6, String str7, String str8) {
        Object obj2;
        JSONObject jSONObject = new JSONObject();
        if (str5 != null && str5.isEmpty()) {
            str5.equalsIgnoreCase(Constants.LICENSE_URL_NOT_REQUIRED);
        }
        try {
            String contentType = getContentType(str6);
            if (contentType.trim().length() > 0) {
                jSONObject.put("type", contentType);
                try {
                    if (contentType.equalsIgnoreCase("movie")) {
                        jSONObject.put("data", new JSONObject(new Gson().toJson(obj)));
                        Object obj3 = activity;
                        if (obj3 != null && (obj3 instanceof FusionViliteMainActivity)) {
                            ((FusionViliteMainActivity) obj3).saveCastObject(new JSONObject(new Gson().toJson(obj)));
                        }
                    } else if ((obj instanceof ContentPage) && (obj2 = activity) != null && (obj2 instanceof FusionViliteMainActivity)) {
                        ((FusionViliteMainActivity) obj2).saveCastObject(new JSONObject(new Gson().toJson(obj)));
                    }
                } catch (Exception unused) {
                }
            } else {
                jSONObject.put("type", "none");
            }
            if (str6 != null && str6.trim().length() > 0) {
                jSONObject.put("metaDataId", str6);
            }
            jSONObject.put("previewDuration", i2);
            if ((str7 != null && str7.trim().length() > 0) || str8.trim().length() > 0) {
                jSONObject.put("licenseUrl", str7);
            } else if (str5 != null && str5.trim().length() > 0) {
                jSONObject.put("licenseUrl", str5);
            }
        } catch (JSONException unused2) {
        }
        MediaMetadata mediaMetadata = new MediaMetadata(1);
        if (str3 == null || str3.trim().length() <= 0) {
            mediaMetadata.putString("com.google.android.gms.cast.metadata.TITLE", "not available");
        } else {
            mediaMetadata.putString("com.google.android.gms.cast.metadata.TITLE", str3);
        }
        if (str4 != null && str4.trim().length() > 0) {
            mediaMetadata.putString("com.google.android.gms.cast.metadata.SUBTITLE", str4);
        }
        mediaMetadata.putString("com.google.android.gms.cast.metadata.STUDIO", "OTT");
        if (str2 == null || str2.trim().length() <= 0) {
            mediaMetadata.addImage(new WebImage(Uri.parse("http://ottapps.revlet.net/apps/androiddevices/default_poster.png")));
            mediaMetadata.addImage(new WebImage(Uri.parse("http://ottapps.revlet.net/apps/androiddevices/default_poster.png")));
        } else {
            Uri parse = Uri.parse(str2);
            mediaMetadata.addImage(new WebImage(parse));
            mediaMetadata.addImage(new WebImage(parse));
        }
        return (str7 == null || str7.isEmpty()) ? (str8 == null || str8.length() <= 0) ? new MediaInfo.Builder(str).setStreamType(1).setContentType("application/x-mpegurl").setCustomData(jSONObject).setMetadata(mediaMetadata).build() : new MediaInfo.Builder(str8).setStreamType(1).setContentType("application/x-mpegurl").setCustomData(jSONObject).setMetadata(mediaMetadata).build() : new MediaInfo.Builder(str8).setStreamType(1).setContentType("application/dash+xml").setCustomData(jSONObject).setMetadata(mediaMetadata).build();
    }

    public static String getContentType(String str) {
        if (str != null && !str.equalsIgnoreCase("")) {
            if (str.contains("live")) {
                return "live";
            }
            if (str.contains("movie")) {
                return "movie";
            }
        }
        return "none";
    }

    public static Object getCustomDataJson(MediaInfo mediaInfo) throws JSONException {
        if (mediaInfo == null) {
            throw new JSONException("Media info is null");
        }
        JSONObject customData = mediaInfo.getCustomData();
        if (customData == null || !customData.has("data")) {
            return null;
        }
        return customData.getString("data");
    }

    public static String getCustomMetaDataJson(MediaInfo mediaInfo) throws JSONException {
        if (mediaInfo == null) {
            throw new JSONException("Media info is null");
        }
        JSONObject customData = mediaInfo.getCustomData();
        return (customData == null || !customData.has("metaDataId")) ? "none" : customData.getString("metaDataId");
    }

    public static ChromeCastUtils getInsatnce(Context context) {
        if (mChromeCastUtils == null) {
            activity = context;
            mChromeCastUtils = new ChromeCastUtils();
        }
        return mChromeCastUtils;
    }

    public static void loadRemoteMedia(CastSession castSession, String str, String str2, long j, String str3, String str4, int i2, String str5, Object obj, String str6, String str7, String str8) {
        CustomLog.e("TAG", "loadRemoteMedia : enter");
        if (castSession == null) {
            return;
        }
        Preferences.instance(activity).setBooleanPreference("chromecast_stopped", Boolean.FALSE);
        RemoteMediaClient remoteMediaClient = castSession.getRemoteMediaClient();
        if (remoteMediaClient == null) {
            return;
        }
        remoteMediaClient.load(buildMediaInfo(str, str2, str3, str4, i2, str5, obj, str6, str7, str8), true, j);
    }

    public static void loadRemoteMediaQueue(CastSession castSession, ArrayList<String> arrayList, String str, long j, String str2, String str3, int i2, int i3, String str4, Object obj, String str5, String str6, String str7) {
        if (castSession == null) {
            return;
        }
        Preferences.instance(activity).setBooleanPreference("chromecast_stopped", Boolean.FALSE);
        RemoteMediaClient remoteMediaClient = castSession.getRemoteMediaClient();
        if (remoteMediaClient == null) {
            return;
        }
        MediaQueueItem[] mediaQueueItemArr = new MediaQueueItem[arrayList.size()];
        for (int i4 = i2; i4 < arrayList.size(); i4++) {
            try {
                try {
                    mediaQueueItemArr[i4] = new MediaQueueItem.Builder(buildMediaInfo(arrayList.get(i4), str, str2, str3, i3, str4, obj, str5, str6, str7)).build();
                } catch (Exception unused) {
                }
            } catch (Exception unused2) {
            }
        }
        remoteMediaClient.queueLoad(mediaQueueItemArr, i2, 0, j, (JSONObject) null);
    }

    public static void stopChromecast(CastSession castSession) {
        RemoteMediaClient remoteMediaClient;
        if (castSession == null || (remoteMediaClient = castSession.getRemoteMediaClient()) == null) {
            return;
        }
        remoteMediaClient.stop();
        Preferences.instance(activity).setBooleanPreference("chromecast_stopped", Boolean.TRUE);
    }
}