Fix media controller position on video view

Fix media controller position on video view



i have videoview in a popup page in my apps, the problem is media controllers position is not properly like below, i want the media controller located inside video view, how i can fix that?



enter image description here



here is my code for displaying video view and media controller, i allready set anchor view to video view but it doesn't work


@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_popup_preview);

DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
getWindow().setLayout((int) (width * .9d), (int) (height * .65d));

final LatestVideo vid = getIntent().getParcelableExtra("videolatest");
String url_video = vid.source_content;

nama.setText(vid.name);
judul.setText(vid.judul);
harga.setText("Rp." + vid.price);

mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);

Uri uri = Uri.parse(url_video);
videoView.setVideoURI(uri);
videoView.setMediaController(mediaController);

videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener()
@Override
public void onPrepared(MediaPlayer mediaPlayer)
videoView.start();

);
videoView.setOnErrorListener(new MediaPlayer.OnErrorListener()
@Override
public boolean onError(MediaPlayer mediaPlayer, int i, int i1)
return false;

);

loadRelatedLatestVideo();



and here is my layout xml for popup page :


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="0.8"
android:gravity="center_horizontal"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:orientation="vertical">
<FrameLayout
android:id="@+id/iv_video"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:background="@android:color/black">
<FrameLayout
android:id="@+id/frm_controller"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" />
<VideoView
android:id="@+id/vv_RelatedLatestpreview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/grey_e4e4e4"
android:elevation="2dp"
android:orientation="vertical"
android:paddingLeft="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/txtpopupnama"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nama Artis"
android:textSize="18sp" />
<TextView
android:id="@+id/txtpopupjudul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Judul Video"
android:textSize="16sp" />
<TextView
android:id="@+id/txtpopupharga"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="3dp"
android:text="Harga"
android:textColor="@android:color/holo_blue_dark"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Berlangganan"
android:textAllCaps="false"
android:textSize="18sp"
android:id="@+id/btnSubscribe"
android:layout_margin="5dp"
android:textColor="@color/white"
android:background="@drawable/selector_rounded_blue_logo" />






2 Answers
2



use mediaController.setAnchorView(videoView); inside setOnPreparedListener


mediaController.setAnchorView(videoView);


videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener()
@Override
public void onPrepared(MediaPlayer mediaPlayer)
mediaController.setAnchorView(videoView);
videoView.start();

);



try to replace parent(linearlayout) of video controller to relativelayout and set property android:layout_alignParentBottom="true" of child(videocontroler) is true in xml.



Required, but never shown



Required, but never shown






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế