Java Code Examples for android.view.SurfaceHolder#Callback

The following examples show how to use android.view.SurfaceHolder#Callback . 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: FullscreenVideoView.java    From fullscreen-video-view with Apache License 2.0 6 votes vote down vote up
private void setUpSurfaceHolder() {
    if (surfaceView != null) {
        surfaceHolderCallback = new SurfaceHolder.Callback() {
            @Override
            public void surfaceCreated(SurfaceHolder holder) {
                if (fullscreenVideoMediaPlayer != null) {
                    fullscreenVideoMediaPlayer.setDisplay(surfaceHolder);
                }
            }

            @Override
            public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
            }

            @Override
            public void surfaceDestroyed(SurfaceHolder holder) {
                if (fullscreenVideoMediaPlayer != null && isMediaPlayerPrepared) {
                    fullscreenVideoMediaPlayer.pause();
                }
            }
        };
        surfaceHolder = surfaceView.getHolder();
        surfaceHolder.addCallback(surfaceHolderCallback);
    }
}
 
Example 2
Source File: AutoFitSurfaceView.java    From sandriosCamera with MIT License 5 votes vote down vote up
public AutoFitSurfaceView(@NonNull Context context, SurfaceHolder.Callback callback) {
    super(context);

    this.surfaceHolder = getHolder();

    this.surfaceHolder.addCallback(callback);
    this.surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
 
Example 3
Source File: VideoStream.java    From VideoMeeting with Apache License 2.0 5 votes vote down vote up
public synchronized void setSurfaceView(SurfaceView view) {
        mSurfaceView = view;
        if (mSurfaceHolderCallback != null && mSurfaceView != null && mSurfaceView.getHolder() != null) {
            mSurfaceView.getHolder().removeCallback(mSurfaceHolderCallback);
        }
        if (mSurfaceView != null && mSurfaceView.getHolder() != null) {
            mSurfaceHolderCallback = new SurfaceHolder.Callback() {
                @Override
                public void surfaceDestroyed(SurfaceHolder holder) {
//                    mSurfaceReady = false;
                    stopPreview();
                    L.d("Surface destroyed !");
                }

                @Override
                public void surfaceCreated(SurfaceHolder holder) {
//                    mSurfaceReady = true;
                    createCamera(holder);
                    startPreview();
                }

                @Override
                public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
                    L.d("Surface Changed !");
                }
            };
            mSurfaceView.getHolder().addCallback(mSurfaceHolderCallback);
//            mSurfaceReady = true;
        }
    }
 
Example 4
Source File: WallpaperService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
void reportSurfaceDestroyed() {
    if (mSurfaceCreated) {
        mSurfaceCreated = false;
        mSurfaceHolder.ungetCallbacks();
        SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks();
        if (callbacks != null) {
            for (SurfaceHolder.Callback c : callbacks) {
                c.surfaceDestroyed(mSurfaceHolder);
            }
        }
        if (DEBUG) Log.v(TAG, "onSurfaceDestroyed("
                + mSurfaceHolder + "): " + this);
        onSurfaceDestroyed(mSurfaceHolder);
    }
}
 
Example 5
Source File: Camera1Manager.java    From sandriosCamera with MIT License 5 votes vote down vote up
@Override
public void openCamera(final Integer cameraId,
                       final CameraOpenListener<Integer, SurfaceHolder.Callback> cameraOpenListener) {
    this.currentCameraId = cameraId;
    backgroundHandler.post(new Runnable() {
        @Override
        public void run() {
            try {
                camera = Camera.open(cameraId);
                prepareCameraOutputs();
                if (cameraOpenListener != null) {
                    uiHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            cameraOpenListener.onCameraOpened(cameraId, previewSize, currentInstance);
                        }
                    });
                }
            } catch (Exception error) {
                Log.d(TAG, "Can't open camera: " + error.getMessage());
                if (cameraOpenListener != null) {
                    uiHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            cameraOpenListener.onCameraOpenError();
                        }
                    });
                }
            }
        }
    });
}
 
