Java Code Examples for android.view.SurfaceHolder#getSurfaceFrame()
The following examples show how to use
android.view.SurfaceHolder#getSurfaceFrame() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleExoPlayer.java From MediaSDK with Apache License 2.0 | 6 votes |
@Override public void setVideoSurfaceHolder(@Nullable SurfaceHolder surfaceHolder) { verifyApplicationThread(); removeSurfaceCallbacks(); if (surfaceHolder != null) { clearVideoDecoderOutputBufferRenderer(); } this.surfaceHolder = surfaceHolder; if (surfaceHolder == null) { setVideoSurfaceInternal(null, /* ownsSurface= */ false); maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0); } else { surfaceHolder.addCallback(componentListener); Surface surface = surfaceHolder.getSurface(); if (surface != null && surface.isValid()) { setVideoSurfaceInternal(surface, /* ownsSurface= */ false); Rect surfaceSize = surfaceHolder.getSurfaceFrame(); maybeNotifySurfaceSizeChanged(surfaceSize.width(), surfaceSize.height()); } else { setVideoSurfaceInternal(/* surface= */ null, /* ownsSurface= */ false); maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0); } } }
Example 2
Source File: SimpleExoPlayer.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
@Override public void setVideoSurfaceHolder(SurfaceHolder surfaceHolder) { removeSurfaceCallbacks(); this.surfaceHolder = surfaceHolder; if (surfaceHolder == null) { setVideoSurfaceInternal(null, false); maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0); } else { surfaceHolder.addCallback(componentListener); Surface surface = surfaceHolder.getSurface(); if (surface != null && surface.isValid()) { setVideoSurfaceInternal(surface, /* ownsSurface= */ false); Rect surfaceSize = surfaceHolder.getSurfaceFrame(); maybeNotifySurfaceSizeChanged(surfaceSize.width(), surfaceSize.height()); } else { setVideoSurfaceInternal(/* surface= */ null, /* ownsSurface= */ false); maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0); } } }
Example 3
Source File: SimpleExoPlayer.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
@Override public void setVideoSurfaceHolder(SurfaceHolder surfaceHolder) { removeSurfaceCallbacks(); this.surfaceHolder = surfaceHolder; if (surfaceHolder == null) { setVideoSurfaceInternal(null, false); maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0); } else { surfaceHolder.addCallback(componentListener); Surface surface = surfaceHolder.getSurface(); if (surface != null && surface.isValid()) { setVideoSurfaceInternal(surface, /* ownsSurface= */ false); Rect surfaceSize = surfaceHolder.getSurfaceFrame(); maybeNotifySurfaceSizeChanged(surfaceSize.width(), surfaceSize.height()); } else { setVideoSurfaceInternal(/* surface= */ null, /* ownsSurface= */ false); maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0); } } }
Example 4
Source File: SimpleExoPlayer.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
@Override public void setVideoSurfaceHolder(SurfaceHolder surfaceHolder) { verifyApplicationThread(); removeSurfaceCallbacks(); this.surfaceHolder = surfaceHolder; if (surfaceHolder == null) { setVideoSurfaceInternal(null, false); maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0); } else { surfaceHolder.addCallback(componentListener); Surface surface = surfaceHolder.getSurface(); if (surface != null && surface.isValid()) { setVideoSurfaceInternal(surface, /* ownsSurface= */ false); Rect surfaceSize = surfaceHolder.getSurfaceFrame(); maybeNotifySurfaceSizeChanged(surfaceSize.width(), surfaceSize.height()); } else { setVideoSurfaceInternal(/* surface= */ null, /* ownsSurface= */ false); maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0); } } }
Example 5
Source File: SimpleExoPlayer.java From Telegram with GNU General Public License v2.0 | 6 votes |
@Override public void setVideoSurfaceHolder(SurfaceHolder surfaceHolder) { verifyApplicationThread(); removeSurfaceCallbacks(); this.surfaceHolder = surfaceHolder; if (surfaceHolder == null) { setVideoSurfaceInternal(null, false); maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0); } else { surfaceHolder.addCallback(componentListener); Surface surface = surfaceHolder.getSurface(); if (surface != null && surface.isValid()) { setVideoSurfaceInternal(surface, /* ownsSurface= */ false); Rect surfaceSize = surfaceHolder.getSurfaceFrame(); maybeNotifySurfaceSizeChanged(surfaceSize.width(), surfaceSize.height()); } else { setVideoSurfaceInternal(/* surface= */ null, /* ownsSurface= */ false); maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0); } } }
Example 6
Source File: Magnifier.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Retrieves the surfaces used by the magnifier: * - a parent surface for the magnifier surface. This will usually be the main app window. * - a surface where the magnified content will be copied from. This will be the main app * window unless the magnified view is a SurfaceView, in which case its backing surface * will be used. */ private void obtainSurfaces() { // Get the main window surface. SurfaceInfo validMainWindowSurface = SurfaceInfo.NULL; if (mView.getViewRootImpl() != null) { final ViewRootImpl viewRootImpl = mView.getViewRootImpl(); final Surface mainWindowSurface = viewRootImpl.mSurface; if (mainWindowSurface != null && mainWindowSurface.isValid()) { final Rect surfaceInsets = viewRootImpl.mWindowAttributes.surfaceInsets; final int surfaceWidth = viewRootImpl.getWidth() + surfaceInsets.left + surfaceInsets.right; final int surfaceHeight = viewRootImpl.getHeight() + surfaceInsets.top + surfaceInsets.bottom; validMainWindowSurface = new SurfaceInfo(mainWindowSurface, surfaceWidth, surfaceHeight, true); } } // Get the surface backing the magnified view, if it is a SurfaceView. SurfaceInfo validSurfaceViewSurface = SurfaceInfo.NULL; if (mView instanceof SurfaceView) { final SurfaceHolder surfaceHolder = ((SurfaceView) mView).getHolder(); final Surface surfaceViewSurface = surfaceHolder.getSurface(); if (surfaceViewSurface != null && surfaceViewSurface.isValid()) { final Rect surfaceFrame = surfaceHolder.getSurfaceFrame(); validSurfaceViewSurface = new SurfaceInfo(surfaceViewSurface, surfaceFrame.right, surfaceFrame.bottom, false); } } // Choose the parent surface for the magnifier and the source surface for the content. mParentSurface = validMainWindowSurface != SurfaceInfo.NULL ? validMainWindowSurface : validSurfaceViewSurface; mContentCopySurface = mView instanceof SurfaceView ? validSurfaceViewSurface : validMainWindowSurface; }
Example 7
Source File: ExoVlcUtil.java From Exoplayer_VLC with Apache License 2.0 | 5 votes |
static boolean validSurface(SurfaceHolder holder) { if (holder.getSurface() != null) { Rect r = holder.getSurfaceFrame(); System.out.println("ExoVlcUtil.validSurface() r = " + r); return (r.width() * r.height()) > 0; } return false; }
Example 8
Source File: ExoVlcUtil.java From Exoplayer_VLC with Apache License 2.0 | 5 votes |
static boolean validSurface(SurfaceHolder holder) { if (holder.getSurface() != null) { Rect r = holder.getSurfaceFrame(); System.out.println("ExoVlcUtil.validSurface() r = " + r); return (r.width() * r.height()) > 0; } return false; }
Example 9
Source File: CameraManager.java From GreenBits with GNU General Public License v3.0 | 4 votes |
public Camera open(final SurfaceHolder holder, final boolean continuousAutoFocus) throws IOException { // try back-facing camera camera = Camera.open(); // fall back to using front-facing camera if (camera == null) { final int cameraCount = Camera.getNumberOfCameras(); final CameraInfo cameraInfo = new CameraInfo(); // search for front-facing camera for (int i = 0; i < cameraCount; i++) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { camera = Camera.open(i); break; } } } camera.setPreviewDisplay(holder); final Camera.Parameters parameters = camera.getParameters(); final Rect surfaceFrame = holder.getSurfaceFrame(); cameraResolution = findBestPreviewSizeValue(parameters, surfaceFrame); final int surfaceWidth = surfaceFrame.width(); final int surfaceHeight = surfaceFrame.height(); final int rawSize = Math.min(surfaceWidth * 2 / 3, surfaceHeight * 2 / 3); final int frameSize = Math.max(MIN_FRAME_SIZE, Math.min(MAX_FRAME_SIZE, rawSize)); final int leftOffset = (surfaceWidth - frameSize) / 2; final int topOffset = (surfaceHeight - frameSize) / 2; frame = new Rect(leftOffset, topOffset, leftOffset + frameSize, topOffset + frameSize); framePreview = new Rect(frame.left * cameraResolution.width / surfaceWidth, frame.top * cameraResolution.height / surfaceHeight, frame.right * cameraResolution.width / surfaceWidth, frame.bottom * cameraResolution.height / surfaceHeight); final String savedParameters = parameters == null ? null : parameters.flatten(); try { setDesiredCameraParameters(camera, cameraResolution, continuousAutoFocus); } catch (final RuntimeException x) { if (savedParameters != null) { final Camera.Parameters parameters2 = camera.getParameters(); parameters2.unflatten(savedParameters); try { camera.setParameters(parameters2); setDesiredCameraParameters(camera, cameraResolution, continuousAutoFocus); } catch (final RuntimeException x2) { log.info("problem setting camera parameters", x2); } } } camera.startPreview(); return camera; }
Example 10
Source File: CameraManager.java From bither-android with Apache License 2.0 | 4 votes |
public Camera open(final SurfaceHolder holder, final boolean continuousAutoFocus) throws IOException { // try back-facing camera camera = Camera.open(); // fall back to using front-facing camera if (camera == null) { final int cameraCount = Camera.getNumberOfCameras(); final CameraInfo cameraInfo = new CameraInfo(); // search for front-facing camera for (int i = 0; i < cameraCount; i++) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { camera = Camera.open(i); break; } } } camera.setDisplayOrientation(90); camera.setPreviewDisplay(holder); final Camera.Parameters parameters = camera.getParameters(); final Rect surfaceFrame = holder.getSurfaceFrame(); cameraResolution = findBestPreviewSizeValue(parameters, surfaceFrame); final int surfaceWidth = surfaceFrame.width(); final int surfaceHeight = surfaceFrame.height(); final int rawSize = Math.min(surfaceWidth * 4 / 5, surfaceHeight * 4 / 5); final int frameSize = Math.max(MIN_FRAME_SIZE, Math.min(MAX_FRAME_SIZE, rawSize)); final int leftOffset = (surfaceWidth - frameSize) / 2; final int topOffset = (surfaceHeight - frameSize) / 2; frame = new Rect(leftOffset, topOffset, leftOffset + frameSize, topOffset + frameSize); framePreview = new Rect(frame.left * cameraResolution.height / surfaceWidth, frame.top * cameraResolution.width / surfaceHeight, frame.right * cameraResolution.height / surfaceWidth, frame.bottom * cameraResolution.width / surfaceHeight); final String savedParameters = parameters == null ? null : parameters .flatten(); try { setDesiredCameraParameters(camera, cameraResolution, continuousAutoFocus); } catch (final RuntimeException x) { if (savedParameters != null) { final Camera.Parameters parameters2 = camera.getParameters(); parameters2.unflatten(savedParameters); try { camera.setParameters(parameters2); setDesiredCameraParameters(camera, cameraResolution, continuousAutoFocus); } catch (final RuntimeException x2) { log.info("problem setting camera parameters", x2); } } } camera.startPreview(); return camera; }
Example 11
Source File: HardwareScalerActivity.java From grafika with Apache License 2.0 | 4 votes |
@Override public void surfaceCreated(SurfaceHolder holder) { Log.d(TAG, "surfaceCreated holder=" + holder); // Grab the view's width. It's not available before now. Rect size = holder.getSurfaceFrame(); mFullViewWidth = size.width(); mFullViewHeight = size.height(); // Configure our fixed-size values. We want to configure it so that the narrowest // dimension (e.g. width when device is in portrait orientation) is equal to the // value in SURFACE_DIM, and the other dimension is sized to maintain the same // aspect ratio. float windowAspect = (float) mFullViewHeight / (float) mFullViewWidth; for (int i = 0; i < SURFACE_DIM.length; i++) { if (i == SURFACE_SIZE_FULL) { // special-case for full size mWindowWidthHeight[i][0] = mFullViewWidth; mWindowWidthHeight[i][1] = mFullViewHeight; } else if (mFullViewWidth < mFullViewHeight) { // portrait mWindowWidthHeight[i][0] = SURFACE_DIM[i]; mWindowWidthHeight[i][1] = (int) (SURFACE_DIM[i] * windowAspect); } else { // landscape mWindowWidthHeight[i][0] = (int) (SURFACE_DIM[i] / windowAspect); mWindowWidthHeight[i][1] = SURFACE_DIM[i]; } } // Some controls include text based on the view dimensions, so update now. updateControls(); SurfaceView sv = (SurfaceView) findViewById(R.id.hardwareScaler_surfaceView); mRenderThread = new RenderThread(sv.getHolder()); mRenderThread.setName("HardwareScaler GL render"); mRenderThread.start(); mRenderThread.waitUntilReady(); RenderHandler rh = mRenderThread.getHandler(); if (rh != null) { rh.sendSetFlatShading(mFlatShadingChecked); rh.sendSurfaceCreated(); } // start the draw events Choreographer.getInstance().postFrameCallback(this); }