playback/src/main/java/com/intel/realsense/playback/MainActivity.java
Go to the documentation of this file.
1 package com.intel.realsense.playback;
2 
3 import android.Manifest;
4 import android.content.Intent;
5 import android.content.pm.PackageManager;
6 import android.net.Uri;
7 import android.os.Bundle;
8 import android.os.Environment;
9 import androidx.core.app.ActivityCompat;
10 import androidx.core.content.ContextCompat;
11 import androidx.appcompat.app.AppCompatActivity;
12 import android.util.Log;
13 
20 
21 public class MainActivity extends AppCompatActivity {
22 
23  private static final String TAG = "librs playback example";
24  private static final int READ_REQUEST_CODE = 0;
25  private Uri mUri;
27 
28  @Override
29  protected void onCreate(Bundle savedInstanceState) {
30  super.onCreate(savedInstanceState);
31  setContentView(R.layout.activity_main);
32 
33  mGLSurfaceView = findViewById(R.id.glSurfaceView);
34 
35  if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
36  ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 0);
37  }
38  }
39 
40  @Override
41  protected void onDestroy() {
42  super.onDestroy();
43  mGLSurfaceView.close();
44  }
45 
46  @Override
47  public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
48  if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
49  ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 0);
50  return;
51  }
52  }
53 
54  @Override
55  protected void onResume() {
56  super.onResume();
57 
58  if(mUri == null){
59  Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
60  intent.addCategory(Intent.CATEGORY_OPENABLE);
61  intent.setType("*/*");
62  startActivityForResult(intent, READ_REQUEST_CODE);
63  } else{
64  init();
65  }
66  }
67 
68  @Override
69  protected void onPause() {
70  super.onPause();
71  mStreaming.interrupt();
72  if(mStreaming.isAlive()) {
73  try {
74  mStreaming.join(1000);
75  mGLSurfaceView.clear();
76  } catch (InterruptedException e) {
77  Log.e(TAG, e.getMessage());
78  }
79  }
80  }
81 
82  private void init(){
83  mStreaming.start();
84  }
85 
86  @Override
87  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
88  super.onActivityResult(requestCode, resultCode, data);
89  if (requestCode == READ_REQUEST_CODE && resultCode == RESULT_OK) {
90  if (data != null) {
91  mUri = data.getData();
92  }
93  }
94  }
95 
96  Thread mStreaming = new Thread() {
97  @Override
98  public void run() {
99  String filePath = getExternalFilesDir(null).getAbsolutePath() + "/" + mUri.getPath().split(":")[1];
100  try(Colorizer colorizer = new Colorizer()) {
101  try (Config config = new Config()) {
102  config.enableDeviceFromFile(filePath);
103  try (Pipeline pipeline = new Pipeline()) {
104  try {
105  // try statement needed here to release resources allocated by the Pipeline:start() method
106  try (PipelineProfile pp = pipeline.start(config)) {}
107  while (!mStreaming.isInterrupted()) {
108  try (FrameSet frames = pipeline.waitForFrames()) {
109  try (FrameSet processed = frames.applyFilter(colorizer)) {
110  mGLSurfaceView.upload(processed);
111  }
112  }
113  }
114  pipeline.stop();
115  } catch (Exception e) {
116  Log.e(TAG, "streaming, error: " + e.getMessage());
117  }
118  }
119  }
120  }
121  }
122  };
123 }
::rosgraph_msgs::Log_< std::allocator< void > > Log
Definition: Log.h:88
uvc_xu_option< int > super
Definition: l500-options.h:32
e
Definition: rmse.py:177
::std_msgs::String_< std::allocator< void > > String
Definition: String.h:47
def run(include_folder_path, addon_folder_path)
Definition: enums.py:46
void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults)
Definition: threads.c:40
Definition: parser.hpp:150


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:21