APK反编译源代码展示 - 南明离火平台提供

应用版本信息
应用名称:Miracast
版本号:1.1.8
包名称:com.cast4tv.miracast

MD5 校验值:45d98ec70237405b7ecec7a7457a5f8b

反编译源代码说明

AVPlayerImpl.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。


package com.sec.android.allshare;

import android.net.Uri;
import android.os.Bundle;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.sec.android.allshare.Device;
import com.sec.android.allshare.Item;
import com.sec.android.allshare.iface.CVMessage;
import com.sec.android.allshare.iface.IBundleHolder;
import com.sec.android.allshare.iface.IHandlerHolder;
import com.sec.android.allshare.iface.message.AllShareAction;
import com.sec.android.allshare.iface.message.AllShareEvent;
import com.sec.android.allshare.iface.message.AllShareKey;
import com.sec.android.allshare.media.AVPlayer;
import com.sec.android.allshare.media.ContentInfo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

public final class AVPlayerImpl extends AVPlayer implements IBundleHolder, IHandlerHolder {
    private static int[] $SWITCH_TABLE$com$sec$android$allshare$Item$MediaType = null;
    private static final String TAG_CLASS = "AVPlayerImpl";
    private IAllShareConnector mAllShareConnector;
    private DeviceImpl mDeviceImpl;
    private AVPlayer.IAVPlayerEventListener mAVPlayerEventListener = null;
    private AVPlayer.IAVPlayerPlaybackResponseListener mAVPlaybackResponseListener = null;
    private AVPlayer.IAVPlayerVolumeResponseListener mAVPlayerVolumeResponseListener = null;
    private boolean mIsSubscribed = false;
    private boolean mContentChangedNotified = true;
    private ArrayList<String> mPlayingContentUris = new ArrayList<>();
    private AllShareEventHandler mEventHandler = new AllShareEventHandler(ServiceConnector.getMainLooper()) {
        private HashMap<String, AVPlayer.AVPlayerState> mAVStateMap;

        {
            HashMap<String, AVPlayer.AVPlayerState> hashMap = new HashMap<>();
            this.mAVStateMap = hashMap;
            hashMap.put(AllShareEvent.EVENT_RENDERER_STATE_BUFFERING, AVPlayer.AVPlayerState.BUFFERING);
            this.mAVStateMap.put(AllShareEvent.EVENT_RENDERER_STATE_PAUSED, AVPlayer.AVPlayerState.PAUSED);
            this.mAVStateMap.put(AllShareEvent.EVENT_RENDERER_STATE_STOPPED, AVPlayer.AVPlayerState.STOPPED);
            this.mAVStateMap.put(AllShareEvent.EVENT_RENDERER_STATE_PLAYING, AVPlayer.AVPlayerState.PLAYING);
            this.mAVStateMap.put(AllShareEvent.EVENT_RENDERER_STATE_NOMEDIA, AVPlayer.AVPlayerState.STOPPED);
            this.mAVStateMap.put(AllShareEvent.EVENT_RENDERER_STATE_CONTENT_CHANGED, AVPlayer.AVPlayerState.CONTENT_CHANGED);
        }

        @Override
        public void handleEventMessage(CVMessage cVMessage) {
            ERROR valueOf;
            String string;
            try {
                ERROR error = ERROR.FAIL;
                Bundle bundle = cVMessage.getBundle();
                String string2 = bundle.getString("BUNDLE_ENUM_ERROR");
                if (string2 == null) {
                    valueOf = ERROR.FAIL;
                } else {
                    valueOf = ERROR.valueOf(string2);
                }
                AVPlayer.AVPlayerState aVPlayerState = this.mAVStateMap.get(cVMessage.getActionID());
                if (aVPlayerState == null) {
                    aVPlayerState = AVPlayer.AVPlayerState.UNKNOWN;
                }
                if (aVPlayerState.equals(AVPlayer.AVPlayerState.CONTENT_CHANGED)) {
                    if (!AVPlayerImpl.this.mContentChangedNotified && (string = bundle.getString(AllShareKey.BUNDLE_STRING_APP_ITEM_ID)) != null && AVPlayerImpl.this.mPlayingContentUris != null && !AVPlayerImpl.this.mPlayingContentUris.isEmpty()) {
                        if (!isContains(string, AVPlayerImpl.this.mPlayingContentUris)) {
                            AVPlayerImpl.this.mContentChangedNotified = true;
                            DLog.i_api(AVPlayerImpl.TAG_CLASS, "Notify ContentChanged event, current track uri: " + string);
                        } else {
                            DLog.d_api(AVPlayerImpl.TAG_CLASS, "handleEventMessage: this is playing content.");
                            return;
                        }
                    }
                    return;
                }
                notifyEvent(aVPlayerState, valueOf);
            } catch (Error e) {
                DLog.w_api(AVPlayerImpl.TAG_CLASS, "handleEventMessage Error", e);
            } catch (Exception unused) {
                DLog.w_api(AVPlayerImpl.TAG_CLASS, "handleEventMessage Fail to notify event : Exception");
            }
        }

        private void notifyEvent(AVPlayer.AVPlayerState aVPlayerState, ERROR error) {
            if (AVPlayerImpl.this.mAVPlayerEventListener != null) {
                try {
                    AVPlayerImpl.this.mAVPlayerEventListener.onDeviceChanged(aVPlayerState, error);
                } catch (Exception e) {
                    DLog.w_api(AVPlayerImpl.TAG_CLASS, "mEventHandler.notifyEvent Error", e);
                }
            }
        }

        private boolean isContains(String str, ArrayList<String> arrayList) {
            if (arrayList == null || str == null) {
                return false;
            }
            Iterator<String> it = arrayList.iterator();
            while (it.hasNext()) {
                if (str.endsWith(it.next())) {
                    return true;
                }
            }
            return false;
        }
    };
    private AllShareResponseHandler mAllShareRespHandler = new AllShareResponseHandler(ServiceConnector.getMainLooper()) {
        @Override
        public void handleResponseMessage(CVMessage cVMessage) {
            AVPlayer.AVPlayerState aVPlayerState;
            String actionID = cVMessage.getActionID();
            Bundle bundle = cVMessage.getBundle();
            if (actionID == null || bundle == null) {
                return;
            }
            ERROR valueOf = ERROR.valueOf(bundle.getString("BUNDLE_ENUM_ERROR"));
            if ((actionID.equals(AllShareAction.ACTION_AV_PLAYER_PLAY_LOCAL_CONTENS_URI) || actionID.equals(AllShareAction.ACTION_AV_PLAYER_PLAY_LOCAL_CONTENS_FILEPATH_WITH_METADATA) || actionID.equals(AllShareAction.ACTION_AV_PLAYER_PLAY_LOCAL_CONTENS_FILEPATH) || actionID.equals(AllShareAction.ACTION_AV_PLAYER_PLAY_URI) || actionID.equals(AllShareAction.ACTION_AV_PLAYER_PLAY)) && valueOf.equals(ERROR.SUCCESS)) {
                ArrayList<String> stringArrayList = bundle.getStringArrayList(AllShareKey.BUNDLE_STRING_SERVER_URI_LIST);
                if (stringArrayList != null) {
                    AVPlayerImpl.this.mPlayingContentUris.clear();
                    Iterator<String> it = stringArrayList.iterator();
                    while (it.hasNext()) {
                        AVPlayerImpl.this.mPlayingContentUris.add(it.next());
                    }
                }
                AVPlayerImpl.this.mContentChangedNotified = false;
            }
            if (AVPlayerImpl.this.mAVPlaybackResponseListener != null) {
                if (actionID.equals(AllShareAction.ACTION_AV_PLAYER_PLAY) || actionID.equals(AllShareAction.ACTION_AV_PLAYER_PLAY_LOCAL_CONTENS_URI) || actionID.equals(AllShareAction.ACTION_AV_PLAYER_PLAY_LOCAL_CONTENS_FILEPATH_WITH_METADATA) || actionID.equals(AllShareAction.ACTION_AV_PLAYER_PLAY_LOCAL_CONTENS_FILEPATH) || actionID.equals(AllShareAction.ACTION_AV_PLAYER_PLAY_WEB_CONTENTS) || actionID.equals(AllShareAction.ACTION_AV_PLAYER_PLAY_URI)) {
                    notifyPlaybackEvent(bundle, valueOf);
                } else if (actionID.equals(AllShareAction.ACTION_AV_PLAYER_STOP)) {
                    AVPlayerImpl.this.mAVPlaybackResponseListener.onStopResponseReceived(valueOf);
                } else if (actionID.equals(AllShareAction.ACTION_AV_PLAYER_SEEK)) {
                    AVPlayerImpl.this.mAVPlaybackResponseListener.onSeekResponseReceived(bundle.getLong(AllShareKey.BUNDLE_LONG_POSITION), valueOf);
                } else if (actionID.equals(AllShareAction.ACTION_AV_PLAYER_PAUSE)) {
                    AVPlayerImpl.this.mAVPlaybackResponseListener.onPauseResponseReceived(valueOf);
                } else if (actionID.equals(AllShareAction.ACTION_AV_PLAYER_RESUME)) {
                    AVPlayerImpl.this.mAVPlaybackResponseListener.onResumeResponseReceived(valueOf);
                } else if (actionID.equals(AllShareAction.ACTION_AV_PLAYER_REQUEST_PLAY_POSITION)) {
                    AVPlayerImpl.this.mAVPlaybackResponseListener.onGetPlayPositionResponseReceived(bundle.getLong(AllShareKey.BUNDLE_LONG_POSITION), valueOf);
                } else if (actionID.equals(AllShareAction.ACTION_AV_PLAYER_REQUEST_GET_MEDIA_INFO)) {
                    AVPlayerImpl.this.mAVPlaybackResponseListener.onGetMediaInfoResponseReceived(ERROR.SUCCESS.equals(valueOf) ? new MediaInfoImpl(bundle) : null, valueOf);
                } else if (actionID.equals(AllShareAction.ACTION_AV_PLAYER_REQUEST_GET_PLAYER_STATE)) {
                    String string = bundle.getString(AllShareKey.BUNDLE_STRING_AV_PLAER_STATE);
                    AVPlayer.AVPlayerState aVPlayerState2 = AVPlayer.AVPlayerState.UNKNOWN;
                    try {
                        aVPlayerState = AVPlayer.AVPlayerState.valueOf(string);
                    } catch (Exception e) {
                        AVPlayer.AVPlayerState aVPlayerState3 = AVPlayer.AVPlayerState.UNKNOWN;
                        DLog.w_api(AVPlayerImpl.TAG_CLASS, "AVPlayerState Exception", e);
                        aVPlayerState = aVPlayerState3;
                    }
                    AVPlayerImpl.this.mAVPlaybackResponseListener.onGetStateResponseReceived(aVPlayerState, valueOf);
                }
            }
            if (AVPlayerImpl.this.mAVPlayerVolumeResponseListener != null) {
                if (actionID.equals(AllShareAction.ACTION_AV_PLAYER_REQUEST_GET_VOLUME)) {
                    AVPlayerImpl.this.mAVPlayerVolumeResponseListener.onGetVolumeResponseReceived(bundle.getInt(AllShareKey.BUNDLE_INT_VOLUME), valueOf);
                    return;
                }
                if (actionID.equals(AllShareAction.ACTION_AV_PLAYER_REQUEST_SET_VOLUME)) {
                    AVPlayerImpl.this.mAVPlayerVolumeResponseListener.onSetVolumeResponseReceived(bundle.getInt(AllShareKey.BUNDLE_INT_VOLUME), valueOf);
                } else if (actionID.equals(AllShareAction.ACTION_AV_PLAYER_REQUEST_GET_MUTE)) {
                    AVPlayerImpl.this.mAVPlayerVolumeResponseListener.onGetMuteResponseReceived(bundle.getBoolean(AllShareKey.BUNDLE_BOOLEAN_MUTE), valueOf);
                } else if (actionID.equals(AllShareAction.ACTION_AV_PLAYER_REQUEST_SET_MUTE)) {
                    AVPlayerImpl.this.mAVPlayerVolumeResponseListener.onSetMuteResponseReceived(bundle.getBoolean(AllShareKey.BUNDLE_BOOLEAN_MUTE), valueOf);
                }
            }
        }

        private void notifyPlaybackEvent(Bundle bundle, ERROR error) {
            Bundle bundle2 = (Bundle) bundle.getParcelable(AllShareKey.BUNDLE_PARCELABLE_ITEM);
            ContentInfo build = new ContentInfo.Builder().setStartingPosition(bundle.getLong(AllShareKey.BUNDLE_LONG_CONTENT_INFO_STARTINGPOSITION)).build();
            Item fromBundle = ItemCreator.fromBundle(bundle2);
            String string = bundle2.getString(AllShareKey.BUNDLE_STRING_ITEM_CONSTRUCTOR_KEY);
            if (string != null && string.equals("WEB_CONTENT") && build != null) {
                ContentInfo.Builder builder = new ContentInfo.Builder();
                builder.setStartingPosition((int) (build.getStartingPosition() / 1000));
                build = builder.build();
            }
            if (fromBundle != null) {
                AVPlayerImpl.this.mAVPlaybackResponseListener.onPlayResponseReceived(fromBundle, build, error);
            } else {
                AVPlayerImpl.this.mAVPlaybackResponseListener.onPlayResponseReceived(fromBundle, build, ERROR.ITEM_NOT_EXIST);
            }
        }
    };

