Jetpack XR SDK รองรับการเล่นวิดีโอสเตอริโอแบบแสดงคู่บนพื้นผิวเรียบ วิดีโอสเตอริโอแต่ละเฟรมประกอบด้วยภาพจากดวงตาซ้ายและขวาเพื่อให้ผู้ชมเห็นภาพเป็นสามมิติ
คุณสามารถเรนเดอร์วิดีโอ 2 มิติแบบไม่สตรีโอสโคปในแอป Android XR โดยใช้ media API มาตรฐานที่ใช้สำหรับการพัฒนา Android ในอุปกรณ์รูปแบบอื่นๆ
เล่นวิดีโอแบบแสดงคู่กันโดยใช้ 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()
เล่นวิดีโอ 180 องศาและ 360 องศาโดยใช้ Jetpack XR SDK
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.