How to create a youtube video "small screen and full-screen game in Android"

I want to develop an activity or fragment like Youtube.

"When a user clicks on a video from the list, he starts playing on a small video image, such as height = 200dp and width = 300dp (as an example), and I want to display a full-screen button on the MediaPlayer controller using a User who can play the same video full screen with video playback effect.

I also want to display a linked list of videos and comments on the currently playing video. So should I use fragments? IF yes what example example.

I am looking in google about this kind of video playback, but I can’t find it .. there is some answer how to use fill parent in height and width ... but I do not want to display the full screen directly.

I want to display the video in both small and full size. How can I do this? In the image you can see the full-screen button in the video controller, I want to do it.

Any help is appreciated

thanks enter image description here

+4
source share
2 answers

try to create a small surface of the video or video and you can change the presentation parameter by the display matrix

DisplayMetrics displaymetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); int height = displaymetrics.heightPixels; int width = displaymetrics.widthPixels; android.widget.FrameLayout.LayoutParams params = (android.widget.FrameLayout.LayoutParams) videoSurface.getLayoutParams(); params.width = width; params.height=height-80;// -80 for android controls params.setMargins(0, 0, 0, 50); 

So, to execute this code, you can create your own custom media controller or use the binding binding by expanding the media controller.

1) Here is the link to the user media controller User media controller

2) expand the media controller and set the tag binding set tag binding

  public void setAnchorView(final View view) { super.setAnchorView(view); Button fullScreen = new Button(context); fullScreen.setText("FullScreen"); Log.e("media controller","Set anchorView"); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params.setMargins(view.getWidth(), 0, 5, 20); params.gravity = Gravity.RIGHT; addView(fullScreen, params); fullScreen.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Log.e("media controller","full screen onclick"); Intent i = new Intent("xyxyxyxhx"); context.sendBroadcast(i); } }); } 
+4
source

You need to override setAnchorView in a new java class that extends Android MediaController (android.widget.MediaController) and adds an extra controller / controller. And do something like this

 @Override public void setAnchorView(View view) { super.setAnchorView(view); Button fullScreen = new Button(context); fullScreen.setText("FullScreen"); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params.gravity = Gravity.RIGHT|Gravity.TOP; addView(fullScreen, params); } 

now add clicklister to view

+2
source

Source: https://habr.com/ru/post/1501817/


All Articles