    static int[] $SWITCH_TABLE$com$sec$android$allshare$Item$MediaType() {
        int[] iArr = $SWITCH_TABLE$com$sec$android$allshare$Item$MediaType;
        if (iArr != null) {
            return iArr;
        }
        int[] iArr2 = new int[Item.MediaType.valuesCustom().length];
        try {
            iArr2[Item.MediaType.ITEM_AUDIO.ordinal()] = 2;
        } catch (NoSuchFieldError unused) {
        }
        try {
            iArr2[Item.MediaType.ITEM_FOLDER.ordinal()] = 1;
        } catch (NoSuchFieldError unused2) {
        }
        try {
            iArr2[Item.MediaType.ITEM_IMAGE.ordinal()] = 3;
        } catch (NoSuchFieldError unused3) {
        }
        try {
            iArr2[Item.MediaType.ITEM_UNKNOWN.ordinal()] = 5;
        } catch (NoSuchFieldError unused4) {
        }
        try {
            iArr2[Item.MediaType.ITEM_VIDEO.ordinal()] = 4;
        } catch (NoSuchFieldError unused5) {
        }
        $SWITCH_TABLE$com$sec$android$allshare$Item$MediaType = iArr2;
        return iArr2;
    }

    public AVPlayerImpl(IAllShareConnector iAllShareConnector, DeviceImpl deviceImpl) {
        this.mDeviceImpl = null;
        if (iAllShareConnector == null) {
            DLog.w_api(TAG_CLASS, "Connection FAIL: AllShare Service Connector does not exist");
            return;
        }
        if (deviceImpl == null) {
            DLog.w_api(TAG_CLASS, "deviceImpl is null");
            return;
        }
        this.mAllShareConnector = iAllShareConnector;
        this.mDeviceImpl = deviceImpl;
        if (deviceImpl.getBundle() == null) {
            DLog.w_api(TAG_CLASS, "deviceImpl.getBundle is null");
        }
    }

