Search code examples
androidandroid-layoutmedia-playerandroid-video-player

How to create videoview like youtube "small screen and full screen play in android "


I want to develop activity or fragment like Youtube.

"When user click on video from list it start playing in small video view like height =200dp and width = 300dp(as example) and i want to display full screen button on MediaPlayer controller by using User can play same video in full screen with effecting video play.

Also i want to display related videoList and comments on current playing video So should i use fragments?? IF yes any sample example.

I search on google about such kind of video play but i don't find it.. there are some answer like use fill parent in height and width ... but i don't want to display full screen directly.

I want to display video in both size small and full screen. How can i do that In image you can see fullscreen button in video controller i want to do that.

Any help is appreciated

Thank youenter image description here


Solution

  • try to create small video surface or video view and can change the parameter of view by 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 you can use set anchor by extending media controller.

    1) Here is Custom media controller link Custom media controller

    2)extending media controller and set anchor tag set anchor tag

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