mirror of
https://github.com/androidx/media.git
synced 2025-05-12 01:59:50 +08:00
Update surface directly from SphericalSurfaceView
The SurfaceListener just sets the surface on the VideoComponent, but SphericalSurfaceView already accesses the VideoComponent directly so it seems simpler to update the surface directly. PiperOrigin-RevId: 249242185
This commit is contained in:
parent
e4d66c4105
commit
1d0618ee1a
@ -35,7 +35,6 @@ import android.util.AttributeSet;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.Surface;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.TextureView;
|
||||
import android.view.View;
|
||||
@ -50,7 +49,6 @@ import com.google.android.exoplayer2.ExoPlaybackException;
|
||||
import com.google.android.exoplayer2.PlaybackPreparer;
|
||||
import com.google.android.exoplayer2.Player;
|
||||
import com.google.android.exoplayer2.Player.DiscontinuityReason;
|
||||
import com.google.android.exoplayer2.Player.VideoComponent;
|
||||
import com.google.android.exoplayer2.metadata.Metadata;
|
||||
import com.google.android.exoplayer2.metadata.id3.ApicFrame;
|
||||
import com.google.android.exoplayer2.source.TrackGroupArray;
|
||||
@ -405,7 +403,6 @@ public class PlayerView extends FrameLayout implements AdsLoader.AdViewProvider
|
||||
break;
|
||||
case SURFACE_TYPE_MONO360_VIEW:
|
||||
SphericalSurfaceView sphericalSurfaceView = new SphericalSurfaceView(context);
|
||||
sphericalSurfaceView.setSurfaceListener(componentListener);
|
||||
sphericalSurfaceView.setSingleTapListener(componentListener);
|
||||
surfaceView = sphericalSurfaceView;
|
||||
break;
|
||||
@ -1359,7 +1356,6 @@ public class PlayerView extends FrameLayout implements AdsLoader.AdViewProvider
|
||||
TextOutput,
|
||||
VideoListener,
|
||||
OnLayoutChangeListener,
|
||||
SphericalSurfaceView.SurfaceListener,
|
||||
SingleTapListener {
|
||||
|
||||
// TextOutput implementation
|
||||
@ -1449,18 +1445,6 @@ public class PlayerView extends FrameLayout implements AdsLoader.AdViewProvider
|
||||
applyTextureViewRotation((TextureView) view, textureViewRotation);
|
||||
}
|
||||
|
||||
// SphericalSurfaceView.SurfaceTextureListener implementation
|
||||
|
||||
@Override
|
||||
public void surfaceChanged(@Nullable Surface surface) {
|
||||
if (player != null) {
|
||||
VideoComponent videoComponent = player.getVideoComponent();
|
||||
if (videoComponent != null) {
|
||||
videoComponent.setVideoSurface(surface);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SingleTapListener implementation
|
||||
|
||||
@Override
|
||||
|
@ -53,20 +53,6 @@ import javax.microedition.khronos.opengles.GL10;
|
||||
*/
|
||||
public final class SphericalSurfaceView extends GLSurfaceView {
|
||||
|
||||
/**
|
||||
* This listener can be used to be notified when the {@link Surface} associated with this view is
|
||||
* changed.
|
||||
*/
|
||||
public interface SurfaceListener {
|
||||
/**
|
||||
* Invoked when the surface is changed or there isn't one anymore. Any previous surface
|
||||
* shouldn't be used after this call.
|
||||
*
|
||||
* @param surface The new surface or null if there isn't one anymore.
|
||||
*/
|
||||
void surfaceChanged(@Nullable Surface surface);
|
||||
}
|
||||
|
||||
// Arbitrary vertical field of view.
|
||||
private static final int FIELD_OF_VIEW_DEGREES = 90;
|
||||
private static final float Z_NEAR = .1f;
|
||||
@ -84,7 +70,6 @@ public final class SphericalSurfaceView extends GLSurfaceView {
|
||||
private final Handler mainHandler;
|
||||
private final TouchTracker touchTracker;
|
||||
private final SceneRenderer scene;
|
||||
private @Nullable SurfaceListener surfaceListener;
|
||||
private @Nullable SurfaceTexture surfaceTexture;
|
||||
private @Nullable Surface surface;
|
||||
private @Nullable Player.VideoComponent videoComponent;
|
||||
@ -156,15 +141,6 @@ public final class SphericalSurfaceView extends GLSurfaceView {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link SurfaceListener} used to listen to surface events.
|
||||
*
|
||||
* @param listener The listener for surface events.
|
||||
*/
|
||||
public void setSurfaceListener(@Nullable SurfaceListener listener) {
|
||||
surfaceListener = listener;
|
||||
}
|
||||
|
||||
/** Sets the {@link SingleTapListener} used to listen to single tap events on this view. */
|
||||
public void setSingleTapListener(@Nullable SingleTapListener listener) {
|
||||
touchTracker.setSingleTapListener(listener);
|
||||
@ -196,8 +172,8 @@ public final class SphericalSurfaceView extends GLSurfaceView {
|
||||
mainHandler.post(
|
||||
() -> {
|
||||
if (surface != null) {
|
||||
if (surfaceListener != null) {
|
||||
surfaceListener.surfaceChanged(null);
|
||||
if (videoComponent != null) {
|
||||
videoComponent.clearVideoSurface(surface);
|
||||
}
|
||||
releaseSurface(surfaceTexture, surface);
|
||||
surfaceTexture = null;
|
||||
@ -214,8 +190,8 @@ public final class SphericalSurfaceView extends GLSurfaceView {
|
||||
Surface oldSurface = this.surface;
|
||||
this.surfaceTexture = surfaceTexture;
|
||||
this.surface = new Surface(surfaceTexture);
|
||||
if (surfaceListener != null) {
|
||||
surfaceListener.surfaceChanged(surface);
|
||||
if (videoComponent != null) {
|
||||
videoComponent.setVideoSurface(surface);
|
||||
}
|
||||
releaseSurface(oldSurfaceTexture, oldSurface);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user