    @Override
    public void play(Item item, ContentInfo contentInfo) {
        IAllShareConnector iAllShareConnector = this.mAllShareConnector;
        if (iAllShareConnector == null || !iAllShareConnector.isAllShareServiceConnected()) {
            DLog.w_api(TAG_CLASS, "play fail : SERVICE_NOT_CONNECTED");
            this.mAVPlaybackResponseListener.onPlayResponseReceived(item, contentInfo, ERROR.SERVICE_NOT_CONNECTED);
            return;
        }
        if (item == 0) {
            DLog.w_api(TAG_CLASS, "play item == null");
            AVPlayer.IAVPlayerPlaybackResponseListener iAVPlayerPlaybackResponseListener = this.mAVPlaybackResponseListener;
            if (iAVPlayerPlaybackResponseListener != null) {
                iAVPlayerPlaybackResponseListener.onPlayResponseReceived(item, contentInfo, ERROR.INVALID_ARGUMENT);
                return;
            }
            return;
        }
        this.mPlayingContentUris.clear();
        this.mContentChangedNotified = false;
        Item.MediaType type = item.getType();
        if (type == null) {
            DLog.w_api(TAG_CLASS, "Invalid media type");
            AVPlayer.IAVPlayerPlaybackResponseListener iAVPlayerPlaybackResponseListener2 = this.mAVPlaybackResponseListener;
            if (iAVPlayerPlaybackResponseListener2 != null) {
                iAVPlayerPlaybackResponseListener2.onPlayResponseReceived(item, contentInfo, ERROR.INVALID_ARGUMENT);
                return;
            }
            return;
        }
        int i = $SWITCH_TABLE$com$sec$android$allshare$Item$MediaType()[type.ordinal()];
        if (i != 2 && i != 4) {
            DLog.w_api(TAG_CLASS, "Invalid media type");
            AVPlayer.IAVPlayerPlaybackResponseListener iAVPlayerPlaybackResponseListener3 = this.mAVPlaybackResponseListener;
            if (iAVPlayerPlaybackResponseListener3 != null) {
                iAVPlayerPlaybackResponseListener3.onPlayResponseReceived(item, contentInfo, ERROR.INVALID_ARGUMENT);
                return;
            }
            return;
        }
        Bundle bundle = new Bundle();
        if (item instanceof IBundleHolder) {
            bundle = ((IBundleHolder) item).getBundle();
        }
        String string = bundle.getString(AllShareKey.BUNDLE_STRING_ITEM_MIMETYPE);
        String string2 = bundle.getString(AllShareKey.BUNDLE_STRING_ITEM_CONSTRUCTOR_KEY);
        if (string2.equals("WEB_CONTENT")) {
            DLog.d_api(TAG_CLASS, "play WEB_CONTENT - " + item.getTitle() + " to " + getName());
            StringBuilder sb = new StringBuilder("play URI ");
            sb.append(item.getURI());
            DLog.d_api(TAG_CLASS, sb.toString());
            if (string.contains("image") || item.getURI() == null) {
                DLog.w_api(TAG_CLASS, "try to play invalid content");
                AVPlayer.IAVPlayerPlaybackResponseListener iAVPlayerPlaybackResponseListener4 = this.mAVPlaybackResponseListener;
                if (iAVPlayerPlaybackResponseListener4 != null) {
                    iAVPlayerPlaybackResponseListener4.onPlayResponseReceived(item, contentInfo, ERROR.INVALID_ARGUMENT);
                    return;
                }
                return;
            }
            if (contentInfo != null) {
                DLog.d_api(TAG_CLASS, "play position - " + contentInfo.getStartingPosition());
            }
            playWebContent(item.getURI(), item, contentInfo, string);
            return;
        }
        if (string2.equals("MEDIA_SERVER")) {
            DLog.d_api(TAG_CLASS, "play MEDIA_SERVER - " + item.getTitle() + " to " + getName());
            if (item.getType().equals(Item.MediaType.ITEM_IMAGE)) {
                DLog.w_api(TAG_CLASS, "try to play image using avplayer");
                AVPlayer.IAVPlayerPlaybackResponseListener iAVPlayerPlaybackResponseListener5 = this.mAVPlaybackResponseListener;
                if (iAVPlayerPlaybackResponseListener5 != null) {
                    iAVPlayerPlaybackResponseListener5.onPlayResponseReceived(item, contentInfo, ERROR.INVALID_ARGUMENT);
                    return;
                }
                return;
            }
            if (contentInfo != null) {
                DLog.d_api(TAG_CLASS, "play position - " + contentInfo.getStartingPosition());
            }
            playMediaContent(item, contentInfo);
            return;
        }
        if (string2.equals("LOCAL_CONTENT")) {
            Uri uri = item.getURI();
            if (string.contains("image") || uri == null) {
                DLog.w_api(TAG_CLASS, "try to play invalid content");
                AVPlayer.IAVPlayerPlaybackResponseListener iAVPlayerPlaybackResponseListener6 = this.mAVPlaybackResponseListener;
                if (iAVPlayerPlaybackResponseListener6 != null) {
                    iAVPlayerPlaybackResponseListener6.onPlayResponseReceived(item, contentInfo, ERROR.INVALID_ARGUMENT);
                    return;
                }
                return;
            }
            String scheme = uri.getScheme();
            if (scheme.contains("file")) {
                String string3 = bundle.getString(AllShareKey.BUNDLE_STRING_FILEPATH);
                DLog.d_api(TAG_CLASS, "play LOCAL_CONTENT file - " + item.getTitle() + " to " + getName());
                StringBuilder sb2 = new StringBuilder("play filePath- ");
                sb2.append(string3);
                DLog.d_api(TAG_CLASS, sb2.toString());
                if (string3 == null) {
                    DLog.w_api(TAG_CLASS, "play LOCAL_CONTENT : uri == null");
                    this.mAVPlaybackResponseListener.onPlayResponseReceived(item, contentInfo, ERROR.INVALID_ARGUMENT);
                    return;
                } else {
                    if (contentInfo != null) {
                        DLog.d_api(TAG_CLASS, "play position - " + contentInfo.getStartingPosition());
                    }
                    playLocalContent(string3, item, contentInfo, string);
                }
            }
            if (scheme.contains(FirebaseAnalytics.Param.CONTENT)) {
                DLog.d_api(TAG_CLASS, "play LOCAL_CONTENT content - " + item.getTitle() + " to " + getName());
                StringBuilder sb3 = new StringBuilder("play uri- ");
                sb3.append(uri);
                DLog.d_api(TAG_CLASS, sb3.toString());
                if (contentInfo != null) {
                    DLog.d_api(TAG_CLASS, "play position - " + contentInfo.getStartingPosition());
                }
                playLocalContent(uri, item, contentInfo, string);
            }
        }
    }

