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:
Keyvan Amiri
2016-02-01 12:02:24 -08:00
parent 4e89da7764
commit 32be3d30dc
4 changed files with 18 additions and 15 deletions

View File

@@ -17,7 +17,6 @@ package android.support.v17.leanback.supportleanbackshowcase.app.media;
import android.app.Fragment; import android.app.Fragment;
import android.os.Bundle; import android.os.Bundle;
import android.support.v17.leanback.app.PlaybackOverlayFragment; 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.Action;
import android.support.v17.leanback.widget.ArrayObjectAdapter; import android.support.v17.leanback.widget.ArrayObjectAdapter;
import android.support.v17.leanback.widget.OnItemViewClickedListener; import android.support.v17.leanback.widget.OnItemViewClickedListener;
@@ -34,6 +33,7 @@ public class VideoConsumptionExampleFragment extends PlaybackOverlayFragment imp
OnItemViewClickedListener, MediaPlayerGlue.OnMediaFileFinishedPlayingListener { OnItemViewClickedListener, MediaPlayerGlue.OnMediaFileFinishedPlayingListener {
private static final String URL = "http://techslides.com/demos/sample-videos/small.mp4"; private static final String URL = "http://techslides.com/demos/sample-videos/small.mp4";
public static final String TAG = "VideoConsumptionExampleFragment";
private ArrayObjectAdapter mRowsAdapter; private ArrayObjectAdapter mRowsAdapter;
private MediaPlayerGlue mGlue; private MediaPlayerGlue mGlue;
@@ -56,8 +56,10 @@ public class VideoConsumptionExampleFragment extends PlaybackOverlayFragment imp
mGlue.setMetaData(metaData); mGlue.setMetaData(metaData);
mGlue.setMediaSource(URL); mGlue.setMediaSource(URL);
Fragment videoSurfaceFragment = getFragmentManager() Fragment videoSurfaceFragment = getFragmentManager()
.findFragmentByTag(VideoExampleActivity.VIDEO_SURFACE_FRAGMENT_TAG); .findFragmentByTag(VideoSurfaceFragment.TAG);
SurfaceView surface = (SurfaceView) videoSurfaceFragment.getView(); SurfaceView surface = (SurfaceView) videoSurfaceFragment.getView();
surface.getHolder().addCallback(new SurfaceHolder.Callback() { surface.getHolder().addCallback(new SurfaceHolder.Callback() {
@Override @Override

View File

@@ -15,6 +15,7 @@
package android.support.v17.leanback.supportleanbackshowcase.app.media; package android.support.v17.leanback.supportleanbackshowcase.app.media;
import android.app.Activity; import android.app.Activity;
import android.app.FragmentTransaction;
import android.os.Bundle; import android.os.Bundle;
import android.support.v17.leanback.supportleanbackshowcase.R; import android.support.v17.leanback.supportleanbackshowcase.R;
@@ -23,17 +24,20 @@ import android.support.v17.leanback.supportleanbackshowcase.R;
*/ */
public class VideoExampleActivity extends Activity { public class VideoExampleActivity extends Activity {
public static final String VIDEO_SURFACE_FRAGMENT_TAG = "VIDEO_SURFACE"; public static final String TAG = "VideoExampleActivity";
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_example); setContentView(R.layout.activity_video_example);
FragmentTransaction ft1 = getFragmentManager().beginTransaction();
ft1.replace(R.id.videoFragment, new VideoSurfaceFragment(), VideoSurfaceFragment.TAG);
ft1.commit();
getFragmentManager().beginTransaction() FragmentTransaction ft2 = getFragmentManager().beginTransaction();
.replace(R.id.videoFragment, new VideoSurfaceFragment(), VIDEO_SURFACE_FRAGMENT_TAG) ft2.add(R.id.videoFragment, new VideoConsumptionExampleFragment(), VideoConsumptionExampleFragment.TAG);
.add(R.id.videoFragment, new VideoConsumptionExampleFragment()) ft2.commit();
.commit();
} }
} }

View File

@@ -18,6 +18,7 @@ import android.app.Fragment;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v17.leanback.supportleanbackshowcase.R; import android.support.v17.leanback.supportleanbackshowcase.R;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@@ -25,9 +26,10 @@ import android.view.ViewGroup;
public class VideoSurfaceFragment extends Fragment { public class VideoSurfaceFragment extends Fragment {
private static final String TAG = "VideoSurfaceFragment"; public static final String TAG = "VideoSurfaceFragment";
@Override public void onCreate(Bundle savedInstanceState) { @Override public void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "onCreate started");
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
} }

View File

@@ -16,12 +16,7 @@
--> -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" 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> </RelativeLayout>