Android'de AR oturumu kaydetme ve oynatma

Kayıt ve Playback API'si, video ve AR verilerini belirli bir ortamda bir kez kaydedip bu içeriği canlı kamera oturumu yerine kullanmanızı sağlar.

Ön koşullar

Temel artırılmış gerçeklik kavramlarını anladığınızdan emin olun ve devam etmeden önce ARCore oturumunun nasıl yapılandırılacağı hakkında daha fazla bilgi edinin.

Diğer ARCore API'leriyle uyumluluk

Oturum verilerinin işlenme biçimi nedeniyle, ARCore API'leri oynatma sırasında kayıt sırasında gözlemlenenden farklı sonuçlar üretebilir. Ayrıca sonraki oynatma oturumlarında farklı sonuçlar üretebilirler. Örneğin, algılanan takip edilebilir öğelerin sayısı, algılanmalarının tam zamanlaması ve zaman içindeki duruşları oynatma sırasında farklı olabilir.

Paylaşılan Kamera ile uyumluluk

Paylaşılan Kamera'nın kullanıldığı oturumlar kaydedilebilir. Ancak, Paylaşılan Kamera modu kullanılarak bu oturumların oynatılması şu anda mümkün değildir.

Cloud Anchor ile uyumluluk

Bir oturumu kaydederken veya oynatırken Cloud Anchor'larını barındırabilir ve çözümleyebilirsiniz.

Kayıt

ARCore oturum kaydını başlatın, durdurun ve durumunu kontrol edin.

ARCore oturumunu kaydetme

ARCore oturumunu 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() adlı kişiyi arayın. Oturum devam ettiğinde kayıt otomatik olarak başlar. Oturum duraklatıldığında kaydı otomatik olarak durdurmak için RecordingConfig.setAutoStopOnPause() numaralı telefonu arayın. Oturumun bir kısmını kaydetmek için oturum devam ederken session.startRecording() tuşuna bası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

Devam eden AR oturumunu duraklatmadan kaydı durdurmak için session.stopRecording() simgesini çağırı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() mevcut RecordingStatus değerini belirlemek için 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 kaydedilen AR oturumlarını oynatma. Oturumlar gerçek zamanlı olarak oynatılır ve oturum oynatma veya hızı ayarlanamaz.

Daha önce kaydedilmiş bir oturumu 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() için yapılan ilk çağrı nedeniyle oynatma başladıktan sonra session.pause() numaralı telefonu arayarak oturumu duraklatmak, tüm kamera görüntü çerçevelerinin ve veri kümesinde kayıtlı diğer tüm sensör verilerinin işlenmesini askıya alır. Bu şekilde silinen kamera görüntü çerçeveleri ve sensör çerçevesi verileri, session.resume() çağrısı yapılarak oturum yeniden başlatıldığında yeniden işlenmez. Oturumun AR izlemesi genellikle işlenen verilerdeki boşluk nedeniyle yaşanır.

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şlatma

Bir oynatmayı veri kümesinin başından itibaren yeniden başlatmak için oturumu duraklatın ve oturumu devam ettirmeden önce aynı MP4 kaydını belirterek session.setPlaybackDatasetUri() işlevini çağırı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 oturumu oynat

Farklı bir veri kümesini oynatmak için oturumu duraklatın ve oturumu devam ettirmeden önce 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

İstediğiniz zaman session.getPlaybackStatus() PlaybackStatus.

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

Sırada ne var?