Interfejs Logging & Playback API umożliwia jednorazowe nagranie danych wideo i AR w danym środowisku i wykorzystanie ich zamiast sesji kamery na żywo.
Wymagania wstępne
Zanim przejdziesz dalej, upewnij się, że znasz podstawowe pojęcia związane z AR i wiesz, jak skonfigurować sesję ARCore.
Zgodność z innymi interfejsami API ARCore
Ze względu na sposób przetwarzania danych sesji interfejsy ARCore API mogą zwracać inne wyniki podczas odtwarzania niż zaobserwowane podczas nagrywania. Mogą one również przynosić inne wyniki podczas kolejnych sesji odtwarzania. Na przykład liczba wykrytych elementów do śledzenia, dokładny czas wykrycia i pozycje w czasie mogą się różnić podczas odtwarzania.
Zgodność ze współdzielonym aparatem
Sesje z użyciem udostępnionej kamery można rejestrować. Jednak odtwarzanie tych sesji przy użyciu trybu współdzielonego aparatu jest obecnie niedostępne.
Zgodność z kotwicami w chmurze
Zakotwiczone w chmurze możesz hostować i rozwiązywać problemy podczas nagrywania lub odtwarzania sesji.
Rejestrowanie
Uruchamiaj, zatrzymuj i sprawdzaj stan nagrywania sesji ARCore.
Nagraj sesję ARCore
Aby nagrać sesję ARCore, skonfiguruj sesję i podaj identyfikator URI nagrania MP4. Zadzwoń pod numer session.startRecording()
przed pierwszym połączeniem z numerem session.resume()
. Nagrywanie rozpocznie się automatycznie po wznowieniu sesji. Aby automatycznie zatrzymać nagrywanie po wstrzymaniu sesji, zadzwoń pod numer RecordingConfig.setAutoStopOnPause()
. Aby nagrać częściową sesję, wywołaj session.startRecording()
w trakcie jej trwania.
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()
Zatrzymaj nagrywanie sesji
Aby zatrzymać nagrywanie bez wstrzymywania trwającej sesji AR, zadzwoń pod numer session.stopRecording()
.
Java
try {
session.stopRecording(); // Stop recording.
} catch (RecordingFailedException e) {
Log.e(TAG, "Failed to stop recording", e);
}
Kotlin
session.stopRecording()
Sprawdzanie stanu nagrywania
session.getRecordingStatus()
można w każdej chwili określić, aby określić bieżącą wartość RecordingStatus
.
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.
}
Odtwarzanie
Odtwarzanie nagranych wcześniej sesji AR. Sesje są odtwarzane w czasie rzeczywistym, a odtwarzanie i szybkość sesji nie mogą zostać zmienione.
Odtwarzanie wcześniej nagranej sesji
Aby odtworzyć wcześniej nagraną sesję, zadzwoń pod numer session.setPlaybackDatasetUri()
przed pierwszym połączeniem z numerem session.resume()
.
Po rozpoczęciu odtwarzania z powodu pierwszego wywołania metody session.resume()
wstrzymanie sesji za pomocą wywołania session.pause()
spowoduje zawieszenie przetwarzania wszystkich klatek obrazu z kamery i innych zapisanych danych z czujnika w zbiorze danych. Odrzucone w ten sposób ramki na zdjęcia z aparatu i przetworzone dane z czujnika nie zostaną przetworzone ponownie po wznowieniu sesji przez wywołanie funkcji session.resume()
. Ogólnie rzecz biorąc, śledzenie AR podczas sesji nie będzie działać prawidłowo z powodu luk w przetwarzanych danych.
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()
Wznów odtwarzanie od początku
Aby ponownie uruchomić odtwarzanie od początku zbioru danych, wstrzymaj sesję i wywołaj metodę session.setPlaybackDatasetUri()
, wskazując to samo nagranie MP4 przed wznowieniem sesji.
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.
Odtwarzanie innej sesji
Aby odtworzyć inny zbiór danych, wstrzymaj sesję i podaj nowy zbiór danych przed jej wznowieniem.
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.
Sprawdzanie stanu odtwarzania
W każdej chwili możesz użyć session.getPlaybackStatus()
, aby sprawdzić aktualną wartość 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.
}
Co dalej?
- Dowiedz się, jak dodać dane niestandardowe do zarejestrowanych sesji.
- Zapoznaj się z Wprowadzeniem do interfejsu ARCorerecord and Playback API.