Fixed the video view crash in SupportLeanbackShowcase master build
The "Video consumption Examples" view in SupportLeanBackShowcase was failing on the master build (fugu-userdebug N AAC30 2573265 devkeys), since onCreate gets called in the reverse order of fragments' appearence in the code when using a single transaction. Fixed that by using separate transactions per fragment addition, and now the example video view works on the master build as well as the LMP-MR1 build. Bug: 26894030 Change-Id: Ic020cb87049af7e2095387ca1aab017f2b026630
This commit is contained in:
@@ -17,7 +17,6 @@ package android.support.v17.leanback.supportleanbackshowcase.app.media;
|
||||
import android.app.Fragment;
|
||||
import android.os.Bundle;
|
||||
import android.support.v17.leanback.app.PlaybackOverlayFragment;
|
||||
import android.support.v17.leanback.supportleanbackshowcase.app.MainFragment;
|
||||
import android.support.v17.leanback.widget.Action;
|
||||
import android.support.v17.leanback.widget.ArrayObjectAdapter;
|
||||
import android.support.v17.leanback.widget.OnItemViewClickedListener;
|
||||
@@ -34,6 +33,7 @@ public class VideoConsumptionExampleFragment extends PlaybackOverlayFragment imp
|
||||
OnItemViewClickedListener, MediaPlayerGlue.OnMediaFileFinishedPlayingListener {
|
||||
|
||||
private static final String URL = "http://techslides.com/demos/sample-videos/small.mp4";
|
||||
public static final String TAG = "VideoConsumptionExampleFragment";
|
||||
private ArrayObjectAdapter mRowsAdapter;
|
||||
private MediaPlayerGlue mGlue;
|
||||
|
||||
@@ -56,8 +56,10 @@ public class VideoConsumptionExampleFragment extends PlaybackOverlayFragment imp
|
||||
mGlue.setMetaData(metaData);
|
||||
mGlue.setMediaSource(URL);
|
||||
|
||||
|
||||
Fragment videoSurfaceFragment = getFragmentManager()
|
||||
.findFragmentByTag(VideoExampleActivity.VIDEO_SURFACE_FRAGMENT_TAG);
|
||||
.findFragmentByTag(VideoSurfaceFragment.TAG);
|
||||
|
||||
SurfaceView surface = (SurfaceView) videoSurfaceFragment.getView();
|
||||
surface.getHolder().addCallback(new SurfaceHolder.Callback() {
|
||||
@Override
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package android.support.v17.leanback.supportleanbackshowcase.app.media;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.os.Bundle;
|
||||
import android.support.v17.leanback.supportleanbackshowcase.R;
|
||||
|
||||
@@ -23,17 +24,20 @@ import android.support.v17.leanback.supportleanbackshowcase.R;
|
||||
*/
|
||||
public class VideoExampleActivity extends Activity {
|
||||
|
||||
public static final String VIDEO_SURFACE_FRAGMENT_TAG = "VIDEO_SURFACE";
|
||||
public static final String TAG = "VideoExampleActivity";
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_video_example);
|
||||
|
||||
FragmentTransaction ft1 = getFragmentManager().beginTransaction();
|
||||
ft1.replace(R.id.videoFragment, new VideoSurfaceFragment(), VideoSurfaceFragment.TAG);
|
||||
ft1.commit();
|
||||
|
||||
getFragmentManager().beginTransaction()
|
||||
.replace(R.id.videoFragment, new VideoSurfaceFragment(), VIDEO_SURFACE_FRAGMENT_TAG)
|
||||
.add(R.id.videoFragment, new VideoConsumptionExampleFragment())
|
||||
.commit();
|
||||
FragmentTransaction ft2 = getFragmentManager().beginTransaction();
|
||||
ft2.add(R.id.videoFragment, new VideoConsumptionExampleFragment(), VideoConsumptionExampleFragment.TAG);
|
||||
ft2.commit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import android.app.Fragment;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v17.leanback.supportleanbackshowcase.R;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -25,9 +26,10 @@ import android.view.ViewGroup;
|
||||
|
||||
public class VideoSurfaceFragment extends Fragment {
|
||||
|
||||
private static final String TAG = "VideoSurfaceFragment";
|
||||
public static final String TAG = "VideoSurfaceFragment";
|
||||
|
||||
@Override public void onCreate(Bundle savedInstanceState) {
|
||||
Log.d(TAG, "onCreate started");
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
}
|
||||
|
||||
@@ -16,12 +16,7 @@
|
||||
-->
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/videoFragment">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/videoFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
</RelativeLayout>
|
||||
</RelativeLayout>
|
||||
Reference in New Issue
Block a user