Nagranie Odtwarzanie API pozwala jednorazowo nagrać dane wideo i AR w danym środowisku i wykorzystać te treści do zastąpienia sesji kamery na żywo.
Wymagania wstępne
Upewnij się, że znasz podstawowe pojęcia związane z AR. i dowiedz się, jak skonfigurować sesję ARCore, zanim przejdziesz dalej.
Zgodność z innymi interfejsami API ARCore
Ze względu na sposób przetwarzania danych sesji interfejsy ARCore API mogą podczas odtwarzania uzyskiwać inne wyniki niż zaobserwowane podczas nagrywania. Mogą też przynieść inne wyniki podczas kolejnych sesji odtwarzania. Podczas odtwarzania może się np. zmieniać liczba wykrytych obiektów śledzonych, dokładny czas ich wykrycia oraz ich pozycje w danym momencie.
Zgodność z udostępnianiem obrazu z kamery
Sesje wykorzystujące udostępnioną kamerę można nagrywać. Jednak odtwarzanie tych sesji w trybie wspólnego aparatu jest obecnie niedostępne.
Zgodność z Cloud Anchors
Zakotwiczone elementy Cloud możesz hostować i rozwiązywać podczas nagrywania lub odtwarzania sesji.
Nagrywanie
Rozpoczynanie, zatrzymywanie i sprawdzanie stanu nagrywania sesji ARCore.
Nagrywanie sesji ARCore
Aby nagrać sesję ARCore, skonfiguruj sesję i podaj identyfikator URI nagrania w formacie MP4. Przed pierwszym połączeniem z numerem session.resume()
zadzwoń pod numer session.startRecording()
. Nagrywanie rozpocznie się automatycznie po wznowieniu sesji. Aby automatycznie zatrzymać nagrywanie po wstrzymaniu sesji, wyślij wywołanie 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()
Zatrzymywanie nagrywania sesji
Aby zatrzymać nagrywanie bez wstrzymywania bieżącej sesji AR, wybierz 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że być używany w dowolnym momencie do określania bieżącego 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 wcześniej nagranych sesji AR. Sesje są odtwarzane w czasie rzeczywistym. Nie można też dostosować odtwarzania ani szybkości transmisji w sesji.
Odtwarzanie wcześniej nagranej sesji
Aby odtworzyć nagraną wcześniej sesję, zadzwoń pod numer session.setPlaybackDatasetUri()
przed pierwszym wywołaniem session.resume()
.
Po rozpoczęciu odtwarzania w następstwie pierwszego wywołania funkcji session.resume()
wstrzymanie sesji przez wywołanie funkcji session.pause()
spowoduje zawieszenie przetwarzania wszystkich klatek obrazu z kamery i innych zarejestrowanych danych z czujnika w danym zbiorze danych. Ramki zdjęcia z aparatu i dane z czujnika, które zostały odrzucone w ten sposób, nie zostaną przetworzone ponownie po ponownym wznowieniu sesji przez wywołanie metody session.resume()
. Śledzenie rozszerzonej rzeczywistości w przypadku sesji będzie zazwyczaj nieprawidłowe z powodu przerwy w przetwarzaniu 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 wznowić odtwarzanie od początku zbioru danych, wstrzymaj sesję i przed wznowieniem sesji wywołaj funkcję session.setPlaybackDatasetUri()
, podając ten sam plik MP4.
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.
Odtwórz inną sesję
Aby odtworzyć inny zbiór danych, przed wznowieniem sesji wstrzymaj sesję i określ nowy zbiór danych.
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ć narzędzia session.getPlaybackStatus()
, aby określić bieżącą
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 dodawać dane niestandardowe do nagranych sesji.
- Zapoznaj się z wprowadzeniem do interfejsu ARCore Notification API codelab.