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

preview_player
Показать описание
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);
}
}
}

--
Рекомендации по теме
Комментарии
Автор

hey great video, thanks. What kind of camera do you use? I need to use the tablet's camera that I leave in my house to do the streaming, is that ok? is this api service free?

victorcapeluto
Автор

thanks fot the video mate, how can i upload a image or a video to the preview camera on real time?

galaxiapirata
Автор

Thank for the video .. I'm trying to use createConstrainedHighSpeedCaptureSession, I want 60fps

obeid_s
Автор

how to broadcast this in real time like webrtc?

pablolarade
welcome to shbcf.ru