Set SurfaceView lifecycle to follow attachment in PlayerView
This avoids destroying the surface if PlayerView is hidden in the view hierarchy. PiperOrigin-RevId: 568501459
This commit is contained in:
parent
212f1f8ea8
commit
69ffac28bb
@ -49,6 +49,7 @@ import android.widget.FrameLayout;
|
|||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.annotation.ColorInt;
|
import androidx.annotation.ColorInt;
|
||||||
|
import androidx.annotation.DoNotInline;
|
||||||
import androidx.annotation.IntDef;
|
import androidx.annotation.IntDef;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
@ -427,7 +428,11 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
surfaceView = new SurfaceView(context);
|
SurfaceView view = new SurfaceView(context);
|
||||||
|
if (Util.SDK_INT >= 34) {
|
||||||
|
Api34.setSurfaceLifecycleToFollowsAttachment(view);
|
||||||
|
}
|
||||||
|
surfaceView = view;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
surfaceView.setLayoutParams(params);
|
surfaceView.setLayoutParams(params);
|
||||||
@ -1737,4 +1742,13 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresApi(34)
|
||||||
|
private static class Api34 {
|
||||||
|
|
||||||
|
@DoNotInline
|
||||||
|
public static void setSurfaceLifecycleToFollowsAttachment(SurfaceView surfaceView) {
|
||||||
|
surfaceView.setSurfaceLifecycle(SurfaceView.SURFACE_LIFECYCLE_FOLLOWS_ATTACHMENT);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user