toro
toro copied to clipboard
SimpleExoPlayerView Height Wrap_Content + RESIZE_MODE_FIXED_WIDTH
Hi @eneim ,
I'm trying to automatically resize my SimpleExoPlayerView view according to its width. So that's my layout:
<RelativeLayout
android:id="@+id/item_feed_square"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/maxplore_spacing_title_content_horizontal">
<com.google.android.exoplayer2.ui.AspectRatioFrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:resize_mode="fixed_width">
<com.google.android.exoplayer2.ui.SimpleExoPlayerView
android:id="@+id/item_feed_video"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:resize_mode="fixed_width"
android:layout_gravity="center"/>
</com.google.android.exoplayer2.ui.AspectRatioFrameLayout>
<ImageView
android:id="@+id/item_feed_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:scaleType="centerInside"/>
<ImageView
android:id="@+id/item_feed_image_video_placeholder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:background="@drawable/maxplore_ic_play_o"/>
</RelativeLayout>`
and that's the code I initialise the playerview:
imageContent.setVisibility(View.GONE);
simpleExoPlayerView.setVisibility(View.VISIBLE);
simpleExoPlayerView.setUseController(false);
simpleExoPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIXED_WIDTH);
//simpleExoPlayerView.setZOrderOnTop(true);
imageVideoPlaceholder.setVisibility(View.VISIBLE);
videoUri = Uri.parse(item.getMedia().getUrl());`
It doesn't seem to be working though. If I set a fixed height for the SimpleExoPlayerView it works fine but the video will be uploaded by the user so I don't have a specific size I can set for all videos. Am I missing something ?
@jonathansds I made a comment else where. But to make it clear, a surface need an init height. If you own your server, please specify all available Video ratio, and then make a specific ViewHolder for each ratio (using ViewType). That is the best way I can think of. If you don't own your Video but you can get the video width, height from API request, you can dynamically setup your width/height before loading the Video into Player I suppose.
@eneim according to the solved issue 1827 ( https://github.com/google/ExoPlayer/issues/1827#issuecomment-251790658 ) I should be able to use:
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:resize_mode="fixed_width"
@jonathansds I see, let me take a look and try the suggested way by ExoPlayer.
@jonathansds Still finding time to try this, but looking at your layout xml, I think you don't need to have another AspectRatioFrameLayout to wrap your SimpleExoPlayerView, because internally SimpleExoPlayerView use an AspectRatioFrameLayout to hold its content.
@eneim I just include the AspectRatioFrameLayout as a try to make it works but originally I didn't have it, just the SimpleExoPlayerView itself.
@jonathansds I see. Sorry I had no time this weekend, will look into this as soon as possible.
@jonathansds So what I have now is: using SimpleExoPlayerView as a single View, NOT in a RecyclerView -->it will behave as expected (resize_mode works and so on), but RecyclerView somehow prevent it from correctly resize the Content. I will need to read how the LayoutManager force the measurement internally first to help you, but at least we know there is something we don't know yet ...
@eneim if any update on this issue, please let us know
I still have this same issue, the Exoplayer in a RecyclerView isn't displayed, either with match_parent or wrap_content, the only solution is to give it a fixed height in dp. I have been stumped by this for days now, and I don't have another solution.