GithubHelp home page GithubHelp logo

android / media-samples Goto Github PK

View Code? Open in Web Editor NEW
1.3K 112.0 738.0 12 MB

Multiple samples showing the best practices in media APIs on Android (audio, video, etc.).

License: Apache License 2.0

Java 88.62% Kotlin 11.38%

media-samples's Introduction

Android Media Samples Repository

This repository contains a set of individual Android Studio projects to help you get started writing/understanding Android Media (audio, video, etc.).

media-samples's People

Contributors

alabiaga avatar axelnennker avatar chickenbane avatar codingjeremy avatar d00mch avatar dturner avatar jrtberlin avatar nic0lette avatar owahltinez avatar tjohns avatar wquasar avatar yaraki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

media-samples's Issues

Need camera permission

11-24 16:19:54.603 18488-26881/com.example.android.mediarecorder E/AndroidRuntime: FATAL EXCEPTION: AsyncTask android/android-MediaRecorder#1
                                                                                   Process: com.example.android.mediarecorder, PID: 18488
                                                                                   java.lang.RuntimeException: An error occurred while executing doInBackground()
                                                                                       at android.os.AsyncTask$3.done(AsyncTask.java:318)
                                                                                       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
                                                                                       at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
                                                                                       at java.util.concurrent.FutureTask.run(FutureTask.java:242)
                                                                                       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
                                                                                       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
                                                                                       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
                                                                                       at java.lang.Thread.run(Thread.java:762)
                                                                                    Caused by: java.lang.RuntimeException: Fail to connect to camera service
                                                                                       at android.hardware.Camera.<init>(Camera.java:519)
                                                                                       at android.hardware.Camera.open(Camera.java:379)
                                                                                       at com.example.android.common.media.CameraHelper.getDefaultCameraInstance(CameraHelper.java:103)
                                                                                       at com.example.android.mediarecorder.MainActivity.prepareVideoRecorder(MainActivity.java:142)
                                                                                       at com.example.android.mediarecorder.MainActivity.access$000(MainActivity.java:44)
                                                                                       at com.example.android.mediarecorder.MainActivity$MediaPrepareTask.doInBackground(MainActivity.java:218)
                                                                                       at com.example.android.mediarecorder.MainActivity$MediaPrepareTask.doInBackground(MainActivity.java:213)
                                                                                       at android.os.AsyncTask$2.call(AsyncTask.java:304)
                                                                                       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                                       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243) 
                                                                                       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
                                                                                       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
                                                                                       at java.lang.Thread.run(Thread.java:762) 

set remotAction on pip mode to mute and unMute

Hi
I tried to set remotaction for adding button to mute and on mute the player on pip mode but the problem is it just work and change the icon when the player state changed . is it possible to add button beside of play button on pip mode to mute and unmute player? (I mean instead of show info button ) .
Thanks in advance

960 fps super slow motion

Currently is it possible to record 960 fps super slow motion video on such phones as Galaxy 9 or Sony Xperia If I modify this android-MediaRecorder example ?

setPictureInPictureArgs: Device doesn't support picture-in-picture mode.

Can not run this sample on Android emulator (API O , Target Android 7+ Google API).
the exception is,

 java.lang.IllegalStateException: setPictureInPictureArgs: Device doesn't support picture-in-picture mode.
           at android.os.Parcel.readException(Parcel.java:1923)
           at android.os.Parcel.readException(Parcel.java:1861)
           at android.app.IActivityManager$Stub$Proxy.setPictureInPictureArgs(IActivityManager.java:9378)
           at android.app.Activity.setPictureInPictureArgs(Activity.java:1984)
           at com.example.pip.MainActivity.updatePictureInPictureActions(MainActivity.java:156)
           at com.example.pip.MainActivity$2.onMovieStarted(MainActivity.java:101)
           at com.example.pip.widget.MovieView.play(MovieView.java:350)
           at com.example.pip.widget.MovieView$3.onPrepared(MovieView.java:384)
           at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:3170)
           at android.os.Handler.dispatchMessage(Handler.java:102)
           at android.os.Looper.loop(Looper.java:156)
           at android.app.ActivityThread.main(ActivityThread.java:6440)
           at java.lang.reflect.Method.invoke(Native Method)
           at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:746)

No option for the set video from the url

I think PIP features come before 2 year. And this is google official sample code but this code is not updated from the last 2 year.

Second thing i found that This sample show PIP mode using raw folder video. Mostly now a day people work with live video url. So, as per that google need to update this demo app for both raw and url base PIP mode.

There is no any property to set video from url instead of raw folder.

Can you please update this, if this update then it very useful to so many people.

Camera onpreviewframe is not called

While recording, the camera's previewcallbacks aren't called anymore. Is there any solution to keep the callbacks running while recording video? Thanks in advance.

Receiving lots of IllegalStateException from Play Store Users.

IllegalStateException
MediaButtonReceiver.onReceive
Report 1 of 10
java.lang.RuntimeException:
at android.app.ActivityThread.handleReceiver (ActivityThread.java:3399)
at android.app.ActivityThread.-wrapl 8 (Unknown Source:0)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1780)
at android.os.Handler.dispatchMessage (Handlerjaval 05)
at android.os.Looper.loop (Looper.java:164)
at android.app.ActivityThread.main (ActivityThread.java:6942)
at java.lang.reflect.Method.invoke (Native Method:0)
at com.android.internal.os.Zygote$MethodAndArgsCaller. run
(Zygote.java:327)
at com.android.internal.os.Zygotelnit.main (Zygotelnit.javal 374)
Caused by: java.Iang.IllegalStateException:
at android.support.v4.media.session.MediaButtonReceiver.onReceive
(Unknown Source:76)
at android.app.ActivityThread.handieReceiver (ActivityThread.java:3392)

Orientation change

I commented out android:screenOrientation="landscape" from the MainActivity declaration in the AndroidManifest.xml, but it doesn't look like it supports orientation change. How can you continue playback from where you left off while doing an orientation change?

record from rtsp

Is it possible to modify the code to make sure that instead of recording from the camera it always registers from a rtsp on the TextureView?

Exit PIP

How do I exit PIP on swipe left or right? Also how do i render the original activity layout on swipe up as we see in netflix?

MediaRouteProvider Not visible in Wifi network

MediaRouteProvider created in this sample is visible in the same device to other apps but its not visible to apps on other device. Can you please help us to get MediaRouteProvider visible in wifi network. Not so sure if I should have posted this in StackOverFlow

How to show video recording preview?

Here we can see a camera preview after start recording. I want to show a camera preview before start recording.

By default, camera preview should be visible and recording should be started when press start button.

Is it possible?

Media Recorder with HEVC encoding

Hello,

When I set videoEndoderto HEVC mediarecorder.start() is not working below is the exception. Kindly let me know the reason or whats going wrong.

