private void showVideoView() { playerStatus.setVisibility(View.INVISIBLE); player.setVisibility(View.VISIBLE); playerHwStatus.setVisibility(View.VISIBLE); SurfaceHolder sfhTrackHolder = player.getSurfaceView().getHolder(); sfhTrackHolder.setFormat(PixelFormat.TRANSPARENT); setTitle(""); }
@Override protected void onStop() { Log.e("SDL", "onStop()"); super.onStop(); if (player != null) player.onStop(); if (toastShot != null) toastShot.cancel(); }
@Override public void onBackPressed() { if (toastShot != null) toastShot.cancel(); player.Close(); if (!playing) { super.onBackPressed(); return; } setUIDisconnected(); }
protected void onPause() { Log.e("SDL", "onPause()"); super.onPause(); editor = settings.edit(); editor.putString("connectionUrl", edtIpAddress.getText().toString()); editor.putStringSet("connectionHistory", edtIpAddressHistory); editor.commit(); if (player != null) player.onPause(); }
@Override protected void onDestroy() { Log.e("SDL", "onDestroy()"); if (toastShot != null) toastShot.cancel(); if (player != null) player.onDestroy(); stopProgressTask(); System.gc(); if (multicastLock != null) { multicastLock.release(); multicastLock = null; } super.onDestroy(); }
private void showStatusView() { player.setVisibility(View.INVISIBLE); playerHwStatus.setVisibility(View.INVISIBLE); // player.setAlpha(0.0f); playerStatus.setVisibility(View.VISIBLE); }
@Override public void onLowMemory() { Log.e("SDL", "onLowMemory()"); super.onLowMemory(); if (player != null) player.onLowMemory(); }
@Override public void onWindowFocusChanged(boolean hasFocus) { Log.e("SDL", "onWindowFocusChanged(): " + hasFocus); super.onWindowFocusChanged(hasFocus); if (player != null) player.onWindowFocusChanged(hasFocus); }
@Override protected void onStart() { Log.e("SDL", "onStart()"); super.onStart(); if (player != null) player.onStart(); }
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 onCreate(Bundle savedInstanceState) { String strUrl; setTitle(R.string.app_name); super.onCreate(savedInstanceState); WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); multicastLock = wifi.createMulticastLock("multicastLock"); multicastLock.setReferenceCounted(true); multicastLock.acquire(); getWindow().requestFeature(Window.FEATURE_PROGRESS); getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON); setContentView(R.layout.main); mthis = this; settings = PreferenceManager.getDefaultSharedPreferences(MainActivity.this); SharedSettings.getInstance(this).loadPrefSettings(); SharedSettings.getInstance().savePrefSettings(); playerStatus = (RelativeLayout) findViewById(R.id.playerStatus); playerStatusText = (TextView) findViewById(R.id.playerStatusText); playerHwStatus = (TextView) findViewById(R.id.playerHwStatus); player = (MediaPlayer) findViewById(R.id.playerView); strUrl = settings.getString("connectionUrl", "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov"); player.getSurfaceView().setZOrderOnTop(true); // necessary SurfaceHolder sfhTrackHolder = player.getSurfaceView().getHolder(); sfhTrackHolder.setFormat(PixelFormat.TRANSPARENT); HashSet<String> tempHistory = new HashSet<String>(); tempHistory.add("rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov"); tempHistory.add("http://hls.cn.ru/streaming/2x2tv/tvrec/playlist.m3u8"); tempHistory.add("rtsp://rtmp.infomaniak.ch/livecast/latele"); player.setOnTouchListener( new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { switch (motionEvent.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { if (player.getState() == PlayerState.Paused) player.Play(); else if (player.getState() == PlayerState.Started) player.Pause(); } } return true; } }); edtIpAddressHistory = settings.getStringSet("connectionHistory", tempHistory); this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); edtIpAddress = (AutoCompleteTextView) findViewById(R.id.edit_ipaddress); edtIpAddress.setText(strUrl); edtIpAddress.setOnEditorActionListener( new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) { InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); in.hideSoftInputFromWindow( edtIpAddress.getApplicationWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); return true; } return false; } }); btnHistory = (Button) findViewById(R.id.button_history); // Array of choices btnHistory.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); in.hideSoftInputFromWindow( MainActivity.edtIpAddress.getApplicationWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); if (edtIpAddressHistory.size() <= 0) return; String urlHistory[] = { "rtsp://russiatoday.fms.visionip.tv/rt/Russia_al_yaum_1000k_1/1000k_1", "rtsp://www.tvarm.ru:1935/live/myStream1.sdp", "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov", "rtsp://live240.impek.com/brtvhd", "http://tv.life.ru/lifetv/480p/index.m3u8" }; MainActivity.edtIpAddressAdapter = new ArrayAdapter<String>( MainActivity.this, R.layout.history_item, new ArrayList<String>(edtIpAddressHistory)); MainActivity.edtIpAddress.setAdapter(MainActivity.edtIpAddressAdapter); MainActivity.edtIpAddress.showDropDown(); } }); btnShot = (Button) findViewById(R.id.button_shot); // Array of choices btnShot.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { if (player != null) { Log.e("SDL", "getVideoShot()"); SharedSettings sett = SharedSettings.getInstance(); if (sett.decoderType != 0) { Toast.makeText( getApplicationContext(), "For Software Decoder Only!", Toast.LENGTH_SHORT) .show(); return; } // VideoShot frame = player.getVideoShot(200, 200); VideoShot frame = player.getVideoShot(-1, -1); if (frame == null) return; // get your custom_toast.xml ayout LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate( R.layout.videoshot_view, (ViewGroup) findViewById(R.id.videoshot_toast_layout_id)); ImageView image = (ImageView) layout.findViewById(R.id.videoshot_image); image.setImageBitmap( getFrameAsBitmap(frame.getData(), frame.getWidth(), frame.getHeight())); // Toast... if (toastShot != null) toastShot.cancel(); toastShot = new Toast(getApplicationContext()); toastShot.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toastShot.setDuration(Toast.LENGTH_SHORT); toastShot.setView(layout); toastShot.show(); } } }); btnConnect = (Button) findViewById(R.id.button_connect); btnConnect.setOnClickListener(this); btnRecord = (Button) findViewById(R.id.button_record); btnRecord.setOnClickListener( new OnClickListener() { @Override public void onClick(View arg0) { is_record = !is_record; if (is_record) { // start recording if (player != null) { int record_flags = PlayerRecordFlags.forType(PlayerRecordFlags.PP_RECORD_AUTO_START) | PlayerRecordFlags.forType( PlayerRecordFlags.PP_RECORD_SPLIT_BY_TIME); // 1 - auto start int rec_split_time = 30; player.RecordSetup(getRecordPath(), record_flags, rec_split_time, 0, ""); player.RecordStart(); } } else { // stop recording if (player != null) { player.RecordStop(); } } ImageView ivLed = (ImageView) findViewById(R.id.led); if (ivLed != null) ivLed.setImageResource((is_record ? R.drawable.led_red : R.drawable.led_green)); btnRecord.setText(is_record ? "Stop Record" : "Start Record"); } }); RelativeLayout layout = (RelativeLayout) findViewById(R.id.main_view); layout.setOnTouchListener( new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (getWindow() != null && getWindow().getCurrentFocus() != null && getWindow().getCurrentFocus().getWindowToken() != null) inputManager.hideSoftInputFromWindow( getWindow().getCurrentFocus().getWindowToken(), 0); return true; } }); playerStatusText.setText("DEMO VERSION"); setShowControls(); }
@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; } }