Android VideoView resizing won't resize video - android

I have a VideoView which resizes on keyboard events. I observed that the video (played by VideoView) will not resize even though the VideoView's layout is changed (the changes are clearly visible). Is there any call I need to make to resize the video to the new layout?
I have tried 'invalidate()' and 'requestLayout()', but they did not work.

I managed to re-actualize my VideoView size by doing this after changing it's owner Layout:
mVideoView.getHolder().setSizeFromLayout();

You need to create a custom VideoView since it require to invoke these 2 methods :
onMeasure() and onConfigurationChanged()
this Answer has explained in very deep detail, please check below:
Android VideoView orientation change with buffered video

Use FrameLayout as parent of videoView
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<VideoView
android:id="#+id/myVideo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" />
</FrameLayout>

Related

Black box in screen after pressing Android menu button

I am creating a library class in Android Studio for my internship. I have created a custom RelativeLayout that inflates the layout shown below.
I can't find this issue anywhere, so I hope someone is able to help me out.
I have a layout file that looks like this:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/videoFrame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:background="#color/wallet_holo_blue_light">
<VideoView
android:id="#+id/videoBackground"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#null"/>
</FrameLayout>
</RelativeLayout>
I do need the FrameLayout, to be able to scale the VideoView where the VideoView's width is bigger then the parent this Layout is inflated into. I resize this VideoView dynamically on runtime-level, but that all works fine.
When I start the activity with this VideoView, everything is fine.
Whenever I hit the Android "Windows"-button and return to the Activity, a black box appears.
Screenshots
It also happens in Portrait mode. Then the black box is even bigger than half the screen.
After changing screenOrientation, so rotating my tablet, for example, the black box is gone again.
I really have no clue, does anyone know what the problem might be?

Webview scrolling on Android not working properly

In the webview.xml, I only have a frame layout as a wrapper for the webView as the following,
<FrameLayout
android:id="#+id/scroll_wrapper"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="#+id/web_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
As a little background of the webview, it's basically a mobile web page that displays pictures, and allows for horizontal scrolling(either swiping or clicking the 'next' button). Right now, I'm able to scroll to the next photo via swiping, but once I release my finger, the photo pops back to the original photo. Same thing is happening for clicking next, the screen displays half of the next photo before scrolling back to the previous photo.
I have absolutely no idea why this is happening as I've tried all options with playing with the horizontal scrolling attributes, but it still isn't working. Could anyone who has experienced this provide some insights. Please feel free to let me know what additional info you need.
try using linear layout rather than using frame layout as you have only one child that is webview for the parent layout.
this one works for me :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<WebView
android:id="#+id/webview_content"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>

VideoView flickering issue

