public void setFlashMode(boolean on) { if (mCamera == null) { return; } releaseCamera(); int cameraId = mPublisher.getCameraId(); ((CustomVideoCapturer) mPublisher.getCapturer()).setFlashOn(true); // Camera camera = Camera.open(cameraId); // try { // camera.setPreviewDisplay(new SurfaceView(mContext).getHolder()); // } catch (IOException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // Parameters params = camera.getParameters(); // params.setFlashMode(Parameters.FLASH_MODE_TORCH); // camera.setParameters(params); // try { // ClassLoader cl = ClassLoader.getSystemClassLoader(); // mCameraClass = cl.loadClass("android.hardware.Camera"); // mParametersClass = cl.loadClass("android.hardware.Camera$Parameters"); // Method method = mCameraClass.getMethod("open", Integer.TYPE); // mCamera = method.invoke(mCamera, cameraId); // // SurfaceView surface = new SurfaceView(mContext); // SurfaceHolder holder = surface.getHolder(); // method = mCameraClass.getMethod("setPreviewDisplay", SurfaceHolder.class); // method.invoke(mCamera, holder); //// Camera c; //// c.setPreviewDisplay(holder); // // Method m = mCameraClass.getMethod("getParameters"); // Object params = m.invoke(mCamera); // m = mParametersClass.getMethod("setFlashMode", String.class); // m.invoke(params, // on?FLASH_MODE_TORCH:mOriginalFlashMode==null?FLASH_MODE_OFF:mOriginalFlashMode); // // m = mCameraClass.getMethod("setParameters", mParametersClass); // m.invoke(mCamera, params); // // Log.i(TAG, "flash mode is set"); // // m = mCameraClass.getMethod("release"); // m.invoke(mCamera); // } catch (Throwable t) { // Log.e(TAG, "aaa", t); // } attachCamera(); }
@Override public void onConnected(Session session) { Log.v(TAG, "Connected to session " + session.getSessionId()); Log.v(TAG, "Starting to publish video to session " + session.getSessionId()); videoOutPublisher = new Publisher(context); videoOutPublisher .swapCamera(); // need a button to make this controlled by user, depending on phone videoOutPublisher.setPublisherListener(this); videoOutViewGroup.addView(videoOutPublisher.getView()); getSession().publish(videoOutPublisher); }
public void startTransmitting(ViewGroup frame) { mPublisher = new Publisher(mContext, "You"); mPublisher.setCapturer(new CustomVideoCapturer(mContext)); // mPublisher.setRenderer(new CustomVideoRenderer(mContext)); mPublisher.setPublisherListener(mPublisherListener); mPublisher.setStyle(BaseVideoRenderer.STYLE_VIDEO_SCALE, BaseVideoRenderer.STYLE_VIDEO_FILL); LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); frame.removeAllViews(); frame.addView(mPublisher.getView(), params); mSession.publish(mPublisher); }
// callbacks @Override protected void onConnected() { Publisher p = new Publisher(mContext, "MyPublisher"); publish(p); // Add video preview RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); mPreview.addView(p.getView(), lp); p.setStyle(BaseVideoRenderer.STYLE_VIDEO_SCALE, BaseVideoRenderer.STYLE_VIDEO_FILL); presentText("Welcome to OpenTok Chat."); }
public boolean isFlashLightOn() { if (mPublisher == null) { return false; } if (true) return ((CustomVideoCapturer) mPublisher.getCapturer()).isFlashOn(); releaseCamera(); boolean result = false; int cameraId = mPublisher.getCameraId(); try { ClassLoader cl = ClassLoader.getSystemClassLoader(); mCameraClass = cl.loadClass("android.hardware.Camera"); mParametersClass = cl.loadClass("android.hardware.Camera$Parameters"); Method method = mCameraClass.getMethod("open", Integer.TYPE); mCamera = method.invoke(mCamera, cameraId); SurfaceView surface = new SurfaceView(mContext); SurfaceHolder holder = surface.getHolder(); method = mCameraClass.getMethod("setPreviewDisplay", SurfaceHolder.class); method.invoke(mCamera, holder); Method m = mCameraClass.getMethod("getParameters"); Object params = m.invoke(mCamera); m = mParametersClass.getMethod("getFlashMode"); String flashMode = (String) m.invoke(params); m = mCameraClass.getMethod("release"); m.invoke(mCamera); if (FLASH_MODE_TORCH.equals(flashMode)) { result = true; } else { mOriginalFlashMode = flashMode; result = false; } } catch (Throwable t) { Log.e(TAG, "aaa", t); result = false; } attachCamera(); return result; }
@Override public void onConnected(Session session) { Log.i(LOGTAG, "Connected to the session."); if (mPublisher == null) { mPublisher = new Publisher(VideoFlyService.this, "publisher"); mPublisher.setPublisherListener(this); // attachPublisherView(mPublisher); mSession.publish(mPublisher); } Log.i(LOGTAG, "Connected to the session."); }
private void releaseCamera() { if (mPublisher == null) { return; } CustomVideoCapturer capturer = (CustomVideoCapturer) mPublisher.getCapturer(); // BaseVideoCapturer capturer = mPublisher.getCapturer(); if (capturer == null) { return; } capturer.stopCapture(); capturer.destroy(); }
private void attachCamera() { if (mPublisher == null) { return; } // CustomVideoCapturer capturer = mPublisher.getCapturer(); CustomVideoCapturer capturer = (CustomVideoCapturer) mPublisher.getCapturer(); if (capturer == null) { return; } if (!capturer.isCaptureStarted()) { capturer.init(); capturer.startCapture(); } }
public void swapCamera() { CustomVideoCapturer customVideoCapturer = (CustomVideoCapturer) mPublisher.getCapturer(); try { if (customVideoCapturer.isFrontCamera()) { customVideoCapturer.swapCamera(customVideoCapturer.getMainCameraIndex()); } else { customVideoCapturer.swapCamera(customVideoCapturer.getFrontCameraIndex()); } } catch (Exception ex) { ex.printStackTrace(); Toast.makeText(mContext, R.string.connection_failed_try_again, Toast.LENGTH_LONG).show(); } // if(mPublisher != null) // mPublisher.swapCamera(); }
public void toggleFlashLight(boolean isOn) { CustomVideoCapturer capturer = (CustomVideoCapturer) mPublisher.getCapturer(); capturer.toggleFlashLight(isOn); }
public boolean isFrontCam() { CustomVideoCapturer customVideoCapturer = (CustomVideoCapturer) mPublisher.getCapturer(); return customVideoCapturer.isFrontCamera(); }