I have a problem with VideoView and ViewPager swiping action. While swiping I can see black lines on the right or left side of VideoView (depends on side of swiping) . How can I deal with this.
It was done using FragmentStatePagerAdapter and ViewPager. Parent Activity has SurfaceView with 0px width and height and set
getWindow( ).setFormat( PixelFormat.TRANSLUCENT );
I'm adding VideoView from JAVA code.
VideoView is based of Surfaceview which is not very ideal for translation and other behaviours. and much more suited to full screen video players that are static in layout. What you are looking for is textureview based videoview. Try searching library on github.
you could try setting the background of the videoview to transparent.
videoView.setBackgroundResource(android.R.color.transparent);
Related
I'm playing a Full HD video inside a VideoView, but my screen size is just 1216px x 684px.
The VideoView is cropping the video, but I want it scaled down. I found one "bug" that makes what I want, but surely it's not the best way. If I set 1px margin around the VideoView, it scales correctly.
The VideoView is inside a RelativeLayout, I tried to set centerInParent, "alignParentLeft, Right, Top and Bottom" but none of this works.
Is there another way to make VideoView correctly scale the source?
Another issue:
When I pause my VideoView, it goes dark, instead of freezing the image. Is there a way I could achieve this behavior?
Thanks in advance for every reply.
everyone. I have a project where I need to display a video within a VideoView in portrait orientation, but I've been running into a weird issue for the last couple weeks. Also note, this issue only occurs the first time the VideoView is loaded with data.
This is a very stripped version of the layout:
<RelativeLayout>
<RelativeLayout>
<VideoView /> <-- W:fill_parent, H:wrap_content
</RelativeLayout>
</RelativeLayout>
Now for the actual issue: when the VideoView is first loaded with data, both its height/width fill the entire screen (minus the padding space) for less than a second (up to 3 seconds, depending on whether it's local or streaming), then it magically adjusts itself to the intended size.
Since it takes longer for videos not stored locally, I feel as if the issue has to do with the VideoView taking time to load the video, and not adjusting its boundaries correctly immediately, which is why it expands to fill the screen, then suddenly drops down to the appropriate size.
Now, I believe the reason it doesn't do that every time is because it's still using the same instance of the VideoView each time it's loaded (since it's using a ViewFlipper and not setContentView, it's not creating a new instance of it).
However, I'm loading the data into the VideoView in the same way, and I don't understand why the issue doesn't persist, which makes me think my assumption of why it's doing that is wrong.
Now for what I've tried:
I started with a width of fill_parent and height of wrap_content for both the RelativeLayout and the VideoView, which is where I noticed this problem initially. Also note: the graphic layout in Eclipse shows the same issue with these settings that I'm trying to solve: the VideoView is expanded to fill the screen, minus the padding it has).
I've tried forcing the layout to a specific pixel dimension in the XML layout (terrible, I know), and then defining new LayoutParams for the views and setting them after the video has been properly loaded.
I've tried creating a new VideoView dynamically and adding it to the layout after it's been loaded; still no luck.
And now I'm out of ideas... Anyone else have some?
And thanks in advance for your help~
EDIT:
As a workaround in the meantime, I created an onPreparedListener() for the VideoView, and keep the view hidden until the onPreparedListener is fired off. That seems to solve the problem, but I'm more curious as to why the VideoView was doing what it's doing, not necessarily just how to fix it.
Thanks again~
I am currently working on a simple video player on Android OS 2.3.3 where I am using a VideoView to display a movie and using the MediaController to control the video.
I want to add a few chapter markers along the seekbar and was wondering if anyone has any ideas on how to go about doing this?
Just use horizontal SeekBar instead of MediaController.
Put it in RelativeLayout and behind SeekBar set some views which will be chapter markers. This markers will be visible if they will be little bit bigger than SeekBar height. You can add this View's programmatically when needed by calculating their positions depend on video duration and seekbar length.
Of course layout can be little bit more complicated.
I have an image and a video player. In portrait, it shows both. Doing landscape left, just the video shows. Doing landscape right just the image shows.
I am using the setVisibility() method right now to achieve that. The problem with doing:
myVideoView.setVisibility(View.INVISIBLE);
causes the video to stop playing. Is there a way to keep it playing but also not visible to the user? Maybe like set the opacity of the VideoView to 0?
I think I found a solution here. In order to make videoview invisible and keep it playing sound you simply hide it by setting alpha value.
mVideoView.setAlpha(0f);
Hope it works for you!
You could try changing the z-order of the views with the bringToFront() method.
If you want the video to show then call mVideoView.bringToFront() and when you want the image to show you could use mImageView.bringToFront() this should work as long as the video and the image both occupy the same space on the screen.
Good luck
I am trying to play a videoview on top of another video view. The first video view is paused, while the second is playing. It appears to work but no second video appears on the screen (though I hear the audio and see the controls that would normally appear on top). I am assuming this is some sort of order issue. Any thoughts. By the way, I have no problem displaying other views on top of the main video view and having the video fill the background.
That won't work - the VideoView is special in the sense that it 'punches' a hole in the normal Views to allow direct access to the display pixels (or, in android terms, the 'Surface' - VideoView is a subclass of SurfaceView). You cannot layer two SurfaceViews on top of eachother - the first one that grabs the pixels (the Surface) will 'own' it. (see SurfaceHolder.Callback.surfaceCreated() / surfaceDestroyed())
Other Views on top of a SurfaceView do work, because the framework will compose the display bits of normal Views on top of the Surface. It cannot do that with another VideoView (i.e. a SurfaceView) because there is nothing to compose.
<VideoView android:id="#+id/videoView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<VideoView android:id="#+id/videoView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
when videoView2 starts playing setvisibilty of videoView1 invisible.
then you can make it visible when you need.
Use Thread to control both video
I don't know if this is helpful at the moment, but I managed to get something similar to what you want...
I needed to nest a VideoView on top of a SurfaceView; as long as they don't overlap 100% it can work. (what i mean is, my surfaceview is the whole screen and videoview is just a small portion of the screen)
The thing is - since you can't compose SurfaceViews, the first one to grab the pixels is the one that will be shown. Intuitiveness will drive you to Z-order your prioritized view AFTER the less-important one in the XML - but as I've said previously, the first one to grab the pixels stays, so make sure you define the smaller view FIRST, and then overlay it with the bigger one.
This will result in such behaviour that the smaller (in my case preview view) acquires the said X * Y pixels, and then the 'background' surfaceview (which is supposed to be on top of it according to the XML) takes up the rest and ignores the smaller surface.
I'm not too sure about handling events from those two though as I only have to play streams in those two views and not react to any kind of clicks/events generated by those two components, but it might be expected that if you followed this route - the bigger view will intercept all clicks made in the smaller view area (because it's on top according to the XML) so maybe you have to programatically move it on top as well upon creation.
Hope it helps.
EDIT:
Although... it like it just works once. It's a work in progress really. Upon returning from any activity, there's nothing i can do to prevent the bigger view claiming everything :/
you can add videoview a on top videoview b,like this,
parentview.removeview(a);
parentview.removviewe(b);
parentview.addview(a);
parentview.addview(b);
parentview.invalidate();
Ti's work for me. I hope it can helps.