    @Override
    public void prepare(Item item) {
        IAllShareConnector iAllShareConnector = this.mAllShareConnector;
        if (iAllShareConnector == null || !iAllShareConnector.isAllShareServiceConnected()) {
            DLog.w_api(TAG_CLASS, "prepare : SERVICE_NOT_CONNECTED");
            return;
        }
        if (item == 0) {
            DLog.w_api(TAG_CLASS, "prepare Fail :  Item does not exist ");
            return;
        }
        CVMessage cVMessage = new CVMessage();
        cVMessage.setActionID(AllShareAction.ACTION_AV_PLAYER_PREPARE);
        Bundle bundle = new Bundle();
        bundle.putString("BUNDLE_STRING_ID", getID());
        if (item instanceof IBundleHolder) {
            bundle.putParcelable(AllShareKey.BUNDLE_PARCELABLE_ITEM, ((IBundleHolder) item).getBundle());
        }
        cVMessage.setBundle(bundle);
        this.mAllShareConnector.requestCVMAsync(cVMessage, this.mAllShareRespHandler);
        DLog.d_api(TAG_CLASS, "prepare : " + item.getTitle() + " to " + getName());
        StringBuilder sb = new StringBuilder("prepare - uri : ");
        sb.append(item.getURI());
        DLog.d_api(TAG_CLASS, sb.toString());
    }

    @Override
    public void stop() {
        IAllShareConnector iAllShareConnector = this.mAllShareConnector;
        if (iAllShareConnector == null || !iAllShareConnector.isAllShareServiceConnected()) {
            DLog.w_api(TAG_CLASS, "stop fail : SERVICE_NOT_CONNECTED");
            this.mAVPlaybackResponseListener.onStopResponseReceived(ERROR.SERVICE_NOT_CONNECTED);
            return;
        }
        DLog.d_api(TAG_CLASS, "stop : " + getName());
        CVMessage cVMessage = new CVMessage();
        cVMessage.setActionID(AllShareAction.ACTION_AV_PLAYER_STOP);
        Bundle bundle = new Bundle();
        bundle.putString("BUNDLE_STRING_ID", getID());
        cVMessage.setBundle(bundle);
        this.mAllShareConnector.requestCVMAsync(cVMessage, this.mAllShareRespHandler);
    }

