Android::VideoView inside a ScrollView - android

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 ;)

Related

recyclview Viewholder are create all together causing scroll lag

I need to create a screen which looks similar to Google play store screen, but need to add vertical recyclview also in between (Horizontal + vertical recycleview )
the problem is it causes a great lag when I scroll. the screen hangs for a second and gets resumed when all the view-holders are done creating!
Use Pagination with your list, load set of data. It will load your data quickly at start, and will occupy less memory.
Set a view pool to inner RecyclerView. So that scrolling does not lag.
<HorizontalScrollView
android:id="#+id/hsv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:fillViewport="true"
android:measureAllChildren="false"
android:scrollbars="none" >
<-- you child view xml code and set recyclerview scroll vertical-->
<HorizontalScrollView>
reduce the size or quality of images , i think your images in one of recycler view is too large , that's why recycler view getting lazy.

Android Media Controller stuck at a position when scrolled in list view?

I have a list of cards using Recycler View of android. I am showing some text and below it video view.
The list was scrolling well with playing video smoothly until I enabled controls using setMediaControll().
After enabling this video media controls when I scroll the list up/down the control stays in the same position even when the video view moves freely along with list view scroll movement.
These control should move along with list view they stay stationary. What may have caused this? Is this expected platform behaviour?
Update code :
Layout :
<FrameLayout
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_gravity="center_horizontal"
android:id="#+id/frame_layout_video_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<VideoView
android:id="#+id/video_view"
android:layout_width="360sp"
android:layout_height="225sp"
android:layout_gravity="center" />
<ImageView
android:id="#+id/image_button_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:contentDescription="play_pause_button"
app:srcCompat="#drawable/ic_play_circle_filled_white_24px" />
<ProgressBar
android:id="#+id/progressbar_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:visibility="gone" />
</FrameLayout>
In view holder :
MyViewHolder(View itemLayoutView) {
super(itemLayoutView);
..........
myVideoView = itemLayoutView.findViewById(R.id.video_view);
..........
}
Code to start video playing :
..........
Uri uri = Uri.parse(url);
holder.myVideoView.setVideoURI(uri);
MediaController fsm = new MediaController(mContext,finalistFragment , url, holder.myVideoView);
fsm.setAnchorView(holder.myVideoView);
holder.myVideoView.setMediaController(fsm);
..........
For the list, I am using RecyclerView.
this is indeed a known behavior with ListView and RecyclerView and is because these things only load the views that are visible to user and since user cannot reach the controls on scroll so they will freeze or maybe they stay in same place
my suggestion for you is to override setOnScrollListener for your RecyclerView, but for VideoView specifically I don't know how exactly.
I hope this helps
This is indeed an issue related to the RecyclerView behavior as suggested by Mr. pouya if you have set a scrollistner in recyler adapter then overide the method in you activity or fragment of the same srcollistenr with the recyler view method if this not works then Just add & wrap the videoView in a FrameLayout inside your cardview and refer the below link for further instruction
https://stackoverflow.com/a/24529711/9287163
Note: Please provide us with your card view layout XML file and code where you are setting the media controller to.

Android GLSurfaceView in ScrollView produces black borders

I have a GLSurfaceView that I want to put inside a ScrollView. I accomplished this by adding a FrameLayout inside a LinearLayout which was added to the ScrollView.
Everyhing works nice, except that I am getting a black border on top of the GLSurfaceView when scrolling. When the screen is still, everyhing looks nice. Anybody have any ideas.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="900dp"
android:orientation="horizontal"
android:layout_weight="1"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginTop="35dp"
android:visibility="visible"
android:weightSum="1"
android:overScrollMode="never">
<FrameLayout
android:id="#+id/ecg_graph"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Generally speaking, you don't want to move SurfaceView (or its subclasses) around the screen. Bear in mind that SurfaceView has two parts, the Surface and the View. The View part -- usually just a transparent "hole" used during layout -- is handled by the app. The Surface part is a separate graphics layer composited by the system, and its size and position are managed by the Window Manager.
When you move a SurfaceView, the View part moves immediately, but the Surface lags behind, because moving it requires communicating with other processes. You should expect to see a black bar in the direction that the View is moving, because you've temporarily exposed an area outside what the Surface covers.
The preferred way to handle this is to use a TextureView, which behaves just like other Views. You would need to do your own EGL setup and thread management, since GLSurfaceView won't be handling those for you. You can find some examples in Grafika.

Lag for multiple images in single scrollview

I am creating a activity for mix text and image input.
Here is the xml for container.
<ScrollView
android:id="#+id/new_question_body_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/new_question_tag_container"
android:layout_above="#+id/oler_keyboard_accessory"
android:layout_alignLeft="#+id/new_question_tag_container"
android:layout_alignRight="#+id/new_question_tag_container"
android:scrollbars="none">
<LinearLayout
android:id="#+id/new_question_body_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="#+id/new_question_body_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#null"
android:hint="Please edit your body here."
android:layout_marginBottom="5dp"/>
</LinearLayout>
</ScrollView>
After dynamically add three (not lag for two) imageViews, it become pretty lag when scrolling.
Even if I make maxHeight and Width for each individual 50dp, the lag still exist. Am I adding imageView in the wrong way or this is the memory limit?
Wouldn't be better to use a ListView with custom layout (for each row) instead of a mix of ScrollView and LinearLayout?
If you want to add tons of images (just like a gallery), you may think about using LRUCache or another algorithm (i.e. lazy loading).
Also, consider the image size you're tring to load into memory. Maybe a smaller size and 'click to zoom' of each item should be a better aproach/UX

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.

Categories

Resources