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 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(); }