{

    // BEGIN_INCLUDE (configure_preview)
    mCamera = CameraHelper.getDefaultCameraInstance();

    // We need to make sure that our preview and recording video size are supported by the
    // camera. Query camera to find all the sizes and choose the optimal size given the
    // dimensions of our preview surface.
    Camera.Parameters parameters = mCamera.getParameters();
    List<Camera.Size> mSupportedPreviewSizes = parameters.getSupportedPreviewSizes();
    List<Camera.Size> mSupportedVideoSizes = parameters.getSupportedVideoSizes();
    Camera.Size optimalSize = CameraHelper.getOptimalVideoSize(mSupportedVideoSizes,
            mSupportedPreviewSizes, mPreview.getWidth(), mPreview.getHeight());

    // Use the same size for recording profile.
    CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
    profile.videoFrameWidth = optimalSize.width;
    profile.videoFrameHeight = optimalSize.height;

    // likewise for the camera object itself.
    parameters.setPreviewSize(profile.videoFrameWidth, profile.videoFrameHeight);
    mCamera.setParameters(parameters);
    try {
            // Requires API level 11+, For backward compatibility use {@link setPreviewDisplay}
            // with {@link SurfaceView}
            mCamera.setPreviewTexture(mPreview.getSurfaceTexture());
    } catch (IOException e) {
        Log.e(TAG, "Surface texture is unavailable or unsuitable" + e.getMessage());
        return false;
    }
    // END_INCLUDE (configure_preview)


    // BEGIN_INCLUDE (configure_media_recorder)
    mMediaRecorder = new MediaRecorder();

    // Step 1: Unlock and set camera to MediaRecorder
    mCamera.unlock();
    mMediaRecorder.setCamera(mCamera);

    // Step 2: Set sources
    mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT );
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    mMediaRecorder.setVideoSize(1280,720);
    mMediaRecorder.setVideoEncodingBitRate(1500);
    mMediaRecorder.setVideoFrameRate(30);
    mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.HEVC);
    mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
    // Step 3: Set a CamcorderProfile (requires API Level 8 or higher)

// mMediaRecorder.setProfile(profile);

    // Step 4: Set output file
    mOutputFile = CameraHelper.getOutputMediaFile(CameraHelper.MEDIA_TYPE_VIDEO);
    if (mOutputFile == null) {
        return false;
    }
    mMediaRecorder.setOutputFile(mOutputFile.getPath());



    // END_INCLUDE (configure_media_recorder)

    // Step 5: Prepare configured MediaRecorder
    try {
        mMediaRecorder.prepare();
    } catch (IllegalStateException e) {
        Log.d(TAG, "IllegalStateException preparing MediaRecorder: " + e.getMessage());
        releaseMediaRecorder();
        return false;
    } catch (IOException e) {
        Log.d(TAG, "IOException preparing MediaRecorder: " + e.getMessage());
        releaseMediaRecorder();
        return false;
    }
    return true;

}
Exceptions

D/vndksupport: Loading /vendor/lib/hw/gralloc.msm8974.so from current namespace instead of sphal namespace.
07-02 17:34:19.078 24853-24889/com.example.android.mediarecorder D/vndksupport: Loading /vendor/lib/hw/[email protected] from current namespace instead of sphal namespace.
07-02 17:34:19.080 24853-24889/com.example.android.mediarecorder D/vndksupport: Loading /vendor/lib/hw/gralloc.msm8974.so from current namespace instead of sphal namespace.
07-02 17:34:20.585 24853-24897/com.example.android.mediarecorder E/MediaRecorder: start failed: -2147483648
07-02 17:34:20.592 24853-24897/com.example.android.mediarecorder E/AndroidRuntime: FATAL EXCEPTION: AsyncTask googlearchive/android-MediaRecorder#1
Process: com.example.android.mediarecorder, PID: 24853
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:353)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.RuntimeException: start failed.
at android.media.MediaRecorder.start(Native Method)
at com.example.android.mediarecorder.MainActivity$MediaPrepareTask.doInBackground(MainActivity.java:226)
at com.example.android.mediarecorder.MainActivity$MediaPrepareTask.doInBackground(MainActivity.java:218)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 
at java.lang.Thread.run(Thread.java:764) 

project doesn't work properly

this project does a capture screen but it shows them (many capture screens) on a surfaceview.
the question is can I get this screenshot and save ot as a png ?
I need only one screenshot

Failed to start presentation mode.

The app works usually for the very first time. It fails easily with the following steps:

  1. run the app successfully for the first time, presentation display on the second display, HDMI TV;

  2. from Android system bar, select square to see all app in memory, then click "CLEAR ALL" to kill all;

  3. run the app again, presentation fails. TV mirrors the LCD screen of android.

  4. Press square button on system bar again, then click the app again. It can recover.

The log shows massive errors repeatedly for 180 times per second.

On Android API 25. It doesn't happen every time but often enough.

07-09 22:54:49.013 1414 1533 E WindowManager: Unhandled exception in Window Manager
07-09 22:54:49.013 1414 1533 E WindowManager: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.DisplayInfo com.android.server.wm.DisplayContent.getDisplayInfo()' on a null object reference
07-09 22:54:49.013 1414 1533 E WindowManager: at com.android.server.wm.Task.getDisplayInfo(Task.java:766)
07-09 22:54:49.013 1414 1533 E WindowManager: at com.android.server.wm.DimLayer.getBoundsForFullscreen(DimLayer.java:209)
07-09 22:54:49.013 1414 1533 E WindowManager: at com.android.server.wm.DimLayer.setBoundsForFullscreen(DimLayer.java:221)
07-09 22:54:49.013 1414 1533 E WindowManager: at com.android.server.wm.DimLayerController.updateDimLayer(DimLayerController.java:60)
07-09 22:54:49.013 1414 1533 E WindowManager: at com.android.server.wm.WindowSurfacePlacer.performLayoutLockedInner(WindowSurfacePlacer.java:1003)
07-09 22:54:49.013 1414 1533 E WindowManager: at com.android.server.wm.WindowSurfacePlacer.applySurfaceChangesTransaction(WindowSurfacePlacer.java:656)
07-09 22:54:49.013 1414 1533 E WindowManager: at com.android.server.wm.WindowSurfacePlacer.performSurfacePlacementInner(WindowSurfacePlacer.java:321)
07-09 22:54:49.013 1414 1533 E WindowManager: at com.android.server.wm.WindowSurfacePlacer.performSurfacePlacementLoop(WindowSurfacePlacer.java:236)
07-09 22:54:49.013 1414 1533 E WindowManager: at com.android.server.wm.WindowSurfacePlacer.performSurfacePlacement(WindowSurfacePlacer.java:184)
07-09 22:54:49.013 1414 1533 E WindowManager: at com.android.server.wm.WindowManagerService$H.handleMessage(WindowManagerService.java:8393)
07-09 22:54:49.013 1414 1533 E WindowManager: at android.os.Handler.dispatchMessage(Handler.java:102)
07-09 22:54:49.013 1414 1533 E WindowManager: at android.os.Looper.loop(Looper.java:154)
07-09 22:54:49.013 1414 1533 E WindowManager: at android.os.HandlerThread.run(HandlerThread.java:61)
07-09 22:54:49.013 1414 1533 E WindowManager: at com.android.server.ServiceThread.run(ServiceThread.java:46)
07-09 22:54:49.016 1414 1533 E WindowManager: Unhandled exception in Window Manager

MediaRecorder second time recoriding prepare failed w/ Camera2

I have been struggling for some time now on why I am not able to record for a second time with MediaRecorder. Every time I try it says:

Caused by: java.io.IOException: prepare failed.

I am not sure what I am doing wrong and frankly I have been staring at this for too long. I am doing this in Kotlin, but for the most part it is the same as Java with the exception of the function syntax. Please can anyone help? I have looked at others and the camera2 and mediarecorder being implemented, but it isn't working.

