Android'de AR oturumu kaydetme ve oynatma

Kaydetme ve Oynatma API'si, video ve AR verilerini belirli bir ortamda bir kez kaydetmenizi ve bu içeriği bir canlı kamera oturumunun yerine kullanmanızı sağlar.

Ön koşullar

Devam etmeden önce temel AR kavramlarını ve ARCore oturumunu nasıl yapılandıracağınızı anladığınızdan emin olun.

Diğer ARCore API'leriyle uyumluluk

ARCore API'leri, oturum verilerinin işlenme şekli nedeniyle oynatma sırasında kayıt sırasında gözlemlenenden farklı sonuçlar üretebilir. Sonraki oynatma oturumlarında da farklı sonuçlar üretebilirler. Örneğin, algılanan izlenebilirlerin sayısı, algılanma zamanının tam zamanı ve pozları, oynatma sırasında zaman içinde farklı olabilir.

Paylaşılan Kamera ile uyumluluk

Paylaşılan Kamera kullanılan oturumlar kaydedilebilir. Ancak bu oturumlarda Paylaşılan Kamera modu kullanılarak oynatma özelliği şu anda kullanılamıyor.

Cloud Anchor'larla uyumluluk

Cloud Anchor'ı, bir oturum kaydederken veya oynatırken barındırabilir ve çözebilirsiniz.

Kayıt

ARCore oturum kaydını başlatabilir, durdurabilir ve durumunu kontrol edebilirsiniz.

ARCore oturumu kaydet

ARCore oturumu kaydetmek için oturumu yapılandırın ve kayıt için bir MP4 URI'si sağlayın. session.resume() numaralı telefona yapılan ilk aramadan önce session.startRecording() numaralı telefonu arayın. Kayıt, oturum devam ettiğinde otomatik olarak başlar. Oturum duraklatıldığında kaydı otomatik olarak durdurmak için RecordingConfig.setAutoStopOnPause() numaralı telefonu arayın. Kısmi bir oturumu kaydetmek için oturum devam ederken session.startRecording() numaralı telefonu arayın.

Java

// Configure the ARCore session.
Session session = new Session(context);
Uri destination = Uri.fromFile(new File(context.getFilesDir(), "recording.mp4"));
RecordingConfig recordingConfig =
        new RecordingConfig(session)
        .setMp4DatasetUri(destination)
        .setAutoStopOnPause(true);
try {
  // Prepare the session for recording, but do not start recording yet.
  session.startRecording(recordingConfig);
} catch (RecordingFailedException e) {
  Log.e(TAG, "Failed to start recording", e);
}

// Resume the ARCore session to start recording.
session.resume();

Kotlin

// Configure the ARCore session.
val session = Session(context)
val destination = Uri.fromFile(File(context.getFilesDir(), "recording.mp4"))
val recordingConfig = RecordingConfig(session)
  .setMp4DatasetUri(destination)
  .setAutoStopOnPause(true)
session.startRecording(recordingConfig)

// Resume the ARCore session to start recording.
session.resume()

Oturum kaydını durdurma

Şu anda çalışan AR oturumunu duraklatmadan kaydı durdurmak için session.stopRecording() numaralı telefonu arayın.

Java

try {
  session.stopRecording();  // Stop recording.
} catch (RecordingFailedException e) {
  Log.e(TAG, "Failed to stop recording", e);
}

Kotlin

session.stopRecording()

Kayıt durumunu kontrol edin

session.getRecordingStatus(), geçerli RecordingStatus değerini belirlemek için herhangi bir zamanda kullanılabilir.

Java

// Use any time to determine current RecordingStatus.
if (session.getRecordingStatus() == RecordingStatus.OK) {
  // Update the UI to show that the session is currently being recorded.
}

Kotlin

// Use any time to determine current RecordingStatus.
if (session.recordingStatus == RecordingStatus.OK) {
  // Update the UI to show that the session is currently being recorded.
}

Oynatma

Önceden kaydedilmiş AR oturumlarını oynatın. Oturumlar gerçek zamanlı olarak oynatılır. Oturum oynatma veya hız ayarlanamaz.

