Closed jacobusp closed 4 years ago
Ater some digging I've solved it with some help from this issue: https://github.com/mrmaffen/vlc-android-sdk/issues/104 The solution is to set aspect ratio and window size:
mediaPlayer.setAspectRatio(videoView.getWidth() + ":" + videoView.getHeight());
vOut.setWindowSize(videoView.getWidth(), videoView.getHeight());
VideoView videoView = findViewById(R.id.videoView);
ArrayList<String> options = new ArrayList<>();
LibVLC libVlc = new LibVLC(this, options);
MediaPlayer mediaPlayer = new MediaPlayer(libVlc);
final IVLCVout vOut = mediaPlayer.getVLCVout();
vOut.setVideoView(videoView); //videoView is a pre-defined view which is part of the layout
mediaPlayer.setAspectRatio(videoView.getWidth() + ":" + videoView.getHeight());
vOut.setWindowSize(videoView.getWidth(), videoView.getHeight());
vOut.addCallback(this);
vOut.attachViews();
mediaPlayer.setEventListener(this);
Media videoMedia = new Media(libVlc, Uri.parse("myRtspUrl"));
mediaPlayer.setMedia(videoMedia);
mediaPlayer.play();
You can't get the width and height of the VideoView
in an Activity.onCreate()
method (they will be 0 then). I made it work by running this code in an Handler.postdelayed()
, so the width and height are known by then.
How to stretch an RTSP stream in a
VideoView
? To be more specific, I've configured an IP camera (Foscam FI9800P) to stream at 640x480, but I want it to stretch over the entireVideoView
in my app.Currently my activity code is like this:
The layout is a constraint layout containing the
VideoView
:The![Stretch RTSP stream in VideoView](https://user-images.githubusercontent.com/26598539/86225329-5ee26e00-bb8a-11ea-96f1-a05ac9245e8b.png)
layout_width
andlayout_height
of 0dp stretches theVideoView
over the screen (black area), but the streamed content within theVideoView
does not get stretched:I am not sure if this question should be posted here or somewhere else. Please point me in the right direction if you can.