private val cameraCaptureCallback = object : CameraCaptureSession.CaptureCallback() {

    private fun process(result: CaptureResult){
        when(cameraState) {
            STATE_PREVIEW -> {}

            STATE_WAITING_LOCK -> {
                val afState = result.get(CaptureResult.CONTROL_AF_STATE)

                if(afState == null){
                    captureImage()

                } else if(CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED == afState
                        || CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED == afState){
                    val aeState = result.get(CaptureResult.CONTROL_AE_STATE)

                    if(aeState == null
                            || aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED){
                        cameraState = STATE_PICTURE_TAKEN
                        captureImage()
                    } else {
                        runPrecaptureSequence()
                    }
                }
            }

            STATE_WAITING_PRECAPTURE -> {
                val aeState = result.get(CaptureResult.CONTROL_AE_STATE)

                if(aeState == null
                        || aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE
                        || aeState == CaptureResult.CONTROL_AE_STATE_FLASH_REQUIRED) {
                    cameraState = STATE_WAITING_NON_PRECAPTURE
                }
            }

            STATE_WAITING_NON_PRECAPTURE -> {
                val aeState = result.get(CaptureResult.CONTROL_AE_STATE)

                if(aeState == null
                        || aeState != CaptureResult.CONTROL_AE_STATE_PRECAPTURE) {
                    cameraState = STATE_PICTURE_TAKEN
                    captureImage()
                }
            }

        }
    }

    override fun onCaptureProgressed(session: CameraCaptureSession?, request: CaptureRequest?, partialResult: CaptureResult?) {
        process(partialResult!!)
    }

    override fun onCaptureCompleted(session: CameraCaptureSession?, request: CaptureRequest?, result: TotalCaptureResult?) {
        process(result!!)
    }
}

private val cameraStateCallback = object : CameraDevice.StateCallback() {
    override fun onOpened(camera: CameraDevice) {
        cameraDevice = camera
        createCameraPreview()
    }

    override fun onDisconnected(camera: CameraDevice) {
        camera.close()
        cameraDevice = null
    }

    override fun onError(camera: CameraDevice, error: Int) {
        camera.close()
        cameraDevice = null

        if(activity != null)
            activity.finish()
    }
}

private val textureListener: TextureView.SurfaceTextureListener = object : TextureView.SurfaceTextureListener {
    override fun onSurfaceTextureAvailable(surface: SurfaceTexture, width: Int, height: Int) {
        //open your camera here
        setupCamera(width, height)
    }

    override fun onSurfaceTextureSizeChanged(surface: SurfaceTexture, width: Int, height: Int) {

    }

    override fun onSurfaceTextureDestroyed(surface: SurfaceTexture): Boolean {

        return true
    }

    override fun onSurfaceTextureUpdated(surface: SurfaceTexture) {}
}

private val previewTextureListener: TextureView.SurfaceTextureListener = object : TextureView.SurfaceTextureListener {
    override fun onSurfaceTextureAvailable(surface: SurfaceTexture?, width: Int, height: Int) {
        try {
            if(contentCaptured == "video"){
                previewNewPostVideoMediaPlayer = MediaPlayer()
                previewNewPostVideoMediaPlayer?.setDataSource(videoFile?.absolutePath)
                previewNewPostVideoMediaPlayer?.setSurface(Surface(surface))
                previewNewPostVideoMediaPlayer?.prepare()

                previewNewPostVideoMediaPlayer?.start()
            }


        } catch (e: IllegalArgumentException ) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (e: SecurityException ) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (e: IllegalStateException ) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (e: IOException) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    override fun onSurfaceTextureSizeChanged(p0: SurfaceTexture?, p1: Int, p2: Int) {
    }

    override fun onSurfaceTextureUpdated(surfaceTexture: SurfaceTexture?) {
    }

    override fun onSurfaceTextureDestroyed(p0: SurfaceTexture?): Boolean {
        return true
    }
}

private fun createCameraPreview() {

    if (cameraDevice == null || !cameraTextureView?.isAvailable!! || cameraPreviewDimension == null) {
        return
    }

    try {
        var texture: SurfaceTexture = cameraTextureView!!.surfaceTexture
        texture.setDefaultBufferSize(cameraPreviewDimension!!.width, cameraPreviewDimension!!.height)

        var surfaces: MutableList<Surface> = ArrayList()

        captureRequestBuilder = cameraDevice?.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW)
        captureRequestBuilder?.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO)

        var surface = Surface(texture)
        captureRequestBuilder?.addTarget(surface)
        surfaces.add(surface)
        surfaces.add(cameraPreviewImageReader?.surface!!)

        cameraDevice?.createCaptureSession(surfaces, object : CameraCaptureSession.StateCallback() {
            override fun onConfigured(session: CameraCaptureSession?) {
                if (cameraDevice == null) {
                    return
                }

                try {
                    cameraCaptureSession = session
                    cameraCaptureSession?.setRepeatingRequest(captureRequestBuilder?.build(), null, mBackgroundHandler)
                } catch (e: CameraAccessException){
                    e.printStackTrace()
                }
            }

            override fun onConfigureFailed(cameraCaptureSession: CameraCaptureSession?) {
                Log.e("Configuration session", "camera capture session failed in create preview")
            }

        }, mBackgroundHandler)
    } catch(e: CameraAccessException) {
        e.printStackTrace()
    }
}

private fun createCameraOutput(width: Int, height: Int){
    var cameraManager: CameraManager = activity.getSystemService(Context.CAMERA_SERVICE) as CameraManager

    try {
        var cameraId = cameraManager.cameraIdList[0]
        var cameraChars: CameraCharacteristics? = cameraManager.getCameraCharacteristics(cameraId)
        var map: StreamConfigurationMap = cameraChars?.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP)!!
        var max: Size = map.getOutputSizes(ImageFormat.JPEG)[0]

        imageFile = createImageFile()
        cameraPreviewImageReader = ImageReader.newInstance(max.width, max.height, ImageFormat.JPEG, 2)
        cameraPreviewImageReader?.setOnImageAvailableListener(OnImageAvailableListener, mBackgroundHandler)

        videoSize = map.getOutputSizes(SurfaceTexture::class.java)[0]
        cameraPreviewDimension = map.getOutputSizes(SurfaceTexture::class.java)[0]

        videoTextureView?.setAspectRatio(cameraPreviewDimension?.height!!, cameraPreviewDimension?.width!!)
        cameraTextureView?.setAspectRatio(cameraPreviewDimension?.height!!, cameraPreviewDimension?.width!!)
        configureTransform(width, height)

        var available: Boolean = cameraChars.get(CameraCharacteristics.FLASH_INFO_AVAILABLE)
        mFlashSupported = available == null ?: available
        cameraDeviceId = cameraId
    } catch(e: CameraAccessException) {
        e.printStackTrace()
    }
}

private fun setupCamera(width: Int, height: Int) {
    if(ActivityCompat.checkSelfPermission(context, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

        var mainActivity = activity as MainActivity

        ActivityCompat.requestPermissions(mainActivity!!, arrayOf(Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE), REQUEST_CAMERA_PERMISSION)
        return
    }

    var cameraManager: CameraManager = activity.getSystemService(Context.CAMERA_SERVICE) as CameraManager
    createCameraOutput(width, height)

    try {
        cameraManager.openCamera(cameraDeviceId, cameraStateCallback, null)

        cameraPreviewFrameLayout?.setOnTouchListener(OnCameraFeaturesListener)
    }  catch (e: CameraAccessException) {
        e.printStackTrace()
    }  catch (e: InterruptedException) {
        throw RuntimeException("Interrupted while trying to lock camera opening.", e);
    }
}

private fun updateCameraPreview() {
    if(cameraDevice == null) {
        return
    }

    try {
        cameraCaptureSession?.setRepeatingRequest(captureRequestBuilder?.build(), cameraCaptureCallback, mBackgroundHandler)
    } catch(e: CameraAccessException) {
        e.printStackTrace()
    }
}

private fun takePicture(){
    initFocus()
}

private fun initFocus(){
    try {
        captureRequestBuilder?.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START)

        cameraState = STATE_WAITING_LOCK
        cameraCaptureSession?.capture(captureRequestBuilder?.build(), cameraCaptureCallback, mBackgroundHandler)
    } catch (e: CameraAccessException) {
        e.printStackTrace()

    }
}

