在應用程式中加入空間定位影片

Jetpack XR SDK 支援在平面上播放立體並排影片。立體影片的每個影格都包含左眼和右眼圖像,可讓觀眾感受到深度。

您可以在 Android XR 應用程式中,使用用於其他板型規格的 Android 開發的標準媒體 API,算繪非立體 2D 影片。

使用 Jetpack XR SDK 播放並排影片

在並排影片中,每個立體影格會以兩張圖片的形式呈現,並水平排列。頂部和底部的影片影格會以垂直相鄰的方式排列。

並排視訊不是轉碼器,而是一種安排立體影格的方式,也就是說,它可以使用 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 度影片。如果影片為立體格式,檔案應採用並排格式。

以下程式碼說明如何設定 StereoSurfaceEntity,以便在 180 度半球和 360 度球上播放。使用這些畫布形狀時,請利用使用者的頭部姿勢來定位表面,以提供身歷式體驗。

// 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.