    @Override
    public void seek(long j) {
        IAllShareConnector iAllShareConnector = this.mAllShareConnector;
        if (iAllShareConnector == null || !iAllShareConnector.isAllShareServiceConnected()) {
            DLog.w_api(TAG_CLASS, "seek fail : SERVICE_NOT_CONNECTED");
            this.mAVPlaybackResponseListener.onSeekResponseReceived(j, ERROR.SERVICE_NOT_CONNECTED);
            return;
        }
        DLog.d_api(TAG_CLASS, "seek pos :" + j + " " + getName());
        CVMessage cVMessage = new CVMessage();
        cVMessage.setActionID(AllShareAction.ACTION_AV_PLAYER_SEEK);
        Bundle bundle = new Bundle();
        bundle.putString("BUNDLE_STRING_ID", getID());
        bundle.putLong(AllShareKey.BUNDLE_LONG_POSITION, j * 1000);
        cVMessage.setBundle(bundle);
        this.mAllShareConnector.requestCVMAsync(cVMessage, this.mAllShareRespHandler);
    }

    @Override
    public void pause() {
        IAllShareConnector iAllShareConnector = this.mAllShareConnector;
        if (iAllShareConnector == null || !iAllShareConnector.isAllShareServiceConnected()) {
            DLog.w_api(TAG_CLASS, "pause fail : SERVICE_NOT_CONNECTED");
            this.mAVPlaybackResponseListener.onPauseResponseReceived(ERROR.SERVICE_NOT_CONNECTED);
            return;
        }
        DLog.d_api(TAG_CLASS, "pause " + getName());
        CVMessage cVMessage = new CVMessage();
        cVMessage.setActionID(AllShareAction.ACTION_AV_PLAYER_PAUSE);
        Bundle bundle = new Bundle();
        bundle.putString("BUNDLE_STRING_ID", getID());
        cVMessage.setBundle(bundle);
        this.mAllShareConnector.requestCVMAsync(cVMessage, this.mAllShareRespHandler);
    }

    @Override
    public void resume() {
        IAllShareConnector iAllShareConnector = this.mAllShareConnector;
        if (iAllShareConnector == null || !iAllShareConnector.isAllShareServiceConnected()) {
            DLog.w_api(TAG_CLASS, "resume fail : SERVICE_NOT_CONNECTED");
            this.mAVPlaybackResponseListener.onResumeResponseReceived(ERROR.SERVICE_NOT_CONNECTED);
            return;
        }
        DLog.d_api(TAG_CLASS, "resume " + getName());
        CVMessage cVMessage = new CVMessage();
        cVMessage.setActionID(AllShareAction.ACTION_AV_PLAYER_RESUME);
        Bundle bundle = new Bundle();
        bundle.putString("BUNDLE_STRING_ID", getID());
        cVMessage.setBundle(bundle);
        this.mAllShareConnector.requestCVMAsync(cVMessage, this.mAllShareRespHandler);
    }

    @Override
    public void getVolume() {
        IAllShareConnector iAllShareConnector = this.mAllShareConnector;
        if (iAllShareConnector == null || !iAllShareConnector.isAllShareServiceConnected()) {
            this.mAVPlayerVolumeResponseListener.onGetVolumeResponseReceived(-1, ERROR.SERVICE_NOT_CONNECTED);
            return;
        }
        CVMessage cVMessage = new CVMessage();
        cVMessage.setActionID(AllShareAction.ACTION_AV_PLAYER_REQUEST_GET_VOLUME);
        Bundle bundle = new Bundle();
        bundle.putString("BUNDLE_STRING_ID", getID());
        cVMessage.setBundle(bundle);
        this.mAllShareConnector.requestCVMAsync(cVMessage, this.mAllShareRespHandler);
    }

    @Override
    public void setVolume(int i) {
        IAllShareConnector iAllShareConnector = this.mAllShareConnector;
        if (iAllShareConnector == null || !iAllShareConnector.isAllShareServiceConnected()) {
            DLog.w_api(TAG_CLASS, "setVolume fail : SERVICE_NOT_CONNECTED");
            this.mAVPlayerVolumeResponseListener.onSetVolumeResponseReceived(i, ERROR.SERVICE_NOT_CONNECTED);
            return;
        }
        if (i < 0 || i > 100) {
            DLog.w_api(TAG_CLASS, "setVolume fail : level (INVALID_ARGUMENT)");
            AVPlayer.IAVPlayerVolumeResponseListener iAVPlayerVolumeResponseListener = this.mAVPlayerVolumeResponseListener;
            if (iAVPlayerVolumeResponseListener != null) {
                iAVPlayerVolumeResponseListener.onSetVolumeResponseReceived(i, ERROR.INVALID_ARGUMENT);
                return;
            }
            return;
        }
        DLog.d_api(TAG_CLASS, "setVolume -level : " + i + " " + getName());
        CVMessage cVMessage = new CVMessage();
        cVMessage.setActionID(AllShareAction.ACTION_AV_PLAYER_REQUEST_SET_VOLUME);
        Bundle bundle = new Bundle();
        bundle.putString("BUNDLE_STRING_ID", getID());
        bundle.putInt(AllShareKey.BUNDLE_INT_VOLUME, i);
        cVMessage.setBundle(bundle);
        this.mAllShareConnector.requestCVMAsync(cVMessage, this.mAllShareRespHandler);
    }

    @Override
    public void getMute() {
        IAllShareConnector iAllShareConnector = this.mAllShareConnector;
        if (iAllShareConnector == null || !iAllShareConnector.isAllShareServiceConnected()) {
            this.mAVPlayerVolumeResponseListener.onSetMuteResponseReceived(false, ERROR.SERVICE_NOT_CONNECTED);
            return;
        }
        CVMessage cVMessage = new CVMessage();
        cVMessage.setActionID(AllShareAction.ACTION_AV_PLAYER_REQUEST_GET_MUTE);
        Bundle bundle = new Bundle();
        bundle.putString("BUNDLE_STRING_ID", getID());
        cVMessage.setBundle(bundle);
        this.mAllShareConnector.requestCVMAsync(cVMessage, this.mAllShareRespHandler);
    }

    @Override
    public void setMute(boolean z) {
        IAllShareConnector iAllShareConnector = this.mAllShareConnector;
        if (iAllShareConnector == null || !iAllShareConnector.isAllShareServiceConnected()) {
            DLog.w_api(TAG_CLASS, "setMute fail : SERVICE_NOT_CONNECTED");
            this.mAVPlayerVolumeResponseListener.onSetMuteResponseReceived(z, ERROR.SERVICE_NOT_CONNECTED);
            return;
        }
        DLog.d_api(TAG_CLASS, "setMute - " + z + " " + getName());
        CVMessage cVMessage = new CVMessage();
        cVMessage.setActionID(AllShareAction.ACTION_AV_PLAYER_REQUEST_SET_MUTE);
        Bundle bundle = new Bundle();
        bundle.putString("BUNDLE_STRING_ID", getID());
        bundle.putBoolean(AllShareKey.BUNDLE_BOOLEAN_MUTE, z);
        cVMessage.setBundle(bundle);
        this.mAllShareConnector.requestCVMAsync(cVMessage, this.mAllShareRespHandler);
    }

