4

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

2 Answers2

4

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

    }
});
    }
Community
  • 1
  • 1
Swap-IOS-Android
  • 4,363
  • 6
  • 49
  • 77
  • i got small problem how can i manage comments and related videos on same page.. like youtube does any hint? –  Sep 13 '13 at 16:07
  • 3
    @NSArray you can use fragments to display comments and related videos or you can use relative layout and manage linear layout inside and you can provide weight to linear layout according to weight sum . to display comments you can use custom listview for simplicity use two listview in horizontal linearlayout and into one fetch comments from server and display and in another listview dislay videos... – Swap-IOS-Android Sep 13 '13 at 16:11
  • Here you are assuming anchorView to be LinearLayout..In other answer I see it's taken as Frame layout..Is it safe to assume it as LinearLayout here? – Android Developer Aug 24 '20 at 10:51
2

You have to override setAnchorView in your new java class which extend the Android's MediaController (android.widget.MediaController) and add an extra view/button to the 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

Shakeeb Ayaz
  • 6,200
  • 6
  • 45
  • 64