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

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

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

Jetpack SceneCore を使用して並列表示の動画を再生する

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

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

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

val stereoSurfaceEntity = SurfaceEntity.create(
    xrSession,
    SurfaceEntity.StereoMode.SIDE_BY_SIDE,
    Pose(Vector3(0.0f, 0.0f, -1.5f)),
    SurfaceEntity.CanvasShape.Quad(1.0f, 1.0f)
)
val videoUri = Uri.Builder()
    .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
    .path("sbs_video.mp4")
    .build()
val mediaItem = MediaItem.fromUri(videoUri)

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

Jetpack SceneCore を使用して MV-HEVC 動画を再生する

MV-HEVC コーデック規格は、立体視動画用に最適化され設計されているため、アプリで臨場感あふれる動画を高画質で効率的に再生できます。MV-HEVC ファイルには、メインストリーム(通常は左目)と、もう一方の目を含むステレオ ストリームがあります。

並列表示動画と同様に、Media3 Exoplayer を使用して読み込み、SurfaceEntity を使用してレンダリングできます。SurfaceEntity.create を呼び出すときに、MV-HEVC ファイルが左プライマリか右プライマリかを stereoMode パラメータで指定する必要があります。

// Create the SurfaceEntity with the StereoMode corresponding to the MV-HEVC content
val stereoSurfaceEntity = SurfaceEntity.create(
    xrSession,
    SurfaceEntity.StereoMode.MULTIVIEW_LEFT_PRIMARY,
    Pose(Vector3(0.0f, 0.0f, -1.5f)),
    SurfaceEntity.CanvasShape.Quad(1.0f, 1.0f)
)
val videoUri = Uri.Builder()
    .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
    .path("mvhevc_video.mp4")
    .build()
val mediaItem = MediaItem.fromUri(videoUri)

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

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

SurfaceEntity は、半球状サーフェスでの 180° 動画の再生と、球状サーフェスでの 360° 動画の再生をサポートしています。radius パラメータは、デフォルトで各サーフェスの半径サイズ(メートル単位)を指します。

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

// Set up the surface for playing a 180° video on a hemisphere.
val hemisphereStereoSurfaceEntity =
    SurfaceEntity.create(
        xrSession,
        SurfaceEntity.StereoMode.SIDE_BY_SIDE,
        xrSession.scene.spatialUser.head?.transformPoseTo(
            Pose.Identity,
            xrSession.scene.activitySpace
        )!!,
        SurfaceEntity.CanvasShape.Vr180Hemisphere(1.0f),
    )
// ... and use the surface for playing the media.

// Set up the surface for playing a 360° video on a sphere.
val sphereStereoSurfaceEntity =
    SurfaceEntity.create(
        xrSession,
        SurfaceEntity.StereoMode.TOP_BOTTOM,
        xrSession.scene.spatialUser.head?.transformPoseTo(
            Pose.Identity,
            xrSession.scene.activitySpace
        )!!,
        SurfaceEntity.CanvasShape.Vr360Sphere(1.0f),
    )
// ... and use the surface for playing the media.

Jetpack Compose for XR を使用して空間動画を再生する

XR 向け Jetpack Compose を使用して動画を再生する方法については、画像または動画コンテンツのサーフェスを追加する方法をご覧ください。