تسجيل جلسة الواقع المعزّز وتشغيلها على جهاز Android

تتيح لك واجهة برمجة تطبيقات التسجيل والتشغيل تسجيل الفيديو وبيانات الواقع المعزّز مرة واحدة في بيئة معينة واستخدام ذلك المحتوى كبديل لجلسة كاميرا مباشرة.

المتطلبات الأساسية

قبل المتابعة، تأكد من فهم مفاهيم الواقع المعزّز الأساسية وكيفية ضبط جلسة ARCore.

التوافق مع واجهات برمجة تطبيقات ARCore الأخرى

بسبب طريقة معالجة بيانات الجلسات، قد تعرض واجهات برمجة تطبيقات ARCore نتائج مختلفة أثناء التشغيل عن النتائج التي يتم رصدها أثناء التسجيل. وقد تعرض أيضًا نتائج مختلفة أثناء جلسات التشغيل اللاحقة. على سبيل المثال، قد يختلف عدد العناصر القابلة للتتبّع التي تم اكتشافها والتوقيت الدقيق لها وأوضاعها بمرور الوقت أثناء التشغيل.

التوافق مع الكاميرا المشتركة

يمكن تسجيل الجلسات التي تستخدم الكاميرا المشتركة. ولكن تشغيل هذه الجلسات باستخدام وضع الكاميرا المشتركة غير متاح حاليًا.

التوافق مع "ثبات السحابة الإلكترونية"

يمكنك استضافة إعلانات Cloud ارتساء وحلّها أثناء تسجيل جلسة أو تشغيلها.

يتم التسجيل

بدء تسجيل جلسة ARCore وإيقافه والتحقّق من حالته

تسجيل جلسة ARCore

لتسجيل جلسة ARCore، يمكنك تهيئة الجلسة وتوفير معرف موارد منتظم (URI) بتنسيق MP4 للتسجيل. يمكنك الاتصال بـ session.startRecording() قبل المكالمة الأولى على الرقم session.resume(). يبدأ التسجيل تلقائيًا عند استئناف الجلسة. لإيقاف التسجيل تلقائيًا عند إيقاف الجلسة مؤقتًا، يمكنك الاتصال بالرقم RecordingConfig.setAutoStopOnPause(). لتسجيل جلسة جزئية، اتصل بالرقم session.startRecording() أثناء تشغيل الجلسة.

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()

إيقاف تسجيل الجلسة

لإيقاف التسجيل بدون إيقاف جلسة الواقع المعزّز قيد التشغيل حاليًا، يُرجى الاتصال بالرقم session.stopRecording().

Java

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

Kotlin

session.stopRecording()

التحقّق من حالة التسجيل

يمكن استخدام session.getRecordingStatus() في أي وقت لتحديد قيمة 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.
}

التشغيل

تشغيل جلسات الواقع المعزّز المُسجّلة سابقًا يتم تشغيل الجلسات في الوقت الفعلي، ولا يمكن ضبط تشغيل الجلسة أو سرعتها.

تشغيل جلسة تم تسجيلها سابقًا

لتشغيل جلسة تم تسجيلها مسبقًا، اتّصِل بالرقم session.setPlaybackDatasetUri() قبل المكالمة الأولى إلى الرقم session.resume().

بعد بدء التشغيل بسبب أول اتصال بـ session.resume()، سيؤدي الإيقاف المؤقت للجلسة من خلال طلب session.pause() إلى تعليق معالجة جميع إطارات صور الكاميرا وأي بيانات أجهزة استشعار أخرى يتم تسجيلها في مجموعة البيانات. لن تتم إعادة معالجة إطارات صور الكاميرا وبيانات إطارات أداة الاستشعار التي تم تجاهلها بهذه الطريقة عند استئناف الجلسة من خلال طلب session.resume(). سيتأثر تتبُّع الواقع المعزّز للجلسة بشكل عام بسبب الفجوة في البيانات التي تمت معالجتها.

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()

إعادة تشغيل الفيديو من البداية

لإعادة تشغيل عملية التشغيل من بداية مجموعة البيانات، أوقِف الجلسة مؤقتًا واستدعِ المشكلة session.setPlaybackDatasetUri()، مع تحديد تسجيل 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.

تشغيل جلسة أخرى

لتشغيل مجموعة بيانات مختلفة، أوقف الجلسة مؤقتًا وحدد مجموعة البيانات الجديدة قبل استئناف الجلسة.

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.

التحقّق من حالة التشغيل

يمكنك استخدام 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.
}

الخطوات التالية