I'm facing weird issue of flickering using VideoView. When activity starts, it causes minor flicker of fraction for a second. Then, video starts. It shows 2 black lines on the top and the bottom of the video. See the snap-shot below.
I have tested my application on 2 devices
1) Samsung n-8000(Tablet)
2) Lenovo a-800
video.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:gravity="center">
<VideoView
android:id="#+id/vvSplash"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#00ffffff">
</VideoView>
</LinearLayout>
Activity code:
private VideoView vd;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.video);
vd = (VideoView) findViewById(R.id.vvSplash);
playVideo();
}
private void playVideo() {
Uri uri = Uri.parse("android.resource://" + getPackageName() +"/"+ R.raw.intro);
vd.setVideoURI(uri);
vd.setMediaController(null);
vd.start();
}
Any help would be appreciated. Thank you.
As ridiculous as it sounds, but the answer is here:
VideoView inside fragment causes black screen flicking
SurfaceView flashes black on load
I repeat the solution, kudos to those who found out:
<SurfaceView
android:layout_width="0px"
android:layout_height="0px"
android:visibility="gone" />
It is VERY IMPORTANT that you add the surface view to the root view in your activity, not the immediate parent. Otherwise it won't work.
i also faced same problem but solved it by changing layout parameter of videoview from wrap content to match parent . Also you need to remove the background property of video view from XML. I hope it will work for you
For people in the future: This ugly bug seems to have been resolved in Marshmallow. At my work, we are developing with Xamarin (so, basically, all views are added in programmatically). We have a bunch of test devices, and I was mainly working with a Marshmallow device, so I never noticed this black flicker when building the page I was working on. After finally testing with a Lollipop device, I noticed this flicker.
Unfortunately I do not have a solution. We need our application to be as cross-platform as possible, so using a layout xml is discouraged /sadface.
If your issue is VideoView flickering when the back button is pressed, just set your VideoView visibility to INVISIBLE or GONE in the onBackPressed() method of your Activity before calling the super implementation.
If the user can also leave through the "up" button, intercept android.R.home option item to hide the VideoView.
Here's an example in Kotlin:
override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) {
android.R.id.home -> super.onOptionsItemSelected(item).also {
video_view.visibility = GONE // Hide videoView before leaving to avoid flickering
}
R.id.action_share -> consume { shareVideo() } // Your regular menu options
else -> super.onOptionsItemSelected(item)
}
override fun onBackPressed() {
video_view.visibility = GONE // Hide videoView before leaving to avoid flickering
super.onBackPressed()
}
Just remove the following line from your xml.
android:background="#00ffffff"
It will help you :)
For anyone who's still facing the problem and don't get how to use the above answer.
It simply just copies this code and paste it in the main activity layout that you're using the videoview in under the main (first) layout.
<SurfaceView
android:layout_width="0px"
android:layout_height="0px"
android:visibility="gone" />
in my case
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/Mainframlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/facebookbgcolor" >
<SurfaceView
android:layout_width="0px"
android:layout_height="0px"
android:visibility="gone" />
.....rest of the layout
Adapted the xml-based solution from https://stackoverflow.com/a/27307286/38557 to use Java code instead. Put this in the Fragment's onCreateView(), before inflating the layout:
// Add a SurfaceView to prevent flickering when the video is loaded later.
SurfaceView surfaceView = new SurfaceView(getActivity());
surfaceView.setVisibility(View.GONE);
container.addView(surfaceView, new ViewGroup.LayoutParams(0, 0));
It does the same thing, and can be used when you can't or don't want to change the XMLs.

How to create header and footer image in my media player?

I wish to create header and footer image in my media player. Now the media player is working fine for me.
If I click media player its display video thumbnails in center of the screen(layout).
If I click that thumbnails the video will play.
My doubt is how to create header and footer images from video thumbnails showing page.
Give me your suggestion please, I am new with android applications.
Element description;
a. Header image, a stretched background image. The location of this external image comes
from the application xml.
b. Footer image, a stretched background image. The location of this external image comes
from the application xml.
xml source:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Gallery xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/videoGrdVw"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</FrameLayout>
I think you should use LinearLayout for header and footer inside RelativeLayout. Set both LinearLayot's orientation to Horizontal. You can also use DroidDraw. I use it sometime whenever i stuck with android layouts.
My suggestion to you is to use RelativeLayout when laying down elements on your application page. Good starting point for this layout is in this page. Also, this layout allows you to do exactly what you want, using ALIGN_PARENT_TOP and ALIGN_PARENT_BOTTOM attributes for your images. One more advantage of this layout is that it will easily adjust to any screen size. On the other side, only disadvantage of this layout is that it can be sometimes tricky to fully understand it's behavior.

Android::VideoView inside a ScrollView

I have a VideoView that is inside a scrollView. When I scroll the scrollView, the VideoView does not scroll with it. It is like its position is fixed. How can I scroll the VideoView correctly with the scrolling of all other elements in the scrollView?
The display is usually divided into two pipelines
Frame buffer pipeline - This is is where all your graphics is displayed. All the UI display elements go into this pipline
Video buffer pipeline - This is where your video data is diverted to.
Now when you declare a surface view you take up some screen space in the UI saying this is where the video will be displayed. So all other UI elements will not be able to occupy that space.
When scrolling happens your surface view will indeed be moved up or down depending on the scroll event but the problem is the video buffer pipeline does not care what happens in the frame buffer pipeline it goes on filling up the video data into the space in which it was initialised with.
So as of now you cannot scroll the video in android..
Romain Guy said in this Android issue:
This is a known limitation of VideoView. You should instead use
TextureView in Android 4.0 and up.
You can put the videoview inside of a layout with an empty View over it.
<RelativeLayout
android:id="#+id/lay_live_video"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="visible" >
<VideoView
android:id="#+id/videoview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent" />
</RelativeLayout>
This code can be inside of your scrollview.
Sorry for my English, I'm learning ;)

Categories

Resources