Example 6
Source File: AutoFitSurfaceView.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public AutoFitSurfaceView(@NonNull Context context, SurfaceHolder.Callback callback) {
    super(context);

    this.surfaceHolder = getHolder();

    this.surfaceHolder.addCallback(callback);
    this.surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
 
Example 7
Source File: AutoFitSurfaceView.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public AutoFitSurfaceView(@NonNull Context context, SurfaceHolder.Callback callback) {
    super(context);

    this.surfaceHolder = getHolder();

    this.surfaceHolder.addCallback(callback);
    this.surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
 
Example 8
Source File: Camera1Controller.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@Override
public void onCameraOpened(Integer cameraId, Size previewSize, SurfaceHolder.Callback surfaceCallback) {
    cameraView.updateUiForMediaAction(configurationProvider.getMediaAction());
    cameraView.updateCameraPreview(previewSize, new AutoFitSurfaceView(context, surfaceCallback));
    cameraView.updateCameraSwitcher(getNumberOfCameras());
}
 
Example 9
Source File: Camera2ControllerAPI24.java    From sandriosCamera with MIT License 4 votes vote down vote up
@Override
public void onCameraOpened(Integer openedCameraId, Size previewSize, SurfaceHolder.Callback surfaceTextureListener) {
    cameraView.updateUiForMediaAction(CameraConfiguration.MEDIA_ACTION_BOTH);
    cameraView.updateCameraPreview(previewSize, new AutoFitSurfaceView(cameraView.getActivity(), surfaceTextureListener));
    cameraView.updateCameraSwitcher(camera2Manager.getNumberOfCameras());
}
 
Example 10
Source File: Camera1Controller.java    From sandriosCamera with MIT License 4 votes vote down vote up
@Override
public void onCameraOpened(Integer cameraId, Size previewSize, SurfaceHolder.Callback surfaceCallback) {
    cameraView.updateUiForMediaAction(configurationProvider.getMediaAction());
    cameraView.updateCameraPreview(previewSize, new AutoFitSurfaceView(cameraView.getActivity(), surfaceCallback));
    cameraView.updateCameraSwitcher(getNumberOfCameras());
}
 
Example 11
Source File: MjpegViewDefault.java    From octoandroid with GNU General Public License v3.0 4 votes vote down vote up
MjpegViewDefault(SurfaceView surfaceView, SurfaceHolder.Callback callback) {
    this.mSurfaceView = surfaceView;
    this.mSurfaceHolderCallback = callback;
    init();
}
 
Example 12
Source File: Camera1Lifecycle.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@Override
public void onCameraOpened(Integer cameraId, Size previewSize, SurfaceHolder.Callback surfaceCallback) {
    mCameraView.updateUiForMediaAction(mCameraConfigProvider.getMediaAction());
    mCameraView.updateCameraPreview(previewSize, new AutoFitSurfaceView(mContext, surfaceCallback));
    mCameraView.updateCameraSwitcher(getNumberOfCameras());
}
 
Example 13
Source File: ChronometerDrawerTest.java    From PTVGlass with MIT License 4 votes vote down vote up
@Override
public void addCallback(SurfaceHolder.Callback callback) {
    // Nothing to do here.
}
 
Example 14
Source File: ChronometerDrawerTest.java    From PTVGlass with MIT License 4 votes vote down vote up
@Override
public void removeCallback(SurfaceHolder.Callback callback) {
    // Nothing to do here.
}
 
Example 15
Source File: TimerDrawerTest.java    From PTVGlass with MIT License 4 votes vote down vote up
@Override
public void addCallback(SurfaceHolder.Callback callback) {
    // Nothing to do here.
}
 
Example 16
Source File: TimerDrawerTest.java    From PTVGlass with MIT License 4 votes vote down vote up
@Override
public void removeCallback(SurfaceHolder.Callback callback) {
    // Nothing to do here.
}
 
Example 17
Source File: TimerDrawerTest.java    From gdk-timer-sample with Apache License 2.0 4 votes vote down vote up
@Override
public void addCallback(SurfaceHolder.Callback callback) {
    // Nothing to do here.
}
 
Example 18
Source File: TimerDrawerTest.java    From gdk-timer-sample with Apache License 2.0 4 votes vote down vote up
@Override
public void removeCallback(SurfaceHolder.Callback callback) {
    // Nothing to do here.
}