Skip to content

Commit 1a51958

Browse files
committed
add camera1 zoom by value
1 parent c3afe26 commit 1a51958

File tree

4 files changed

+89
-3
lines changed

4 files changed

+89
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ allprojects {
5151
}
5252
}
5353
dependencies {
54-
implementation 'com.github.pedroSG94.rtmp-rtsp-stream-client-java:rtplibrary:2.1.5'
54+
implementation 'com.github.pedroSG94.rtmp-rtsp-stream-client-java:rtplibrary:2.1.6'
5555
}
5656
5757
```

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
buildscript {
44
ext.kotlin_version = '1.6.10'
55
ext.library_group = "com.github.pedroSG94"
6-
ext.version_code = 215
7-
ext.version_name = "2.1.5"
6+
ext.version_code = 216
7+
ext.version_name = "2.1.6"
88

99
repositories {
1010
google()

encoder/src/main/java/com/pedro/encoder/input/video/Camera1ApiManager.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,54 @@ public void setPreviewOrientation(final int orientation) {
216216
}
217217
}
218218

219+
public void setZoom(int level) {
220+
try {
221+
if (camera != null && running && camera.getParameters() != null && camera.getParameters()
222+
.isZoomSupported()) {
223+
android.hardware.Camera.Parameters params = camera.getParameters();
224+
int maxZoom = params.getMaxZoom();
225+
if (level > maxZoom) level = maxZoom;
226+
else if (level < getMinZoom()) level = getMinZoom();
227+
params.setZoom(level);
228+
camera.setParameters(params);
229+
}
230+
} catch (Exception e) {
231+
Log.e(TAG, "Error", e);
232+
}
233+
}
234+
235+
public int getZoom() {
236+
try {
237+
if (camera != null && running && camera.getParameters() != null && camera.getParameters()
238+
.isZoomSupported()) {
239+
android.hardware.Camera.Parameters params = camera.getParameters();
240+
return params.getZoom();
241+
} else {
242+
return getMinZoom();
243+
}
244+
} catch (Exception e) {
245+
Log.e(TAG, "Error", e);
246+
return getMinZoom();
247+
}
248+
}
249+
250+
public int getMaxZoom() {
251+
try {
252+
if (camera != null && running && camera.getParameters() != null && camera.getParameters()
253+
.isZoomSupported()) {
254+
android.hardware.Camera.Parameters params = camera.getParameters();
255+
return params.getMaxZoom();
256+
} else {
257+
return getMinZoom();
258+
}
259+
} catch (Exception e) {
260+
Log.e(TAG, "Error", e);
261+
return getMinZoom();
262+
}
263+
}
264+
265+
public int getMinZoom() { return 0; }
266+
219267
public void setZoom(MotionEvent event) {
220268
try {
221269
if (camera != null && running && camera.getParameters() != null && camera.getParameters()

rtplibrary/src/main/java/com/pedro/rtplibrary/base/Camera1Base.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,44 @@ public void setZoom(MotionEvent event) {
561561
cameraManager.setZoom(event);
562562
}
563563

564+
/**
565+
* Set zoomIn or zoomOut to camera.
566+
* Use this method if you use a zoom slider.
567+
*
568+
* @param level Expected to be >= 1 and <= max zoom level
569+
* @see Camera2Base#getZoom()
570+
*/
571+
public void setZoom(int level) {
572+
cameraManager.setZoom(level);
573+
}
574+
575+
/**
576+
* Return current zoom level
577+
*
578+
* @return current zoom level
579+
*/
580+
public float getZoom() {
581+
return cameraManager.getZoom();
582+
}
583+
584+
/**
585+
* Return max zoom level
586+
*
587+
* @return max zoom level range
588+
*/
589+
public int getMaxZoom() {
590+
return cameraManager.getMaxZoom();
591+
}
592+
593+
/**
594+
* Return min zoom level
595+
*
596+
* @return min zoom level range
597+
*/
598+
public int getMinZoom() {
599+
return cameraManager.getMinZoom();
600+
}
601+
564602
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
565603
public void startStreamAndRecord(String url, String path, RecordController.Listener listener) throws IOException {
566604
startStream(url);

0 commit comments

Comments
 (0)