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.
Related
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);
I have a poster image on a video that is shifted down about 40 pixels leaving whitespace above it. When the video plays it moves up and plays in its correct location. Also, the control bar centers vertically on the video instead of aligning at the bottom of the video.
This video is being rendered in an Android WebView. Works fine on all other browsers without the fantom margin or odd control placement.
I'm wondering if any of my css could be throwing it off (When I check the computed values in Safari Web Inspector both padding and margin are 0)
Above the video poster image can be seen with the fantom margin. The poster image should be flush with the hairline divider.
I believe the above issue is related, the video controls are centered vertically on the video when they should sit at the bottom. You can see that the video has shifted up in that margin.
Eventually the controls fade away and the video plays as it should.
Is there any way to apply css directly to a video poster? I'm guessing the poster is displaying awkwardly because it is a different size than the video. I'm wondering what CSS I'd need to handle this.
My CSS foo is not that great. I'm more a native developer.
This was a problem with my CSS. Eventually I had to wrap everything in a div an put height and width to 100%
I'm implementing a video player with ads. Eventually, playback is paused and some ads are shown, after the ads playback is resumed.
To implement this I've done a FrameLayout with a VideoView and another View to display the ads.
When the ads break is reached I do:
videoView.pause();
videoView.setVisibility(View.GONE);
adsView.setVisibility(View.VISIBLE):
//Play ads for X time
adsView.setVisibility(View.GONE);
videoView.setVisibility(View.VISIBLE);
videoView.play();
It's fairly simple and it works fine in all devices I tried except the Nexus 7.
On the Nexus 7 when playback is resumed the video gets smaller and it doesn't fill the whole screen. It only uses aprox 1/4 of the screen.
After a lot of hours investigating I realised this only happens when I change the visibility of the VideoView. If I comment the following line //videoView.setVisibility(View.GONE); the problem disappears but I can't see the ads.
Some logs that may be relevant:
NvOsDebugPrintf BeginSequence 640x368
NvOsDebugPrintf pnvsi->nDecodeBuffers = 9
NvOsDebugPrintf Display Resolution : (640x360)
NvOsDebugPrintf Display Aspect Ratio : (128x360)
Display aspect ratio (128x360) should be the same as the display resolution (640x360) but it isn't.
Any idea?
Thanks
Not sure of the cause but there seems to be measuring error (I think there are other reports of some measuring issues on n7). View.GONE causes the views to be relaid out to account of the space that is now free from the disappearing view.
As a work around, you can avoid being relaid out -- try placing both views inside a RelativeLayout and have them completely overlap by setting fill_parent on width and height to both. Then you can use setVisibility(View.INVISIBLE) which does not cause the widgets to resize.
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.