@Override public void onBackPressed() { if (toastShot != null) toastShot.cancel(); player.Close(); if (!playing) { super.onBackPressed(); return; } setUIDisconnected(); }
public void onClick(View v) { SharedSettings.getInstance().loadPrefSettings(); if (player != null) { if (!edtIpAddressHistory.contains(player.getConfig().getConnectionUrl())) edtIpAddressHistory.add(player.getConfig().getConnectionUrl()); player.getConfig().setConnectionUrl(edtIpAddress.getText().toString()); if (player.getConfig().getConnectionUrl().isEmpty()) return; if (toastShot != null) toastShot.cancel(); player.Close(); if (playing) { setUIDisconnected(); } else { SharedSettings sett = SharedSettings.getInstance(); boolean bPort = (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT); int aspect = bPort ? 1 : sett.rendererEnableAspectRatio; MediaPlayerConfig conf = new MediaPlayerConfig(); player.setVisibility(View.INVISIBLE); conf.setConnectionUrl(player.getConfig().getConnectionUrl()); conf.setConnectionNetworkProtocol(sett.connectionProtocol); conf.setConnectionDetectionTime(sett.connectionDetectionTime); conf.setConnectionBufferingTime(sett.connectionBufferingTime); conf.setDecodingType(sett.decoderType); conf.setRendererType(sett.rendererType); conf.setSynchroEnable(sett.synchroEnable); conf.setSynchroNeedDropVideoFrames(sett.synchroNeedDropVideoFrames); conf.setEnableColorVideo(sett.rendererEnableColorVideo); conf.setEnableAspectRatio(aspect); conf.setDataReceiveTimeout(30000); conf.setNumberOfCPUCores(0); // record config if (is_record) { int record_flags = PlayerRecordFlags.forType( PlayerRecordFlags.PP_RECORD_AUTO_START); // 1 - auto start conf.setRecordPath(getRecordPath()); conf.setRecordFlags(record_flags); conf.setRecordSplitTime(0); conf.setRecordSplitSize(0); } else { conf.setRecordPath(""); conf.setRecordFlags(0); conf.setRecordSplitTime(0); conf.setRecordSplitSize(0); } Log.v(TAG, "conf record=" + is_record); // Open Player player.Open(conf, mthis); btnConnect.setText("Disconnect"); playing = true; } } }
@Override public void handleMessage(Message msg) { PlayerNotifyCodes status = (PlayerNotifyCodes) msg.obj; switch (status) { case CP_CONNECT_STARTING: if (reconnect_type == PlayerConnectType.Reconnecting) strText = "Reconnecting"; else strText = "Connecting"; startProgressTask(strText); player_state = PlayerStates.Busy; showStatusView(); reconnect_type = PlayerConnectType.Normal; setHideControls(); break; case VRP_NEED_SURFACE: player_state = PlayerStates.Busy; showVideoView(); break; case PLP_PLAY_SUCCESSFUL: player_state = PlayerStates.ReadyForUse; stopProgressTask(); playerStatusText.setText(""); setTitle(R.string.app_name); break; case PLP_CLOSE_STARTING: player_state = PlayerStates.Busy; stopProgressTask(); playerStatusText.setText("Disconnected"); showStatusView(); setUIDisconnected(); break; case PLP_CLOSE_SUCCESSFUL: player_state = PlayerStates.ReadyForUse; stopProgressTask(); playerStatusText.setText("Disconnected"); showStatusView(); System.gc(); setShowControls(); setUIDisconnected(); break; case PLP_CLOSE_FAILED: player_state = PlayerStates.ReadyForUse; stopProgressTask(); playerStatusText.setText("Disconnected"); showStatusView(); setShowControls(); setUIDisconnected(); break; case CP_CONNECT_FAILED: player_state = PlayerStates.ReadyForUse; stopProgressTask(); playerStatusText.setText("Disconnected"); showStatusView(); setShowControls(); setUIDisconnected(); break; case PLP_BUILD_FAILED: player_state = PlayerStates.ReadyForUse; stopProgressTask(); playerStatusText.setText("Disconnected"); showStatusView(); setShowControls(); setUIDisconnected(); break; case PLP_PLAY_FAILED: player_state = PlayerStates.ReadyForUse; stopProgressTask(); playerStatusText.setText("Disconnected"); showStatusView(); setShowControls(); setUIDisconnected(); break; case PLP_ERROR: player_state = PlayerStates.ReadyForUse; stopProgressTask(); playerStatusText.setText("Disconnected"); showStatusView(); setShowControls(); setUIDisconnected(); break; case CP_INTERRUPTED: player_state = PlayerStates.ReadyForUse; stopProgressTask(); playerStatusText.setText("Disconnected"); showStatusView(); setShowControls(); setUIDisconnected(); break; case CP_RECORD_STARTED: Log.v(TAG, "=handleMessage CP_RECORD_STARTED"); { String sFile = player.RecordGetFileName(1); Toast.makeText( getApplicationContext(), "Record Started. File " + sFile, Toast.LENGTH_LONG) .show(); } break; case CP_RECORD_STOPPED: Log.v(TAG, "=handleMessage CP_RECORD_STOPPED"); { String sFile = player.RecordGetFileName(0); Toast.makeText( getApplicationContext(), "Record Stopped. File " + sFile, Toast.LENGTH_LONG) .show(); } break; // case CONTENT_PROVIDER_ERROR_DISCONNECTED: case CP_STOPPED: case VDP_STOPPED: case VRP_STOPPED: case ADP_STOPPED: case ARP_STOPPED: if (player_state != PlayerStates.Busy) { stopProgressTask(); player_state = PlayerStates.Busy; if (toastShot != null) toastShot.cancel(); player.Close(); playerStatusText.setText("Disconnected"); showStatusView(); player_state = PlayerStates.ReadyForUse; setShowControls(); setUIDisconnected(); } break; case CP_ERROR_DISCONNECTED: if (player_state != PlayerStates.Busy) { player_state = PlayerStates.Busy; if (toastShot != null) toastShot.cancel(); player.Close(); playerStatusText.setText("Disconnected"); showStatusView(); player_state = PlayerStates.ReadyForUse; setUIDisconnected(); Toast.makeText(getApplicationContext(), "Demo Version!", Toast.LENGTH_SHORT).show(); } break; default: player_state = PlayerStates.Busy; } }