private fun releaseFocus(){
    try {
        captureRequestBuilder?.set(CaptureRequest.CONTROL_AF_TRIGGER,
                CameraMetadata.CONTROL_AF_TRIGGER_CANCEL)

        cameraCaptureSession?.capture(captureRequestBuilder?.build(), null, mBackgroundHandler)
        cameraState = STATE_PREVIEW
        cameraCaptureSession?.setRepeatingRequest(captureRequestBuilder?.build(), cameraCaptureCallback, mBackgroundHandler)
    } catch (e: CameraAccessException ) {
        e.printStackTrace()
    }
}

private fun runPrecaptureSequence() {
    try {
        captureRequestBuilder?.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
                CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START)
        cameraState = STATE_WAITING_PRECAPTURE;
        cameraCaptureSession?.capture(captureRequestBuilder?.build(), cameraCaptureCallback,
                mBackgroundHandler)
    } catch (e: CameraAccessException ) {
        e.printStackTrace()
    }
}

private fun captureImage() {
    if(cameraDevice == null){
        return
    }

    try {
        var tempCaptureBuilder: CaptureRequest.Builder = cameraDevice?.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE)!!
        tempCaptureBuilder.addTarget(cameraPreviewImageReader?.surface!!)

        var camManager: CameraManager = context.getSystemService(Context.CAMERA_SERVICE) as CameraManager
        var camChars: CameraCharacteristics = camManager.getCameraCharacteristics(cameraDevice?.id)

        var rotation: Int = activity.windowManager.defaultDisplay.rotation
        var actualRotation = getJpegOrientation(camChars, rotation)

        tempCaptureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(actualRotation))

        var tempCallback = object: CameraCaptureSession.CaptureCallback() {
            override fun onCaptureCompleted(session: CameraCaptureSession?, request: CaptureRequest?, result: TotalCaptureResult?) {
                releaseFocus()
            }
        }

        cameraCaptureSession?.capture(tempCaptureBuilder.build(), tempCallback, null)
}


private fun setupRecorder() {
    try {
        videoFile = createVideoFile()
        videoPath = videoFile?.path
    } catch (e: IOException) {
        e.printStackTrace()
    }

    if(mediaRecorder == null) {
        mediaRecorder = MediaRecorder()
    }

    mediaRecorder?.setAudioSource(MediaRecorder.AudioSource.MIC)
    mediaRecorder?.setVideoSource(MediaRecorder.VideoSource.SURFACE)
    mediaRecorder?.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
    mediaRecorder?.setVideoEncoder(MediaRecorder.VideoEncoder.H264)
    mediaRecorder?.setAudioEncoder(MediaRecorder.AudioEncoder.AAC)
    mediaRecorder?.setOutputFile(videoPath)
    mediaRecorder?.setVideoSize(videoSize?.width!!, videoSize?.height!!)
    mediaRecorder?.setVideoFrameRate(30)
    mediaRecorder?.setVideoEncodingBitRate(10000000)
    mediaRecorder?.setOrientationHint(90)

}

private fun startRecordingVideo() {
    if(cameraDevice == null || cameraPreviewDimension == null || !cameraTextureView?.isAvailable!!) {
        return
    }

    try {
        closeCameraSession()
        setupRecorder()

        mediaRecorder?.prepare()

        var texture = cameraTextureView?.surfaceTexture

        texture?.setDefaultBufferSize(cameraPreviewDimension?.width!!, cameraPreviewDimension?.height!!)
        captureRequestBuilder = cameraDevice?.createCaptureRequest(CameraDevice.TEMPLATE_RECORD)

        captureRequestBuilder?.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_VIDEO)
        captureRequestBuilder?.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON)

        var surfaces: MutableList<Surface> = ArrayList()
        var previewSurface = Surface(texture)
        var recorderSurface = mediaRecorder?.surface!!

        Log.i("media recorder",mediaRecorder?.surface!!.toString())
        var imageReaderSurface = cameraPreviewImageReader?.surface!!

        surfaces.add(previewSurface)
        surfaces.add(recorderSurface)
        captureRequestBuilder?.addTarget(recorderSurface)
        captureRequestBuilder?.addTarget(previewSurface)

        cameraDevice?.createCaptureSession(surfaces, object : CameraCaptureSession.StateCallback() {
            override fun onConfigured(session: CameraCaptureSession?) {
                recordCaptureSession = session
                try {
                    recordCaptureSession?.setRepeatingRequest(captureRequestBuilder?.build(), null, mBackgroundHandler)

                } catch(e: CameraAccessException){
                    e.printStackTrace()
                }

                activity.runOnUiThread {
                    mediaRecorder?.start()
                }

            }

            override fun onConfigureFailed(session: CameraCaptureSession?) {
                Log.e("capture session error","session error")
            }


        }, mBackgroundHandler)

    } catch(e: CameraAccessException){
        e.printStackTrace()
    }
}

private fun stopRecordingVideo() {
    recordCaptureSession?.stopRepeating()
    recordCaptureSession?.abortCaptures()
    createCameraPreview()
    if(mediaRecorder != null){

        try {

        } catch(e: CameraAccessException){
            e.printStackTrace()
        }
        mediaRecorder?.stop()
        mediaRecorder?.reset()

        mediaRecorder?.setAudioSource(MediaRecorder.AudioSource.MIC)
        mediaRecorder?.setVideoSource(MediaRecorder.VideoSource.SURFACE)
        mediaRecorder?.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
        mediaRecorder?.setVideoEncoder(MediaRecorder.VideoEncoder.H264)
        mediaRecorder?.setAudioEncoder(MediaRecorder.AudioEncoder.AAC)
        mediaRecorder?.setOutputFile(videoPath)
        mediaRecorder?.setVideoSize(videoSize?.width!!, videoSize?.height!!)
        mediaRecorder?.setVideoFrameRate(30)
        mediaRecorder?.setVideoEncodingBitRate(10000000)
        mediaRecorder?.setOrientationHint(90)

    }

}

private fun startBackgroundThread() {
    mBackgroundThread = HandlerThread("CameraBackground")
    mBackgroundThread?.start()

    mBackgroundHandler = Handler(mBackgroundThread?.looper)
}

private fun stopBackgroundThread() {
    mBackgroundThread?.quitSafely()

    try {
        mBackgroundThread?.join()
        mBackgroundThread = null
        mBackgroundHandler = null
    } catch(e: InterruptedException) {
        e.printStackTrace()
    }
}

private fun closeCamera() {
    try {
        if (cameraCaptureSession != null) {
            cameraCaptureSession?.close()
            cameraCaptureSession = null
        }

        if (cameraDevice != null) {
            cameraDevice?.close()
            cameraDevice = null
        }

        if(cameraPreviewImageReader != null){
            cameraPreviewImageReader?.close()
            cameraPreviewImageReader = null
        }

        if(mediaRecorder != null){
            mediaRecorder?.reset()
            mediaRecorder?.release()
            mediaRecorder = null
        }

    }  catch (e: InterruptedException) {
        throw RuntimeException("Interrupted while trying to lock camera closing.", e)
    }
}

}

