Неразрешенная ссылка: SurfaceTexture — Android ARAndroid

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Неразрешенная ссылка: SurfaceTexture — Android AR

Сообщение Anonymous »

Очень новичок в разработке Android... на самом деле пытаюсь интегрировать AR-представление в приложение Flutter.
Пытаюсь его настроить. Ниже приведен ARActivity.kt, и я не понимаю, почему мы продолжаем получать эту ошибку.
e: file:///Users/william/Documents/GitHub/game_native/android/app/src/main/kotlin/com/gps/app/ARActivity.kt:90:45 Unresolved reference: surfaceTexture

Может быть, потому, что представление поверхности запаздывает и оно не объявлено при использовании?
private lateinit var surfaceView: SurfaceView
import android.content.Context
import android.app.Activity
import android.os.Bundle
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import android.view.View
import android.view.SurfaceView
import android.view.SurfaceHolder
import com.google.ar.core.Config
import com.google.ar.core.Session
import com.google.ar.core.ArCoreApk
import com.google.ar.core.exceptions.CameraNotAvailableException

class ARActivity : AppCompatActivity() {

private var arSession: Session? = null
private lateinit var surfaceView: SurfaceView

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
window.decorView.systemUiVisibility = (
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_FULLSCREEN
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)

// First, check if ARCore is available and installed
checkAndInstallARCore(this)

// Then, initialize and set up the SurfaceView
surfaceView = SurfaceView(this)
setContentView(surfaceView)

// Finally, set up the AR session
setupARSession()
}

private fun checkAndInstallARCore(activity: Activity) {
val availability = ArCoreApk.getInstance().checkAvailability(activity)
when (availability) {
ArCoreApk.Availability.SUPPORTED_INSTALLED -> {
println("ARCore is installed and supported")
}
ArCoreApk.Availability.SUPPORTED_NOT_INSTALLED -> {
println("ARCore is not installed but supported")
ArCoreApk.getInstance().requestInstall(activity, true)
}
ArCoreApk.Availability.UNSUPPORTED_DEVICE_NOT_CAPABLE -> {
println("This device does not support ARCore")
finish() // or show a message and close the activity
}
else -> {
println("ARCore availability check failed or unknown")
}
}
}

private fun setupARSession() {
try {
arSession = Session(this as Context)
val config = Config(arSession)
config.updateMode = Config.UpdateMode.LATEST_CAMERA_IMAGE
config.planeFindingMode = Config.PlaneFindingMode.HORIZONTAL
config.lightEstimationMode = Config.LightEstimationMode.ENVIRONMENTAL_HDR
arSession?.configure(config)
} catch (e: Exception) {
println("Error setting up AR session: ${e.message}")
finish()
return
}

surfaceView.holder.addCallback(object : SurfaceHolder.Callback {
override fun surfaceCreated(holder: SurfaceHolder) {
try {
arSession?.resume()
checkAndSetTexture(holder)
} catch (e: CameraNotAvailableException) {
println("Camera not available on surfaceCreated: ${e.message}")
} catch (e: ClassCastException) {
println("Failed to cast holder to SurfaceHolder: ${e.message}")
}
}

private fun checkAndSetTexture(holder: SurfaceHolder) {
val surfaceTexture = holder.surfaceTexture
if (surfaceTexture.isNotEmpty) {
arSession?.setCameraTextureName(surfaceTexture.getTextureId())
println("Texture ID set: ${surfaceTexture.getTextureId()}")
} else {
println("SurfaceTexture not available, retrying in 100ms")
surfaceView.postDelayed({ checkAndSetTexture(holder) }, 100)
}
}

override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
// This method can be used to adjust AR configuration if the surface size changes
}

override fun surfaceDestroyed(holder: SurfaceHolder) {
arSession?.pause()
}
})
}

// ... rest of your lifecycle methods ...
override fun onResume() {
super.onResume()
try {
arSession?.resume()
} catch (e: CameraNotAvailableException) {
println("Camera not available during onResume: ${e.message}")
}
}

override fun onPause() {
super.onPause()
arSession?.pause()
}

override fun onDestroy() {
super.onDestroy()
arSession?.close()
}

}


Подробнее здесь: https://stackoverflow.com/questions/793 ... android-ar
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»