filmov
tv
How to live stream video from camera using the new createCaptureSession API in Android App? - API 34

Показать описание
In this video it shows the steps to create live streaming video from the phone's camera on the Texture View widget of your Android App.
Complete source code and other details/ steps of this video are posted in the below link:
However, the main Java code is copied below also for reference:
public class MainActivity extends AppCompatActivity {
private TextureView textureView;
private CameraCaptureSession myCameraCaptureSession;
private String stringCameraID;
private CameraManager cameraManager;
private CameraDevice myCameraDevice;
private CaptureRequest.Builder captureRequestBuilder;
@Override
protected void onCreate(Bundle savedInstanceState) {
new String[]{CAMERA},
PackageManager.PERMISSION_GRANTED);
cameraManager = (CameraManager) getSystemService(CAMERA_SERVICE);
startCamera();
}
private CameraDevice.StateCallback stateCallback = new CameraDevice.StateCallback() {
@Override
myCameraDevice = cameraDevice;
}
@Override
}
@Override
myCameraDevice = null;
}
};
private void startCamera() {
try {
return;
}
} catch (CameraAccessException e) {
throw new RuntimeException(e);
}
}
public void buttonStartCamera(View view){
Surface surface = new Surface(surfaceTexture);
try {
OutputConfiguration outputConfiguration = new OutputConfiguration(surface);
SessionConfiguration sessionConfiguration = new SessionConfiguration(SessionConfiguration.SESSION_REGULAR,
getMainExecutor(),
new CameraCaptureSession.StateCallback() {
@Override
myCameraCaptureSession = cameraCaptureSession;
CameraMetadata.CONTROL_MODE_AUTO);
try {
} catch (CameraAccessException e) {
throw new RuntimeException(e);
}
}
@Override
myCameraCaptureSession = null;
}
}
);
} catch (CameraAccessException e) {
throw new RuntimeException(e);
}
}
public void buttonStopCamera(View view){
try {
} catch (CameraAccessException e) {
throw new RuntimeException(e);
}
}
}
--
Complete source code and other details/ steps of this video are posted in the below link:
However, the main Java code is copied below also for reference:
public class MainActivity extends AppCompatActivity {
private TextureView textureView;
private CameraCaptureSession myCameraCaptureSession;
private String stringCameraID;
private CameraManager cameraManager;
private CameraDevice myCameraDevice;
private CaptureRequest.Builder captureRequestBuilder;
@Override
protected void onCreate(Bundle savedInstanceState) {
new String[]{CAMERA},
PackageManager.PERMISSION_GRANTED);
cameraManager = (CameraManager) getSystemService(CAMERA_SERVICE);
startCamera();
}
private CameraDevice.StateCallback stateCallback = new CameraDevice.StateCallback() {
@Override
myCameraDevice = cameraDevice;
}
@Override
}
@Override
myCameraDevice = null;
}
};
private void startCamera() {
try {
return;
}
} catch (CameraAccessException e) {
throw new RuntimeException(e);
}
}
public void buttonStartCamera(View view){
Surface surface = new Surface(surfaceTexture);
try {
OutputConfiguration outputConfiguration = new OutputConfiguration(surface);
SessionConfiguration sessionConfiguration = new SessionConfiguration(SessionConfiguration.SESSION_REGULAR,
getMainExecutor(),
new CameraCaptureSession.StateCallback() {
@Override
myCameraCaptureSession = cameraCaptureSession;
CameraMetadata.CONTROL_MODE_AUTO);
try {
} catch (CameraAccessException e) {
throw new RuntimeException(e);
}
}
@Override
myCameraCaptureSession = null;
}
}
);
} catch (CameraAccessException e) {
throw new RuntimeException(e);
}
}
public void buttonStopCamera(View view){
try {
} catch (CameraAccessException e) {
throw new RuntimeException(e);
}
}
}
--
Комментарии