    @Override
    public void getPlayPosition() {
        IAllShareConnector iAllShareConnector = this.mAllShareConnector;
        if (iAllShareConnector == null || !iAllShareConnector.isAllShareServiceConnected()) {
            this.mAVPlaybackResponseListener.onGetPlayPositionResponseReceived(-1L, ERROR.SERVICE_NOT_CONNECTED);
            return;
        }
        CVMessage cVMessage = new CVMessage();
        cVMessage.setActionID(AllShareAction.ACTION_AV_PLAYER_REQUEST_PLAY_POSITION);
        Bundle bundle = new Bundle();
        bundle.putString("BUNDLE_STRING_ID", getID());
        cVMessage.setBundle(bundle);
        this.mAllShareConnector.requestCVMAsync(cVMessage, this.mAllShareRespHandler);
    }

    @Override
    public AVPlayer.AVPlayerState getPlayerState() {
        Bundle bundle;
        AVPlayer.AVPlayerState aVPlayerState = AVPlayer.AVPlayerState.UNKNOWN;
        IAllShareConnector iAllShareConnector = this.mAllShareConnector;
        if (iAllShareConnector == null || !iAllShareConnector.isAllShareServiceConnected()) {
            return aVPlayerState;
        }
        CVMessage cVMessage = new CVMessage();
        cVMessage.setActionID(AllShareAction.ACTION_AV_PLAYER_GET_PLAYER_STATE_SYNC);
        Bundle bundle2 = new Bundle();
        bundle2.putString("BUNDLE_STRING_ID", getID());
        cVMessage.setBundle(bundle2);
        CVMessage requestCVMSync = this.mAllShareConnector.requestCVMSync(cVMessage);
        if (requestCVMSync == null || (bundle = requestCVMSync.getBundle()) == null) {
            return aVPlayerState;
        }
        try {
            return AVPlayer.AVPlayerState.valueOf(bundle.getString(AllShareKey.BUNDLE_STRING_AV_PLAER_STATE));
        } catch (Exception e) {
            DLog.w_api(TAG_CLASS, "getPlayerState Exception", e);
            return aVPlayerState;
        }
    }

    @Override
    public void setResponseListener(AVPlayer.IAVPlayerPlaybackResponseListener iAVPlayerPlaybackResponseListener) {
        this.mAVPlaybackResponseListener = iAVPlayerPlaybackResponseListener;
    }

    @Override
    public void setResponseListener(AVPlayer.IAVPlayerVolumeResponseListener iAVPlayerVolumeResponseListener) {
        this.mAVPlayerVolumeResponseListener = iAVPlayerVolumeResponseListener;
    }

    @Override
    public void setEventListener(AVPlayer.IAVPlayerEventListener iAVPlayerEventListener) {
        IAllShareConnector iAllShareConnector = this.mAllShareConnector;
        if (iAllShareConnector == null || !iAllShareConnector.isAllShareServiceConnected()) {
            DLog.w_api(TAG_CLASS, "setEventListener error! AllShareService is not connected");
            return;
        }
        this.mAVPlayerEventListener = iAVPlayerEventListener;
        boolean z = this.mIsSubscribed;
        if (!z && iAVPlayerEventListener != null) {
            this.mAllShareConnector.subscribeAllShareEvent(AllShareEvent.EVENT_DEVICE_SUBSCRIBE, this.mDeviceImpl.getBundle(), this.mEventHandler);
            this.mIsSubscribed = true;
        } else if (z && iAVPlayerEventListener == null) {
            this.mAllShareConnector.unsubscribeAllShareEvent(AllShareEvent.EVENT_DEVICE_SUBSCRIBE, this.mDeviceImpl.getBundle(), this.mEventHandler);
            this.mIsSubscribed = false;
        }
    }

    @Override
    public String getModelName() {
        DeviceImpl deviceImpl = this.mDeviceImpl;
        if (deviceImpl == null) {
            return "";
        }
        return deviceImpl.getModelName();
    }

    @Override
    public Device.DeviceType getDeviceType() {
        DeviceImpl deviceImpl = this.mDeviceImpl;
        if (deviceImpl == null) {
            return Device.DeviceType.UNKNOWN;
        }
        return deviceImpl.getDeviceType();
    }

    @Override
    public String getIPAddress() {
        DeviceImpl deviceImpl = this.mDeviceImpl;
        if (deviceImpl == null) {
            return "";
        }
        return deviceImpl.getIPAddress();
    }

    @Override
    public String getName() {
        DeviceImpl deviceImpl = this.mDeviceImpl;
        if (deviceImpl == null) {
            return "";
        }
        return deviceImpl.getName();
    }

    @Override
    public Uri getIcon() {
        DeviceImpl deviceImpl = this.mDeviceImpl;
        if (deviceImpl == null) {
            return Uri.parse("");
        }
        return deviceImpl.getIcon();
    }

    @Override
    public ArrayList<Icon> getIconList() {
        DeviceImpl deviceImpl = this.mDeviceImpl;
        if (deviceImpl == null) {
            return new ArrayList<>();
        }
        return deviceImpl.getIconList();
    }

    @Override
    public String getID() {
        DeviceImpl deviceImpl = this.mDeviceImpl;
        if (deviceImpl == null) {
            return "";
        }
        return deviceImpl.getID();
    }

    @Override
    public Device.DeviceDomain getDeviceDomain() {
        DeviceImpl deviceImpl = this.mDeviceImpl;
        if (deviceImpl == null) {
            return Device.DeviceDomain.UNKNOWN;
        }
        return deviceImpl.getDeviceDomain();
    }

    @Override
    public Bundle getBundle() {
        DeviceImpl deviceImpl = this.mDeviceImpl;
        if (deviceImpl == null) {
            return new Bundle();
        }
        return deviceImpl.getBundle();
    }

