mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
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
1 changed files with 15 additions and 1 deletions
|
|
@ -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…
Reference in a new issue