google / ExoPlayer

This project is deprecated and stale. The latest ExoPlayer code is available in https://github.com/androidx/media
https://developer.android.com/media/media3/exoplayer
Apache License 2.0
21.71k stars 6.02k forks source link

How to enable GyroSensors for Exoplayer 360 videos #6966

Closed shanu-jha closed 4 years ago

shanu-jha commented 4 years ago

I am developing a custom player based on Exoplayer for playing VR videos. I was able to create a Simplified version using SimpleExoPlayer however, even though I move my device, the VR player doesn't rotate as it should.

I then went to try out the Exoplayer demo and it completely worked. However, I was unable to modify the code to fit my needs, so I had to start from scratch.

As I mentioned, I was able to create a very simplified version. however, the gyro sensors are not rotating the video. I wonder, what I am missing.

Here is my VRPlayerActivity:

class VRPlayerActivity : AppCompatActivity() {

    private val mp4VideoUri: Uri? = Uri.parse("https://theyouthbuzz.com/ytplayer/Seoul8KVR3DTrailer.mp4")

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_vrplayer)
        val player = SimpleExoPlayer.Builder(this).build()
        val playerView = findViewById<SimpleExoPlayerView>(R.id.player_view)

        // Produces DataSource instances through which media data is loaded.
        // Produces DataSource instances through which media data is loaded.
        val dataSourceFactory: DataSource.Factory = DefaultDataSourceFactory(
            this,
            Util.getUserAgent(this, "YouthBuzz")
        )
        // This is the MediaSource representing the media to be played.
        // This is the MediaSource representing the media to be played.
        val videoSource: MediaSource = ProgressiveMediaSource.Factory(dataSourceFactory)
            .createMediaSource(mp4VideoUri)
        // Prepare the player with the source.
        // Prepare the player with the source.
        player.prepare(videoSource)
        (playerView.videoSurfaceView as SphericalGLSurfaceView?)!!.setDefaultStereoMode(
            C.STEREO_MODE_TOP_BOTTOM
        )

        playerView.player = player

    }
}
kim-vde commented 4 years ago

Did you set the surface_type attribute of the PlayerView to spherical_view? Did you call PlayerView.onResume() and PlayerView.onPause() at the correct time?

shanu-jha commented 4 years ago

Thank you very much @kim-vde ! It worked when I put those methods in place