    private Bundle extractBundle(Item item) {
        Bundle bundle = new Bundle();
        if (item instanceof IBundleHolder) {
            bundle.putParcelable(AllShareKey.BUNDLE_PARCELABLE_ITEM, ((IBundleHolder) item).getBundle());
        }
        return bundle;
    }

    private void playMediaContent(Item item, ContentInfo contentInfo) {
        playItem(item, contentInfo, AllShareAction.ACTION_AV_PLAYER_PLAY);
    }

    private void playLocalContent(Uri uri, Item item, ContentInfo contentInfo, String str) {
        playUri(uri, item, contentInfo, str, AllShareAction.ACTION_AV_PLAYER_PLAY_LOCAL_CONTENS_URI);
    }

    private void playLocalContent(String str, Item item, ContentInfo contentInfo, String str2) {
        playFilePath(str, item, contentInfo, str2, AllShareAction.ACTION_AV_PLAYER_PLAY_LOCAL_CONTENS_FILEPATH_WITH_METADATA);
    }

    private void playWebContent(Uri uri, Item item, ContentInfo contentInfo, String str) {
        ContentInfo contentInfo2;
        if (contentInfo != null) {
            ContentInfo.Builder builder = new ContentInfo.Builder();
            builder.setStartingPosition(contentInfo.getStartingPosition() * 1000);
            contentInfo2 = builder.build();
        } else {
            contentInfo2 = null;
        }
        playUri(uri, item, contentInfo2, str, AllShareAction.ACTION_AV_PLAYER_PLAY_URI);
    }

    private void playItem(Item item, ContentInfo contentInfo, String str) {
        IAllShareConnector iAllShareConnector = this.mAllShareConnector;
        if (iAllShareConnector == null || !iAllShareConnector.isAllShareServiceConnected()) {
            this.mAVPlaybackResponseListener.onPlayResponseReceived(item, contentInfo, ERROR.SERVICE_NOT_CONNECTED);
            return;
        }
        CVMessage cVMessage = new CVMessage();
        cVMessage.setActionID(str);
        Bundle extractBundle = extractBundle(item);
        extractBundle.putString("BUNDLE_STRING_ID", getID());
        extractBundle.putLong(AllShareKey.BUNDLE_LONG_CONTENT_INFO_STARTINGPOSITION, contentInfo != null ? contentInfo.getStartingPosition() : 0L);
        cVMessage.setBundle(extractBundle);
        this.mAllShareConnector.requestCVMAsync(cVMessage, this.mAllShareRespHandler);
    }

    private void playUri(Uri uri, Item item, ContentInfo contentInfo, String str, String str2) {
        IAllShareConnector iAllShareConnector = this.mAllShareConnector;
        if (iAllShareConnector == null || !iAllShareConnector.isAllShareServiceConnected()) {
            this.mAVPlaybackResponseListener.onPlayResponseReceived(item, contentInfo, ERROR.SERVICE_NOT_CONNECTED);
            return;
        }
        String title = item.getTitle();
        CVMessage cVMessage = new CVMessage();
        cVMessage.setActionID(str2);
        Bundle extractBundle = extractBundle(item);
        extractBundle.putString(AllShareKey.BUNDLE_STRING_TITLE, title);
        extractBundle.putString("BUNDLE_STRING_ID", getID());
        extractBundle.putParcelable(AllShareKey.BUNDLE_PARCELABLE_URI, uri);
        extractBundle.putLong(AllShareKey.BUNDLE_LONG_CONTENT_INFO_STARTINGPOSITION, contentInfo != null ? contentInfo.getStartingPosition() : 0L);
        cVMessage.setBundle(extractBundle);
        this.mAllShareConnector.requestCVMAsync(cVMessage, this.mAllShareRespHandler);
    }

    private void playFilePath(String str, Item item, ContentInfo contentInfo, String str2, String str3) {
        IAllShareConnector iAllShareConnector = this.mAllShareConnector;
        if (iAllShareConnector == null || !iAllShareConnector.isAllShareServiceConnected()) {
            this.mAVPlaybackResponseListener.onPlayResponseReceived(item, contentInfo, ERROR.SERVICE_NOT_CONNECTED);
            return;
        }
        String title = item.getTitle();
        CVMessage cVMessage = new CVMessage();
        cVMessage.setActionID(str3);
        Bundle extractBundle = extractBundle(item);
        extractBundle.putString(AllShareKey.BUNDLE_STRING_TITLE, title);
        extractBundle.putString("BUNDLE_STRING_ID", getID());
        extractBundle.putLong(AllShareKey.BUNDLE_LONG_CONTENT_INFO_STARTINGPOSITION, contentInfo != null ? contentInfo.getStartingPosition() : 0L);
        cVMessage.setBundle(extractBundle);
        this.mAllShareConnector.requestCVMAsync(cVMessage, this.mAllShareRespHandler);
    }

    @Override
    public void getMediaInfo() {
        IAllShareConnector iAllShareConnector = this.mAllShareConnector;
        if (iAllShareConnector == null || !iAllShareConnector.isAllShareServiceConnected()) {
            this.mAVPlaybackResponseListener.onGetMediaInfoResponseReceived(null, ERROR.SERVICE_NOT_CONNECTED);
            return;
        }
        CVMessage cVMessage = new CVMessage();
        cVMessage.setActionID(AllShareAction.ACTION_AV_PLAYER_REQUEST_GET_MEDIA_INFO);
        Bundle bundle = new Bundle();
        bundle.putString("BUNDLE_STRING_ID", getID());
        cVMessage.setBundle(bundle);
        this.mAllShareConnector.requestCVMAsync(cVMessage, this.mAllShareRespHandler);
    }

    @Override
    public boolean isSupportVideo() {
        Bundle bundle;
        IAllShareConnector iAllShareConnector = this.mAllShareConnector;
        if (iAllShareConnector == null || !iAllShareConnector.isAllShareServiceConnected()) {
            return false;
        }
        CVMessage cVMessage = new CVMessage();
        cVMessage.setActionID(AllShareAction.ACTION_AV_PLAYER_IS_SUPPORT_VIDEO_SYNC);
        Bundle bundle2 = new Bundle();
        bundle2.putString("BUNDLE_STRING_ID", getID());
        cVMessage.setBundle(bundle2);
        CVMessage requestCVMSync = this.mAllShareConnector.requestCVMSync(cVMessage);
        if (requestCVMSync == null || (bundle = requestCVMSync.getBundle()) == null) {
            return false;
        }
        try {
            return bundle.getBoolean(AllShareKey.BUNDLE_BOOLEAN_SUPPORT_VIDEO);
        } catch (Exception e) {
            DLog.w_api(TAG_CLASS, "isSupportVideo Exception", e);
            return false;
        }
    }