Logcat:

11-28 01:13:43.162 31509-31509/ W/ArrayUtils: Ignoring invalid value emboss
11-28 01:13:43.162 31509-31509/ W/ArrayUtils: Ignoring invalid value sketch
11-28 01:13:43.162 31509-31509/ W/ArrayUtils: Ignoring invalid value neon
11-28 01:13:43.162 31509-31509/ W/ArrayUtils: Ignoring invalid value vintage-warm
11-28 01:13:43.162 31509-31509/ W/ArrayUtils: Ignoring invalid value vintage-cold
11-28 01:13:43.162 31509-31509/ W/ArrayUtils: Ignoring invalid value washed
11-28 01:13:43.162 31509-31509/ W/ArrayUtils: Ignoring invalid value asd
11-28 01:13:43.162 31509-31509/ W/ArrayUtils: Ignoring invalid value back-light
11-28 01:13:43.162 31509-31509/ W/ArrayUtils: Ignoring invalid value flowers
11-28 01:13:43.162 31509-31509/ W/ArrayUtils: Ignoring invalid value AR
11-28 01:13:43.162 31509-31509/ W/ArrayUtils: Ignoring invalid value text
11-28 01:13:43.162 31509-31509/ W/ArrayUtils: Ignoring invalid value fall-color
11-28 01:13:43.162 31509-31509/ W/ArrayUtils: Ignoring invalid value dusk-dawn
11-28 01:13:43.182 31509-31509/ I/Flash info: true
11-28 01:13:43.192 31509-31509/ W/ArrayUtils: Ignoring invalid value emboss
11-28 01:13:43.192 31509-31509/ W/ArrayUtils: Ignoring invalid value sketch
11-28 01:13:43.192 31509-31509/ W/ArrayUtils: Ignoring invalid value neon
11-28 01:13:43.192 31509-31509/ W/ArrayUtils: Ignoring invalid value vintage-warm
11-28 01:13:43.192 31509-31509/ W/ArrayUtils: Ignoring invalid value vintage-cold
11-28 01:13:43.192 31509-31509/ W/ArrayUtils: Ignoring invalid value washed
11-28 01:13:43.192 31509-31509/ W/ArrayUtils: Ignoring invalid value asd
11-28 01:13:43.192 31509-31509/ W/ArrayUtils: Ignoring invalid value back-light
11-28 01:13:43.192 31509-31509/ W/ArrayUtils: Ignoring invalid value flowers
11-28 01:13:43.192 31509-31509/ W/ArrayUtils: Ignoring invalid value AR
11-28 01:13:43.192 31509-31509/ W/ArrayUtils: Ignoring invalid value text
11-28 01:13:43.192 31509-31509/ W/ArrayUtils: Ignoring invalid value fall-color
11-28 01:13:43.192 31509-31509/ W/ArrayUtils: Ignoring invalid value dusk-dawn
11-28 01:13:43.192 31509-31509/ I/CameraManager: Using legacy camera HAL.
11-28 01:13:43.502 31509-31509/ W/ArrayUtils: Ignoring invalid value emboss
11-28 01:13:43.502 31509-31509/ W/ArrayUtils: Ignoring invalid value sketch
11-28 01:13:43.502 31509-31509/ W/ArrayUtils: Ignoring invalid value neon
11-28 01:13:43.502 31509-31509/ W/ArrayUtils: Ignoring invalid value vintage-warm
11-28 01:13:43.502 31509-31509/ W/ArrayUtils: Ignoring invalid value vintage-cold
11-28 01:13:43.502 31509-31509/ W/ArrayUtils: Ignoring invalid value washed
11-28 01:13:43.502 31509-31509/ W/ArrayUtils: Ignoring invalid value asd
11-28 01:13:43.502 31509-31509/ W/ArrayUtils: Ignoring invalid value back-light
11-28 01:13:43.502 31509-31509/ W/ArrayUtils: Ignoring invalid value flowers
11-28 01:13:43.502 31509-31509/ W/ArrayUtils: Ignoring invalid value AR
11-28 01:13:43.502 31509-31509/ W/ArrayUtils: Ignoring invalid value text
11-28 01:13:43.502 31509-31509/ W/ArrayUtils: Ignoring invalid value fall-color
11-28 01:13:43.502 31509-31509/ W/ArrayUtils: Ignoring invalid value dusk-dawn
11-28 01:13:43.512 31509-31509/ I/camera: camera has been opened
11-28 01:13:43.562 31509-31509/ I/CameraDeviceState: Legacy camera service transitioning to state CONFIGURING
11-28 01:13:43.572 31509-32334/ I/RequestThread-0: Configure outputs: 2 surfaces configured.
11-28 01:13:43.572 31509-32334/ D/Camera: app passed NULL surface
11-28 01:13:43.572 31509-32334/ I/RequestThread-0: configureOutputs - set take picture size to 4128x3096
11-28 01:13:43.612 31509-31509/ I/CameraDeviceState: Legacy camera service transitioning to state IDLE
11-28 01:13:43.612 31509-32305/ I/RequestQueue: Repeating capture request set.
11-28 01:13:43.612 31509-32334/ W/LegacyRequestMapper: convertRequestMetadata - control.awbRegions setting is not supported, ignoring value
11-28 01:13:43.612 31509-32334/ W/LegacyRequestMapper: Only received metering rectangles with weight 0.
11-28 01:13:44.353 31509-31520/ E/BufferQueueProducer: [unnamed-31509-2] dequeueBuffer: min undequeued buffer count (2) exceeded (dequeued=11 undequeued=0)
11-28 01:13:44.353 31509-32336/ I/CameraDeviceState: Legacy camera service transitioning to state CAPTURING
11-28 01:13:44.463 31509-31520/ E/BufferQueueProducer: [unnamed-31509-2] dequeueBuffer: min undequeued buffer count (2) exceeded (dequeued=10 undequeued=1)
11-28 01:13:45.794 31509-31509/ D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
11-28 01:13:46.315 31509-31509/ I/RequestQueue: Repeating capture request cancelled.
11-28 01:13:46.365 31509-32334/ I/CameraDeviceState: Legacy camera service transitioning to state IDLE
11-28 01:13:46.605 31509-31509/ I/media recorder: Surface(name=null)/@0x1a8c1cd2
11-28 01:13:46.615 31509-31509/ I/CameraDeviceState: Legacy camera service transitioning to state CONFIGURING
11-28 01:13:46.615 31509-32334/ I/RequestThread-0: Configure outputs: 2 surfaces configured.
11-28 01:13:46.795 31509-32334/ D/Camera: app passed NULL surface
11-28 01:13:46.845 31509-31509/ I/CameraDeviceState: Legacy camera service transitioning to state IDLE
11-28 01:13:46.845 31509-32305/ I/RequestQueue: Repeating capture request set.
11-28 01:13:46.855 31509-32334/ W/LegacyRequestMapper: convertRequestMetadata - control.awbRegions setting is not supported, ignoring value
11-28 01:13:46.855 31509-32334/ W/LegacyRequestMapper: Only received metering rectangles with weight 0.
11-28 01:13:47.916 31509-32336/ I/CameraDeviceState: Legacy camera service transitioning to state CAPTURING
11-28 01:13:47.926 31509-31520/ E/BufferQueueProducer: [unnamed-31509-3] dequeueBuffer: min undequeued buffer count (2) exceeded (dequeued=11 undequeued=0)
11-28 01:13:48.026 31509-31521/ E/BufferQueueProducer: [unnamed-31509-3] dequeueBuffer: min undequeued buffer count (2) exceeded (dequeued=10 undequeued=1)
11-28 01:13:52.080 31509-31509/ I/RequestQueue: Repeating capture request cancelled.
11-28 01:13:52.090 31509-32334/ I/CameraDeviceState: Legacy camera service transitioning to state IDLE
11-28 01:13:52.100 31509-31509/ I/CameraDeviceState: Legacy camera service transitioning to state CONFIGURING
11-28 01:13:52.110 31509-32334/ I/RequestThread-0: Configure outputs: 2 surfaces configured.
11-28 01:13:52.401 31509-32334/ D/Camera: app passed NULL surface
11-28 01:13:52.431 31509-32334/ I/RequestThread-0: configureOutputs - set take picture size to 4128x3096
11-28 01:13:52.501 31509-31509/ I/CameraDeviceState: Legacy camera service transitioning to state IDLE
11-28 01:13:52.501 31509-32305/ I/RequestQueue: Repeating capture request set.
11-28 01:13:52.511 31509-32334/ W/LegacyRequestMapper: convertRequestMetadata - control.awbRegions setting is not supported, ignoring value
11-28 01:13:52.521 31509-32334/ W/LegacyRequestMapper: Only received metering rectangles with weight 0.
11-28 01:13:52.691 31509-31509/ I/here: video recording stop now
11-28 01:13:52.701 31509-31509/ I/Choreographer: Skipped 36 frames! The application may be doing too much work on its main thread.
11-28 01:13:52.781 31509-31509/ V/MediaPlayer-JNI: native_setup
11-28 01:13:52.781 31509-31509/ V/MediaPlayer: constructor
11-28 01:13:52.781 31509-31509/ V/MediaPlayer: setListener
11-28 01:13:52.781 31509-31509/ E/ExtMediaPlayer-JNI: QCMediaPlayer could not be located....
11-28 01:13:52.781 31509-31509/ E/MediaPlayer-JNI: QCMediaPlayer mediaplayer NOT present
11-28 01:13:52.791 31509-31509/ V/MediaPlayer-JNI: setDataSourceFD: fd 78
11-28 01:13:52.791 31509-31509/ V/MediaPlayer: setDataSource(78, 0, 576460752303423487)
11-28 01:13:52.801 31509-31521/ V/MediaPlayer: message received msg=8, ext1=0, ext2=0
11-28 01:13:52.801 31509-31521/ V/MediaPlayer: notify(8, 0, 0) callback on disconnected mediaplayer
11-28 01:13:52.851 31509-31509/ V/MediaPlayer: setVideoSurfaceTexture
11-28 01:13:52.851 31509-31509/ V/MediaPlayer: setVideoSurfaceTexture
11-28 01:13:52.851 31509-31509/ V/MediaPlayer: prepare
11-28 01:13:53.031 31509-31520/ V/MediaPlayer: message received msg=5, ext1=1080, ext2=1440
11-28 01:13:53.031 31509-31520/ V/MediaPlayer: New video size 1080 x 1440
11-28 01:13:53.031 31509-31520/ V/MediaPlayer: callback application
11-28 01:13:53.031 31509-31520/ V/MediaPlayer: back from callback
11-28 01:13:53.031 31509-31520/ V/MediaPlayer: message received msg=1, ext1=0, ext2=0
11-28 01:13:53.031 31509-31520/ V/MediaPlayer: prepared
11-28 01:13:53.031 31509-31520/ V/MediaPlayer: signal application thread
11-28 01:13:53.031 31509-31520/ V/MediaPlayer: callback application
11-28 01:13:53.031 31509-31509/ V/MediaPlayer: prepare complete - status=0
11-28 01:13:53.031 31509-31520/ V/MediaPlayer: back from callback
11-28 01:13:53.031 31509-31509/ E/MediaPlayer: Should have subtitle controller already set
11-28 01:13:53.031 31509-31509/ I/videoTV: android.graphics.SurfaceTexture@caa82cc
11-28 01:13:53.031 31509-31509/ I/videoTV: -1
11-28 01:13:53.031 31509-31509/ I/videoTV: -1
11-28 01:13:53.031 31509-31509/ V/MediaPlayer: getAudioStreamType
11-28 01:13:53.031 31509-31509/ V/MediaPlayer-JNI: getAudioStreamType: 3 (streamtype)
11-28 01:13:53.041 31509-31509/ V/MediaPlayer-JNI: start
11-28 01:13:53.041 31509-31509/ V/MediaPlayer: start
11-28 01:13:53.041 31509-32391/ V/MediaPlayer: message received msg=300, ext1=0, ext2=0
11-28 01:13:53.041 31509-32391/ V/MediaPlayer: Received SEC_MM_PLAYER_CONTEXT_AWARE
11-28 01:13:53.041 31509-32391/ V/MediaPlayer: callback application
11-28 01:13:53.041 31509-32391/ V/MediaPlayer: back from callback
11-28 01:13:53.151 31509-31509/ W/MediaPlayer: this is IMEDIA_PLAYER_VIDEO_EXIST
11-28 01:13:53.151 31509-31509/ I/MediaPlayer: sendBroadcast android.media.IMediaPlayer.videoexist
11-28 01:13:53.151 31509-31509/ E/MediaPlayer: Should have subtitle controller already set
11-28 01:13:53.221 31509-32336/ I/CameraDeviceState: Legacy camera service transitioning to state CAPTURING
11-28 01:13:53.221 31509-31520/ E/BufferQueueProducer: [unnamed-31509-4] dequeueBuffer: min undequeued buffer count (2) exceeded (dequeued=11 undequeued=0)
11-28 01:13:53.232 31509-32391/ V/MediaPlayer: message received msg=6, ext1=0, ext2=0
11-28 01:13:53.232 31509-32391/ V/MediaPlayer: Received MEDIA_STARTED
11-28 01:13:53.232 31509-32391/ V/MediaPlayer: callback application
11-28 01:13:53.232 31509-32391/ V/MediaPlayer: back from callback
11-28 01:13:53.232 31509-31509/ V/MediaPlayer-JNI: getCurrentPosition: 0 (msec)
11-28 01:13:53.242 31509-31509/ V/MediaPlayer-JNI: isPlaying: 1
11-28 01:13:53.282 31509-31521/ E/BufferQueueProducer: [unnamed-31509-4] dequeueBuffer: min undequeued buffer count (2) exceeded (dequeued=10 undequeued=1)
11-28 01:13:53.382 31509-32391/ V/MediaPlayer: message received msg=200, ext1=3, ext2=0
11-28 01:13:53.382 31509-32391/ W/MediaPlayer: info/warning (3, 0)
11-28 01:13:53.382 31509-32391/ V/MediaPlayer: callback application
11-28 01:13:53.382 31509-32391/ V/MediaPlayer: back from callback
11-28 01:13:53.882 31509-31509/ E/ContentValues: onPause
11-28 01:13:53.892 31509-31509/ I/RequestQueue: Repeating capture request cancelled.
11-28 01:13:53.972 31509-31520/ W/MessageQueue: Handler (android.graphics.SurfaceTexture$1) {3592742a} sending message to a Handler on a dead thread
java.lang.IllegalStateException: Handler (android.graphics.SurfaceTexture$1) {3592742a} sending message to a Handler on a dead thread
at android.os.MessageQueue.enqueueMessage(MessageQueue.java:325)
at android.os.Handler.enqueueMessage(Handler.java:631)
at android.os.Handler.sendMessageAtTime(Handler.java:600)
at android.os.Handler.sendMessageDelayed(Handler.java:570)
at android.os.Handler.sendEmptyMessageDelayed(Handler.java:534)
at android.os.Handler.sendEmptyMessage(Handler.java:519)
at android.graphics.SurfaceTexture.postEventFromNative(SurfaceTexture.java:368)
11-28 01:13:53.982 31509-31521/ E/BufferQueueProducer: [unnamed-31509-4] dequeueBuffer: BufferQueue has been abandoned
11-28 01:13:54.022 31509-32391/ E/BufferQueueProducer: [unnamed-31509-4] queueBuffer: BufferQueue has been abandoned
11-28 01:13:54.022 31509-31520/ E/BufferQueueProducer: [unnamed-31509-4] dequeueBuffer: BufferQueue has been abandoned
11-28 01:13:54.172 31509-32334/ E/BufferQueueProducer: [unnamed-31509-4] cancelBuffer: BufferQueue has been abandoned
11-28 01:13:54.172 31509-32334/ E/BufferQueueProducer: [unnamed-31509-4] cancelBuffer: BufferQueue has been abandoned
11-28 01:13:54.172 31509-32334/ E/BufferQueueProducer: [unnamed-31509-4] cancelBuffer: BufferQueue has been abandoned
11-28 01:13:54.182 31509-32334/ E/BufferQueueProducer: [unnamed-31509-4] cancelBuffer: BufferQueue has been abandoned
11-28 01:13:54.182 31509-32334/ E/BufferQueueProducer: [unnamed-31509-4] cancelBuffer: BufferQueue has been abandoned
11-28 01:13:54.182 31509-32334/ E/BufferQueueProducer: [unnamed-31509-4] cancelBuffer: BufferQueue has been abandoned
11-28 01:13:54.182 31509-32334/ E/BufferQueueProducer: [unnamed-31509-4] cancelBuffer: BufferQueue has been abandoned
11-28 01:13:54.182 31509-32334/ E/BufferQueueProducer: [unnamed-31509-4] cancelBuffer: BufferQueue has been abandoned
11-28 01:13:54.182 31509-32334/ E/BufferQueueProducer: [unnamed-31509-4] cancelBuffer: BufferQueue has been abandoned
11-28 01:13:54.643 31509-31509/ E/ContentValues: onResume
11-28 01:13:54.643 31509-31509/ I/in here: wtf
11-28 01:13:54.643 31509-31509/ W/ArrayUtils: Ignoring invalid value emboss
11-28 01:13:54.643 31509-31509/ W/ArrayUtils: Ignoring invalid value sketch
11-28 01:13:54.643 31509-31509/ W/ArrayUtils: Ignoring invalid value neon
11-28 01:13:54.643 31509-31509/ W/ArrayUtils: Ignoring invalid value vintage-warm
11-28 01:13:54.643 31509-31509/ W/ArrayUtils: Ignoring invalid value vintage-cold
11-28 01:13:54.643 31509-31509/ W/ArrayUtils: Ignoring invalid value washed
11-28 01:13:54.643 31509-31509/ W/ArrayUtils: Ignoring invalid value asd
11-28 01:13:54.643 31509-31509/ W/ArrayUtils: Ignoring invalid value back-light
11-28 01:13:54.643 31509-31509/ W/ArrayUtils: Ignoring invalid value flowers
11-28 01:13:54.643 31509-31509/ W/ArrayUtils: Ignoring invalid value AR
11-28 01:13:54.643 31509-31509/ W/ArrayUtils: Ignoring invalid value text
11-28 01:13:54.643 31509-31509/ W/ArrayUtils: Ignoring invalid value fall-color
11-28 01:13:54.643 31509-31509/ W/ArrayUtils: Ignoring invalid value dusk-dawn
11-28 01:13:54.653 31509-31509/ I/Flash info: true
11-28 01:13:54.653 31509-31509/ W/ArrayUtils: Ignoring invalid value emboss
11-28 01:13:54.653 31509-31509/ W/ArrayUtils: Ignoring invalid value sketch
11-28 01:13:54.653 31509-31509/ W/ArrayUtils: Ignoring invalid value neon
11-28 01:13:54.653 31509-31509/ W/ArrayUtils: Ignoring invalid value vintage-warm
11-28 01:13:54.653 31509-31509/ W/ArrayUtils: Ignoring invalid value vintage-cold
11-28 01:13:54.653 31509-31509/ W/ArrayUtils: Ignoring invalid value washed
11-28 01:13:54.653 31509-31509/ W/ArrayUtils: Ignoring invalid value asd
11-28 01:13:54.653 31509-31509/ W/ArrayUtils: Ignoring invalid value back-light
11-28 01:13:54.653 31509-31509/ W/ArrayUtils: Ignoring invalid value flowers
11-28 01:13:54.653 31509-31509/ W/ArrayUtils: Ignoring invalid value AR
11-28 01:13:54.653 31509-31509/ W/ArrayUtils: Ignoring invalid value text
11-28 01:13:54.653 31509-31509/ W/ArrayUtils: Ignoring invalid value fall-color
11-28 01:13:54.653 31509-31509/ W/ArrayUtils: Ignoring invalid value dusk-dawn
11-28 01:13:54.663 31509-31509/ I/CameraManager: Using legacy camera HAL.
11-28 01:13:55.033 31509-31509/ W/ArrayUtils: Ignoring invalid value emboss
11-28 01:13:55.033 31509-31509/ W/ArrayUtils: Ignoring invalid value sketch
11-28 01:13:55.033 31509-31509/ W/ArrayUtils: Ignoring invalid value neon
11-28 01:13:55.033 31509-31509/ W/ArrayUtils: Ignoring invalid value vintage-warm
11-28 01:13:55.033 31509-31509/ W/ArrayUtils: Ignoring invalid value vintage-cold
11-28 01:13:55.033 31509-31509/ W/ArrayUtils: Ignoring invalid value washed
11-28 01:13:55.043 31509-31509/ W/ArrayUtils: Ignoring invalid value asd
11-28 01:13:55.043 31509-31509/ W/ArrayUtils: Ignoring invalid value back-light
11-28 01:13:55.043 31509-31509/ W/ArrayUtils: Ignoring invalid value flowers
11-28 01:13:55.043 31509-31509/ W/ArrayUtils: Ignoring invalid value AR
11-28 01:13:55.043 31509-31509/ W/ArrayUtils: Ignoring invalid value text
11-28 01:13:55.043 31509-31509/ W/ArrayUtils: Ignoring invalid value fall-color
11-28 01:13:55.043 31509-31509/ W/ArrayUtils: Ignoring invalid value dusk-dawn
11-28 01:13:55.053 31509-31509/ I/camera: camera has been opened
11-28 01:13:55.083 31509-31509/ I/CameraDeviceState: Legacy camera service transitioning to state CONFIGURING
11-28 01:13:55.083 31509-32705/ I/RequestThread-0: Configure outputs: 2 surfaces configured.
11-28 01:13:55.083 31509-32705/ D/Camera: app passed NULL surface
11-28 01:13:55.093 31509-32705/ I/RequestThread-0: configureOutputs - set take picture size to 4128x3096
11-28 01:13:55.123 31509-31509/ I/CameraDeviceState: Legacy camera service transitioning to state IDLE
11-28 01:13:55.123 31509-31509/ I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@e3b5f9 time:438855524
11-28 01:13:55.123 31509-32670/ I/RequestQueue: Repeating capture request set.
11-28 01:13:55.133 31509-32705/ W/LegacyRequestMapper: convertRequestMetadata - control.awbRegions setting is not supported, ignoring value
11-28 01:13:55.133 31509-32705/ W/LegacyRequestMapper: Only received metering rectangles with weight 0.
11-28 01:13:55.864 31509-32709/ I/CameraDeviceState: Legacy camera service transitioning to state CAPTURING
11-28 01:13:55.864 31509-32391/ E/BufferQueueProducer: [unnamed-31509-7] dequeueBuffer: min undequeued buffer count (2) exceeded (dequeued=11 undequeued=0)
11-28 01:13:55.934 31509-32391/ E/BufferQueueProducer: [unnamed-31509-7] dequeueBuffer: min undequeued buffer count (2) exceeded (dequeued=10 undequeued=1)
11-28 01:13:55.984 31509-31509/ D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
11-28 01:13:57.626 31509-31509/ D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
11-28 01:13:58.747 31509-31521/ V/MediaPlayer: message received msg=2, ext1=0, ext2=0
11-28 01:13:58.757 31509-31521/ V/MediaPlayer: playback complete
11-28 01:13:58.757 31509-31521/ V/MediaPlayer: callback application
11-28 01:13:58.757 31509-31521/ V/MediaPlayer: back from callback
11-28 01:13:58.767 31509-31521/ V/MediaPlayer: message received msg=7, ext1=0, ext2=0
11-28 01:13:58.767 31509-31521/ V/MediaPlayer: unrecognized message: (7, 0, 0)
11-28 01:13:58.767 31509-31521/ V/MediaPlayer: callback application
11-28 01:13:58.767 31509-31521/ V/MediaPlayer: back from callback
11-28 01:13:58.777 31509-31509/ V/MediaPlayer-JNI: getCurrentPosition: 5476 (msec)
11-28 01:13:58.777 31509-31509/ V/MediaPlayer-JNI: isPlaying: 0
11-28 01:13:58.857 31509-31509/ D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
11-28 01:14:02.921 31509-31509/ D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
11-28 01:14:04.533 31509-31509/ D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
11-28 01:14:05.033 31509-31509/ I/RequestQueue: Repeating capture request cancelled.
11-28 01:14:05.063 31509-32705/ I/CameraDeviceState: Legacy camera service transitioning to state IDLE
11-28 01:14:05.103 31509-31509/ E/MediaRecorder: prepare failed: -2147483648
11-28 01:14:05.103 31509-31509/ D/AndroidRuntime: Shutting down VM
11-28 01:14:05.113 31509-31509/ E/AndroidRuntime: FATAL EXCEPTION: main
Process: , PID: 31509
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) 
Caused by: java.io.IOException: prepare failed.
at android.media.MediaRecorder._prepare(Native Method)
at android.media.MediaRecorder.prepare(MediaRecorder.java:873)
at .fragments.NewPostFragment.startRecordingVideo(NewPostFragment.kt:1455)
at .fragments.NewPostFragment.onLongClick(NewPostFragment.kt:589)
at android.view.View.performLongClick(View.java:5236)
at android.widget.TextView.performLongClick(TextView.java:10471)
at android.view.View$CheckForLongPress.run(View.java:20900)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) 

