アプリに空間オーディオ動画を追加する

Jetpack XR SDK は、平面へのステレオ サイドバイサイド動画の再生をサポートしています。ステレオスコープ動画では、各フレームは左目と右目の画像で構成され、視聴者に奥行き感を与えます。

他のフォーム ファクタの Android 開発で使用される標準のメディア API を使用して、Android XR アプリで非ステレオ 2D 動画をレンダリングできます。

Jetpack XR SDK を使用して並べて動画を再生する

左右分割動画では、各立体フレームが横方向に隣接して配置された 2 つの画像として表示されます。上部と下部の動画フレームは、垂直方向に隣接して配置されます。

サイドバイサイド動画はコーデックではなく、立体フレームを整理する方法です。つまり、Android でサポートされているコーデックのいずれかでエンコードできます。

Media3 Exoplayer を使用して並列表示動画を読み込み、新しい StereoSurfaceEntity を使用してレンダリングできます。StereoSurfaceEntity を作成するには、次の例に示すように StereoSurfaceEntity.create を呼び出します。

stereoSurfaceEntity = StereoSurfaceEntity.create(
            xrSession,
            StereoSurfaceEntity.StereoMode.SIDE_BY_SIDE,
            // Position 1.5 meters in front of user
            Pose(Vector3(0.0f, 0.0f, -1.5f), Quaternion(0.0f, 0.0f, 0.0f, 1.0f)),
            StereoSurfaceEntity.CanvasShape.Quad(1.0f, 1.0f)
        )
        val videoUri = Uri.Builder()
            .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
            .path(R.raw.sbs_test_video.toString())
            .build()
        val mediaItem = MediaItem.fromUri(videoUri)

exoPlayer = ExoPlayer.Builder(this).build()
exoPlayer.setVideoSurface(stereoSurfaceEntity.getSurface())
exoPlayer.setMediaItem(mediaItem)
exoPlayer.prepare()
exoPlayer.play()

Jetpack XR SDK を使用して 180° 動画と 360° 動画を再生する

Alpha02 以降

バージョン 1.0.0-alpha02 以降、StereoSurfaceEntity は半球状サーフェスでの 180° 動画の再生と、球状サーフェスでの 360° 動画の再生をサポートしています。動画が立体視の場合は、ファイルが左右並びの形式である必要があります。

次のコードは、180° の半球と 360° の球面での再生用に StereoSurfaceEntity を設定する方法を示しています。これらのキャンバス形状を使用する場合は、ユーザーの頭の向きを利用してサーフェスを配置し、没入感のあるエクスペリエンスを提供します。

// Set up the surface for playing a 180° video on a hemisphere.
hemisphereStereoSurfaceEntity =
    StereoSurfaceEntity.create(
        xrCoreSession,
        StereoSurfaceEntity.StereoMode.SIDE_BY_SIDE,
        xrCoreSession.spatialUser.head?.transformPoseTo(
            Pose.Identity,
            xrCoreSession.activitySpace
        )!!,
        StereoSurfaceEntity.CanvasShape.Vr180Hemisphere(1.0f),
    )
// ... and use the surface for playing the media.
// Set up the surface for playing a 360° video on a sphere.
sphereStereoSurfaceEntity =
    StereoSurfaceEntity.create(
        xrCoreSession,
        StereoSurfaceEntity.StereoMode.TOP_BOTTOM,
        xrCoreSession.spatialUser.head?.transformPoseTo(
            Pose.Identity,
            xrCoreSession.activitySpace
        )!!,
        StereoSurfaceEntity.CanvasShape.Vr360Sphere(1.0f),
    )
// ... and use the surface for playing the media.