    @Override
    public boolean isSupportAudio() {
        Bundle bundle;
        IAllShareConnector iAllShareConnector = this.mAllShareConnector;
        if (iAllShareConnector == null || !iAllShareConnector.isAllShareServiceConnected()) {
            return false;
        }
        CVMessage cVMessage = new CVMessage();
        cVMessage.setActionID(AllShareAction.ACTION_AV_PLAYER_IS_SUPPORT_AUDIO_SYNC);
        Bundle bundle2 = new Bundle();
        bundle2.putString("BUNDLE_STRING_ID", getID());
        cVMessage.setBundle(bundle2);
        CVMessage requestCVMSync = this.mAllShareConnector.requestCVMSync(cVMessage);
        if (requestCVMSync == null || (bundle = requestCVMSync.getBundle()) == null) {
            return false;
        }
        try {
            return bundle.getBoolean(AllShareKey.BUNDLE_BOOLEAN_SUPPORT_AUDIO);
        } catch (Exception e) {
            DLog.w_api(TAG_CLASS, "isSupportAudio Exception", e);
            return false;
        }
    }

    @Override
    public boolean isSupportRedirect() {
        Bundle bundle;
        IAllShareConnector iAllShareConnector = this.mAllShareConnector;
        if (iAllShareConnector == null || !iAllShareConnector.isAllShareServiceConnected()) {
            return false;
        }
        CVMessage cVMessage = new CVMessage();
        cVMessage.setActionID(AllShareAction.ACTION_AV_PLAYER_IS_SUPPORT_REDIRECT_SYNC);
        Bundle bundle2 = new Bundle();
        bundle2.putString("BUNDLE_STRING_ID", getID());
        cVMessage.setBundle(bundle2);
        CVMessage requestCVMSync = this.mAllShareConnector.requestCVMSync(cVMessage);
        if (requestCVMSync == null || (bundle = requestCVMSync.getBundle()) == null) {
            return false;
        }
        String string = bundle.getString("BUNDLE_ENUM_ERROR");
        if (string != null && ERROR.NOT_SUPPORTED_FRAMEWORK_VERSION.toString().equals(string)) {
            DLog.w_api(TAG_CLASS, "isRedirectSupportable() Exception : NOT_SUPPORTED_FRAMEWORK_VERSION");
            return false;
        }
        try {
            return bundle.getBoolean(AllShareKey.BUNDLE_BOOLEAN_SUPPORT_REDIRECT);
        } catch (Exception e) {
            DLog.w_api(TAG_CLASS, "isRedirectSupportable Exception", e);
            return false;
        }
    }

    @Override
    public String getNIC() {
        DeviceImpl deviceImpl = this.mDeviceImpl;
        if (deviceImpl == null) {
            return "";
        }
        return deviceImpl.getNIC();
    }

    @Override
    public void getState() {
        IAllShareConnector iAllShareConnector = this.mAllShareConnector;
        if (iAllShareConnector == null || !iAllShareConnector.isAllShareServiceConnected()) {
            this.mAVPlaybackResponseListener.onGetStateResponseReceived(AVPlayer.AVPlayerState.UNKNOWN, ERROR.SERVICE_NOT_CONNECTED);
            return;
        }
        CVMessage cVMessage = new CVMessage();
        cVMessage.setActionID(AllShareAction.ACTION_AV_PLAYER_REQUEST_GET_PLAYER_STATE);
        Bundle bundle = new Bundle();
        bundle.putString("BUNDLE_STRING_ID", getID());
        cVMessage.setBundle(bundle);
        this.mAllShareConnector.requestCVMAsync(cVMessage, this.mAllShareRespHandler);
    }

    @Override
    public void removeEventHandler() {
        this.mAllShareConnector.unsubscribeAllShareEvent(AllShareEvent.EVENT_DEVICE_SUBSCRIBE, getBundle(), this.mEventHandler);
        this.mIsSubscribed = false;
    }

    @Override
    public boolean isSupportDynamicBuffering() {
        Bundle bundle;
        IAllShareConnector iAllShareConnector = this.mAllShareConnector;
        if (iAllShareConnector == null || !iAllShareConnector.isAllShareServiceConnected()) {
            return false;
        }
        CVMessage cVMessage = new CVMessage();
        cVMessage.setActionID(AllShareAction.ACTION_AV_PLAYER_IS_SUPPORT_DYNAMIC_BUFFERING);
        Bundle bundle2 = new Bundle();
        bundle2.putString("BUNDLE_STRING_ID", getID());
        cVMessage.setBundle(bundle2);
        CVMessage requestCVMSync = this.mAllShareConnector.requestCVMSync(cVMessage);
        if (requestCVMSync == null || (bundle = requestCVMSync.getBundle()) == null) {
            return false;
        }
        try {
            return bundle.getBoolean(AllShareKey.BUNDLE_BOOLEAN_SUPPORT_DYNAMIC_BUFFERING);
        } catch (Exception e) {
            DLog.w_api(TAG_CLASS, "isSupportDynamicBuffering Exception", e);
            return false;
        }
    }

    @Override
    public void skipDynamicBuffering() {
        IAllShareConnector iAllShareConnector = this.mAllShareConnector;
        if (iAllShareConnector == null || !iAllShareConnector.isAllShareServiceConnected()) {
            return;
        }
        CVMessage cVMessage = new CVMessage();
        cVMessage.setActionID(AllShareAction.ACTION_AV_PLAYER_SKIP_DYNAMIC_BUFFERING);
        Bundle bundle = new Bundle();
        bundle.putString("BUNDLE_STRING_ID", getID());
        cVMessage.setBundle(bundle);
        this.mAllShareConnector.requestCVMAsync(cVMessage, this.mAllShareRespHandler);
    }
}