3

I have a viewpager with 2 fragments, each with their own video views. I have used this SO answer to successfully scale landscape video to fit full screen portrait mode in a cropCenter-type way, and it did that successfully, showing the center part of the video only, while scaling up the height. Since the resizing sets the videoView's width to wider than the frame, scrolling to the next page will indeed play the 2nd video, but it is covered by the first video view.

Setting each of the views to GONE is not an option, since it creates a black screen between the swipes until the other video is set back to VISIBLE.

How can I properly crop the views? Other posts offered third-party libraries, but the libs are either not updated or don't contain the methods I need from the video view.

galaxigirl
  • 2,390
  • 2
  • 20
  • 29
  • 1
    I will be very surprised if `VideoView` works well in a `ViewPager`. `VideoView` is based on `SurfaceView`, which cannot be animated (at least on some Android versions -- I think they fixed that limitation somewhere along the line). You could try switching to `MediaPlayer` and a `TextureView`. – CommonsWare Oct 24 '17 at 13:17
  • I'm a bit confused when you say animation - is this referring to the page swipe? Also, I see the problem with the container, which in this case is the videoView, since it doesn't respect my match_parent attributes. But I suppose the righthand border of the view is extended as soon as the page is being swiped. You think MediaPlayer and TextureView would prevent that? – galaxigirl Oct 24 '17 at 13:26
  • "is this referring to the page swipe?" -- yes. "You think MediaPlayer and TextureView would prevent that?" -- I have no idea. I have not tried having a page in a `ViewPager` extend beyond the screen. My point is that I would be surprised if `VideoView` animated properly during the swipe itself, at least on Android 6.0(?) and older. – CommonsWare Oct 24 '17 at 13:30
  • thanks for your comments. But to be clear I am NOT trying to have the page extend beyond the screen. I'm trying to achieve the oppposite - 2 pages each with it's own video. The bug is the first video extending it's 'match_parent'ness, completely covering the second video (but I can still hear the 2nd one playing) – galaxigirl Oct 24 '17 at 13:34
  • "But to be clear I am NOT trying to have the page extend beyond the screen" -- ummm... "Since the resizing sets the videoView's width to wider than the frame" suggests otherwise. If you get rid of the crop-center logic, and have the video completely fit within the page, does the problem go away? – CommonsWare Oct 24 '17 at 13:35
  • If the device is in landscape, then video 1 does not overlap video 2. If I do resize, video 1 peaks out and covers about an inch over video 2. But in portrait, if I don't resize, the landscape video will only take up 1/4-1/3 of the screen. Forget the 'crop-center' bit - bad wording on my part. It simply resizes the video proportionally. Just wish there was someway to crop the excess width on the fly – galaxigirl Oct 24 '17 at 13:53
  • I don't know that there's a way to do that cleanly with pages in a `ViewPager`, sorry. I have never tried that, and what little experience I have in the area (camera previews, not in a pager) doesn't fill me with confidence. – CommonsWare Oct 24 '17 at 14:01
  • great! with that answer I can just tell the designer (with confidence) - not possible! :) – galaxigirl Oct 24 '17 at 14:15

0 Answers0