Asad
Asad

Reputation: 1439

How to rotate/move 360 spherical video in ExoPlayer in Android TV by using D-pad

I'm trying to move or rotate 360 spherical video in Android TV by using D-pad, but its rotating the player, not the spherical video.

tried with ExoPlayer and androidx.media3.exoplayer.ExoPlayer

Xml:


        <androidx.media3.ui.PlayerView
                android:id="@+id/playerView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:show_buffering="always"
                app:show_subtitle_button="true"
                app:surface_type="spherical_gl_surface_view"
                app:use_controller="true" />

Code:

            ...
    private lateinit var playerView: PlayerView
    private lateinit var player: ExoPlayer
        
        //rest implementation
            
            override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
                    when (keyCode) {
                        KeyEvent.KEYCODE_DPAD_LEFT -> {
                            // Move left (yaw left)
                            yawDegrees -= 100f // Adjust the angle as needed
                            updateRotation()
                            return true
                        }
                        KeyEvent.KEYCODE_DPAD_RIGHT -> {
                            // Move right (yaw right)
                            yawDegrees += 100f // Adjust the angle as needed
                            updateRotation()
                            return true
                        }
                    return super.onKeyDown(keyCode, event)
                }
            
            
            private fun updateRotation() {
                    playerView.videoSurfaceView?.rotation = yawDegrees
            
                }
            
            ...

Upvotes: 1

Views: 409

Answers (1)

JensV
JensV

Reputation: 4534

Apparently the SphericalGLSurfaceView does not support any rotation information source other than touch or orientation.

My suggestion is to basically copy the class from Google and modify it to your needs. (You're unable to subclass or modify without hacky reflection due to the private/final declarations).

So basically:

  1. create a copy of: SphericalGLSurfaceView
  2. Create a getter for the Renderer
  3. Create a method in the Renderer inner class which will update touchPitch and touchYawMatrix and calls updatePitchMatrix() or something. (I would investigate the onScrollChange method to figure out what values need manipulation and try around a bit)
  4. Use your own SurfaceView on the ExoPlayer by using reflection and setting surfaceView on the Player after creating it. (Because that had to be private and final as well...). Also reset the params from the old surfaceView (see this for reference)

Upvotes: 1

Related Questions