Önceden kaydedilmiş bir oturumu tekrar oynatma

Önceden kaydedilmiş bir oturumu oynatmak için session.resume() numaralı telefona yapılan ilk aramadan önce session.setPlaybackDatasetUri() numaralı telefonu arayın.

session.resume()'e yapılan ilk çağrı nedeniyle oynatma başladıktan sonra, session.pause() çağrısı yapılarak oturum duraklatıldığında, tüm kamera görüntüsü karelerinin ve veri kümesinde kayıtlı diğer sensör verilerinin işlenmesini askıya alınır. Bu şekilde silinen kamera görüntü çerçeveleri ve sensör çerçevesi verileri, session.resume() çağrısı yapılarak oturum tekrar devam ettirildiğinde yeniden işlenmez. Oturumla ilgili AR takibi genellikle işlenen verilerdeki boşluktan dolayı sorun yaşar.

Java

// Configure the ARCore session.
Session session = new Session(context);

// Specify the previously recorded MP4 file.
Uri recordingUri = Uri.fromFile(new File(context.getFilesDir(), "recording.mp4"));
session.setPlaybackDatasetUri(recordingUri);
…

// Start playback from the beginning of the dataset.
session.resume();
…

// Pause the AR session, but silently continue MP4 playback. Camera frames
// and other recorded sensor data is discarded while the session is paused.
session.pause();
…

// Resume the AR session. Camera frames and other sensor data from the MP4
// that was silently played back while the session was paused is not
// processed by ARCore.
session.resume();

Kotlin

// Configure the ARCore session.
val session = Session(context)

// Specify the previously recorded MP4 file.
val recordingUri = Uri.fromFile(File(context.filesDir, "recording.mp4"))
session.playbackDatasetUri = recordingUri
…

// Start playback from the beginning of the dataset.
session.resume()
…

// Pause the AR session, but silently continue MP4 playback. Camera frames
// and other recorded sensor data is discarded while the session is paused.
session.pause()
…

// Resume the AR session. Camera frames and other sensor data from the MP4
// that was silently played back while the session was paused is not
// processed by ARCore.
session.resume()

Oynatmayı baştan başlat

Bir oynatmayı veri kümesinin başından yeniden başlatmak için oturumu duraklatın ve oturumu devam ettirmeden önce aynı MP4 kaydını belirterek session.setPlaybackDatasetUri() numarasını arayın.

Java

session.pause();
// Pause and specify the SAME dataset:
session.setPlaybackDatasetUri(previousRecordingUri);
session.resume();  // Playback starts from the BEGINNING of the dataset.

Kotlin

session.pause()
// Pause and specify the SAME dataset:
session.playbackDatasetUri = previousRecordingUri
session.resume()  // Playback starts from the BEGINNING of the dataset.

Farklı bir oturum oynat

Farklı bir veri kümesini oynatmak için oturumu devam ettirmeden önce oturumu duraklatın ve yeni veri kümesini belirtin.

Java

// Switch to a different dataset.
session.pause();   // Pause the playback of the first dataset.
// Specify a different dataset to use.
session.setPlaybackDatasetUri(newRecordingUri);
session.resume();  // Start playback from the beginning of the new dataset.

Kotlin

// Switch to a different dataset.
session.pause()   // Pause the playback of the first dataset.
// Specify a different dataset to use.
session.playbackDatasetUri = newRecordingUri
session.resume()  // Start playback from the beginning of the new dataset.

Oynatma durumunu kontrol etme

Geçerli PlaybackStatus sürümünü belirlemek için istediğiniz zaman session.getPlaybackStatus() aracını kullanabilirsiniz.

Java

// Use any time to determine current PlaybackStatus.
if (session.getPlaybackStatus() != PlaybackStatus.OK) {
  // Update the UI to show that the session playback has finished.
}

Kotlin

// Use any time to determine current PlaybackStatus.
if (session.playbackStatus != PlaybackStatus.OK) {
  // Update the UI to show that the session playback has finished.
}

Sonraki adımlar