directory to save

When the button"Stop" is clicked, where is the location the recorded file is saved ?
Actually I don't think any video is saved. There is no video file newly found in my phone.

Linux-ish

is it possible to launch pip activity directly from a terminal using am command;
i.e., am start -n pkg.name/pkg.activity

ExoPlayer in RecyclerView

Hello,

I wanted to ask if you can also provide a sample with a combination of ExoPlayer and RecyclerView.
So, having a RecyclerView with some Video items and ExoPlayer showing those items while scrolling through the list.

I tried it but releasing the ExoPlayer after one video is handled is a great problem. It did not work very well for me.

Unable to fine Screen change area information

i am searching API that will give me update Rectangle that are change in UI of android , i dont want to copy whole screen shoot , want to capture only the area that is change, how can i doo that

how can i received callback when pip was closed

when pip window was closed, my app still playing the video. i'm unwilling to stop video when onStop called, because maybe it just restored fullscreen. So i hope receive closed callback, i can really destroy activity and release my MediaPlayer.

Android Studio 3 build.gradle issues

Importing this project as a Kotlin code sample in Android Studio 3.0.1, I get the following warnings relating to build.gradle:

  1. AS 3.0.1 warns about an outdated Kotlin runtime
  2. There are gradle deprecation warnings relating to 'compile', 'androidTestCompile' and 'testCompile' dependencies and CompileOptions.bootClasspath

