|
| 1 | +/* |
| 2 | + * Copyright 2025 The Android Open Source Project |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.example.xr.compose |
| 18 | + |
| 19 | +import android.content.ContentResolver |
| 20 | +import android.net.Uri |
| 21 | +import androidx.compose.runtime.Composable |
| 22 | +import androidx.compose.runtime.remember |
| 23 | +import androidx.compose.ui.platform.LocalContext |
| 24 | +import androidx.compose.ui.unit.dp |
| 25 | +import androidx.media3.common.MediaItem |
| 26 | +import androidx.media3.exoplayer.ExoPlayer |
| 27 | +import androidx.xr.compose.spatial.Subspace |
| 28 | +import androidx.xr.compose.subspace.SpatialExternalSurface |
| 29 | +import androidx.xr.compose.subspace.StereoMode |
| 30 | +import androidx.xr.compose.subspace.layout.SubspaceModifier |
| 31 | +import androidx.xr.compose.subspace.layout.height |
| 32 | +import androidx.xr.compose.subspace.layout.width |
| 33 | + |
| 34 | +// [START androidxr_compose_SpatialExternalSurfaceStereo] |
| 35 | +@Composable |
| 36 | +fun SpatialExternalSurfaceContent() { |
| 37 | + val context = LocalContext.current |
| 38 | + Subspace { |
| 39 | + SpatialExternalSurface( |
| 40 | + modifier = SubspaceModifier |
| 41 | + .width(1200.dp) |
| 42 | + .height(676.dp), |
| 43 | + stereoMode = StereoMode.TopBottom, |
| 44 | + ) { |
| 45 | + val exoPlayer = remember { ExoPlayer.Builder(context).build() } |
| 46 | + val videoUri = Uri.Builder() |
| 47 | + .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) |
| 48 | + .path("sbs_video.mp4") |
| 49 | + .build() |
| 50 | + val mediaItem = MediaItem.fromUri(videoUri) |
| 51 | + |
| 52 | + onSurfaceCreated { surface -> |
| 53 | + exoPlayer.setVideoSurface(surface) |
| 54 | + exoPlayer.setMediaItem(mediaItem) |
| 55 | + exoPlayer.prepare() |
| 56 | + exoPlayer.play() |
| 57 | + } |
| 58 | + onSurfaceDestroyed { exoPlayer.release() } |
| 59 | + } |
| 60 | + } |
| 61 | +} |
| 62 | +// [END androidxr_compose_SpatialExternalSurfaceStereo] |
0 commit comments