0

This is my xml .

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
    android:id="@+id/firstLayout"
    android:layout_weight="1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/secondView"
    android:orientation="vertical">

    <FrameLayout
        android:id="@+id/videoFrame"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <org.videolan.libvlc.util.VLCVideoLayout
            android:id="@+id/videoLayout"
            android:fitsSystemWindows="false"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </FrameLayout>

</LinearLayout>



<LinearLayout
    android:id="@+id/thirdLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/secondView"
    android:layout_weight="1"
    android:background="@android:color/holo_orange_light"
    android:orientation="vertical">


</LinearLayout>

This is my class :

public class WifiActivity extends AppCompatActivity {
    private BroadcastReceiver MyReceiver = null;

    private static final String url = " rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4";

    private LibVLC libVlc;
    private MediaPlayer mediaPlayer;
    private VLCVideoLayout videoLayout;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video);
        if (getSupportActionBar() != null) {
            getSupportActionBar().hide();
        }

        libVlc = new LibVLC(this);
        mediaPlayer = new MediaPlayer(libVlc);
        videoLayout = findViewById(R.id.videoLayout);

    }

    @Override
    protected void onStart() {
        super.onStart();
        mediaPlayer.attachViews(videoLayout, null, false, false);

        Media media = new Media(libVlc, Uri.parse(url));
        media.setHWDecoderEnabled(true, false);
        media.addOption(":network-caching=600");

        mediaPlayer.setMedia(media);
        media.release();
        mediaPlayer.play();

    }
}

after running this code I am able to show live streaming using the given URL look like this.

enter image description here

I am trying to remove the black bar which is showing in the given image I want to keep it full screen please help me how to achieve this I am unable to find any solution for this.

enter image description here

MARSH
  • 117
  • 1
  • 7
  • 22
  • you want to make these bars invisible or you want to "stretch"/center video for fitting whole screen? – snachmsm Sep 01 '22 at 06:11
  • Thanks for the answer @snachmsm yes I want to remove or invisible the top black bar so that i can fit video screen in full video I tried but unable to do – MARSH Sep 01 '22 at 06:35
  • @snachmsm I have change live video URl you use to see video i want to remove black bar top and bottom from video view – MARSH Sep 01 '22 at 06:54

1 Answers1

1

you are setting layout_height="match_parent" for VLCVideoLayout, so currently it behaves properly, according to written code

if you want different height for this view, then you should calculate it and set for VLCVideoLayout. here is fun fact: this class will re-set its width and height at runtime (check out onAttachedToWindow method), so even when you set some fixed values in XML - these will be overwritten. its made for "some reason" by library authors, so let's don't touch this class, but now we know that VLCVideoLayout will always stretch/fit to parent

so now I would create some parent class for this video view only

<LinearLayout
    android:id="@+id/firstLayout"
    android:layout_weight="1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/secondView"
    android:orientation="vertical">

        <FrameLayout
            android:id="@+id/videoFrame"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <org.videolan.libvlc.util.VLCVideoLayout
                android:id="@+id/videoLayout"
                android:fitsSystemWindows="false"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
            
        </FrameLayout>

</LinearLayout>

now as we know that frame/video will match_parent width then we can measure it by measuring screen. if this video would be packed into some more complicated layout, e.g. some small video frame in corner - you should measure size of this area (which oftenly have fixed width/size in such case)

knowing videoFrame width you can calculate easily height with just multiplying by ratio of video

int scrWidth = getScreenWidth();
FrameLayout frameLayout = findViewById(R.id.videoFrame);
double ratio = 16d/9d;  // 16:9
frameLayout.getLayoutParams().height = (int)(scrWidth / ratio);
snachmsm
  • 17,866
  • 3
  • 32
  • 74
  • OK Thanks let me try with this – MARSH Sep 01 '22 at 07:24
  • It worked but one small thing I need help with after applying your logic my screen is coming something like this which i updated screen in question i want keep it half screen in my device same logic i have applied as you suggest . – MARSH Sep 01 '22 at 07:33
  • sadly I don't understand what do you want to achieve now... thats new question related to splitting screen to half. XML posted in question is wrong, there's no root in it... please ask new question with updated code (full) and maybe some image with desired look. if you want you may post link in here for me, if I would have time I will try to answer – snachmsm Sep 01 '22 at 09:33
  • Thanks for helping me I am trying to increase the height of the video frame but when I trying to increase when the again black bar comes I want to fit it whatever area I will give for the video frame – MARSH Sep 01 '22 at 13:38