I'll submit a PR.

Only Audio Playing - Android 7.0

I am facing an issue on OS 7.0 and 8.0, When i recorded video and playing it, Its playing only audio not showing video.

----Using following setup
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
if (mNextVideoAbsolutePath == null || mNextVideoAbsolutePath.isEmpty()) {
mediaFileR = getVideoFilePath(getActivity().getApplicationContext());
}
mMediaRecorder.setOutputFile(mediaFileR.getAbsolutePath());
mMediaRecorder.setVideoEncodingBitRate(10000000);
mMediaRecorder.setVideoFrameRate(30);
mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight());

    mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);// MPEG_4_SP
    mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

Resize PIP window size

How can I resize my PIP window. As it is so small that I'm not able to show relevant information. Google maps shows the same in larger view with portrait mode(Height more than width). And my PIP is opening in portrait mode but here width is more than height.

BasicMediaDecoder - no audio

Hi,
I am trying to play BasicMediaDecoder sample code. I am running it on PIXEL 2 API 29 emulator. Unfortunately I am not hearing any audio. Is it intended? If not please help me to fix the audio.

how to Start to preview in view Function

How to enter the page on the opening of the camera to start the preview, press after the beginning of recording?i think everyone in view start to preview ,help me ,thanks!

Picture in Picture mode issue

I am trying to implement Picture in Picture mode independent from activities. For now i have pip functionality but its activity dependent.so i want to make it activity independent and it should continue for all over the app once this available for devices.

custom actions icons like next, previous always looks in white color only

Dear Team.
Thanks in advance.
I am using custom actions like play next, play previous in PIP mode and for this I am using icons or images as next play button and previous play button. My problem is that i an using red/gray color icons but, when i run my code, color of icons/images became white automatically. I also tried many other color images but result is still same. So I want to ask that can we use the icons of different color other than white?

onSend() have interval more than 3 seconds.

Hi.
I connected my MIDI DEVICE with App.
I've entered the key quickly in DEVICE, but it takes more than 3 seconds to get it from the app.
Was this delay intended?
Is there a solution for getting input fast?
Thank you.

12-30 14:11:45.120 6267-6320/com.example.android.midiscope I/MidiScope: 52.434: 90 3C 2B: NoteOn(1, 60, 43)
12-30 14:11:48.173 6267-6320/com.example.android.midiscope I/MidiScope: 55.487: 90 3C 00: NoteOn(1, 60, 0)
12-30 14:11:51.181 6267-6320/com.example.android.midiscope I/MidiScope: 58.497: 90 3C 3E: NoteOn(1, 60, 62)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.