From 05a79a417a8ef5e1f38092531494cfc0d074f9c9 Mon Sep 17 00:00:00 2001 From: olly Date: Tue, 27 Nov 2018 13:58:44 +0000 Subject: [PATCH] Fall back to TYPE_ROTATION_VECTOR if TYPE_GAME_ROTATION_VECTOR unavailable Issue: #5119 PiperOrigin-RevId: 222978448 --- RELEASENOTES.md | 3 +++ .../ui/spherical/SphericalSurfaceView.java | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index af974df8aa5..7e2c57b0373 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -11,6 +11,9 @@ ([#4883](https://github.com/google/ExoPlayer/issues/4883)). * DASH: Fix detecting the end of live events ([#4780](https://github.com/google/ExoPlayer/issues/4780)). +* Spherical video: Fall back to `TYPE_ROTATION_VECTOR` if + `TYPE_GAME_ROTATION_VECTOR` is unavailable + ([#5119](https://github.com/google/ExoPlayer/issues/5119)). * Support seeking for a wider range of MPEG-TS streams ([#5097](https://github.com/google/ExoPlayer/issues/5097)). * Support for playing spherical videos on Daydream. diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/spherical/SphericalSurfaceView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/spherical/SphericalSurfaceView.java index 8665852de77..36589c5e34b 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/spherical/SphericalSurfaceView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/spherical/SphericalSurfaceView.java @@ -102,12 +102,18 @@ public SphericalSurfaceView(Context context, @Nullable AttributeSet attributeSet // Configure sensors and touch. sensorManager = (SensorManager) Assertions.checkNotNull(context.getSystemService(Context.SENSOR_SERVICE)); - // TYPE_GAME_ROTATION_VECTOR is the easiest sensor since it handles all the complex math for - // fusion. It's used instead of TYPE_ROTATION_VECTOR since the latter uses the magnetometer on - // devices. When used indoors, the magnetometer can take some time to settle depending on the - // device and amount of metal in the environment. - int type = Util.SDK_INT >= 18 ? Sensor.TYPE_GAME_ROTATION_VECTOR : Sensor.TYPE_ROTATION_VECTOR; - orientationSensor = sensorManager.getDefaultSensor(type); + Sensor orientationSensor = null; + if (Util.SDK_INT >= 18) { + // TYPE_GAME_ROTATION_VECTOR is the easiest sensor since it handles all the complex math for + // fusion. It's used instead of TYPE_ROTATION_VECTOR since the latter uses the magnetometer on + // devices. When used indoors, the magnetometer can take some time to settle depending on the + // device and amount of metal in the environment. + orientationSensor = sensorManager.getDefaultSensor(Sensor.TYPE_GAME_ROTATION_VECTOR); + } + if (orientationSensor == null) { + orientationSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR); + } + this.orientationSensor = orientationSensor; scene = new SceneRenderer(); renderer = new Renderer(scene);