1

I want to make the app like "EASY screen recorder". From where I have to start because I search a lot but not any link i have found to getting start. There is any api that is used to create the screen recorder not screen shots. I do not want to create video from screen shots using javacv. I just want user start the application and and click on start recording button and what ever user did on the mobile record these.

1) Is there any api for this in android.

2) How I can create the screen recorder application in android.

3) Is there is not any api in android then please refer me other api so I can used in the android.

I search a lot but still no able to create the recording app. I have android application in which i add the code that take the screen shots using the handler after specific time at the end it create the video using javacv but i do not like because for this i have to write the code in every application and that take the screen shots of current activity and at the end create the video.

How EASY screen recorder developer create this app? which api they used. I want to create the clone of this app.

Sohaib Ahmed
  • 31
  • 1
  • 6
  • Check [this](http://stackoverflow.com/questions/1817742/how-can-i-capture-a-video-recording-on-android) and [this](http://stackoverflow.com/questions/14336338/screen-video-record-of-current-activity-android) – MysticMagicϡ Sep 02 '14 at 04:50
  • thanks, but I already read these links but not helpfull – Sohaib Ahmed Sep 02 '14 at 04:53

4 Answers4

5

Sorry for late answer but here is a working code. It will work on Lollipop and above

    private VirtualDisplay mVirtualDisplay;
    private MediaRecorder mMediaRecorder;
    private MediaProjection mMediaProjection;
    private MediaProjectionCallback callback;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        MediaProjectionManager projectionManager = (MediaProjectionManager) 
        context.getSystemService(Context.MEDIA_PROJECTION_SERVICE);
        mMediaProjection.registerCallback(callback, null);
        initRecorder();
        mMediaRecorder.prepare();
        mVirtualDisplay = createVirtualDisplay();
        mMediaRecorder.start();
}

public void initRecorder() {
        path = "/sdcard/Record/video" + ".mp4";
        recId = "capture-" + System.currentTimeMillis() + ".mp4";
        File myDirectory = new File(Environment.getExternalStorageDirectory(), "Record");

            mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
            mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
            mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
            mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
            mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
            mMediaRecorder.setVideoEncodingBitRate(MainFragment.bitRate);          
            mMediaRecorder.setVideoFrameRate(30);
            mMediaRecorder.setVideoSize(MainFragment.DISPLAY_WIDTH,
            MainFragment.DISPLAY_HEIGHT);
            mMediaRecorder.setOutputFile(path);
    }


    private VirtualDisplay createVirtualDisplay() {
        return mMediaProjection.createVirtualDisplay("MainActivity",
                MainFragment.DISPLAY_WIDTH, MainFragment.DISPLAY_HEIGHT, MainFragment.screenDensity,
                DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
                mMediaRecorder.getSurface(), null /*Callbacks*/, null /*Handler*/);
    }

public class MediaProjectionCallback extends MediaProjection.Callback {
        @Override
        public void onStop() {
            mMediaRecorder.stop();
            // mMediaRecorder.reset();
            mMediaRecorder.release();
            mMediaProjection.unregisterCallback(callback);
            mMediaProjection = null;
            mMediaRecorder = null;
        }
Wonjung Kim
  • 1,873
  • 15
  • 18
Muhammad Umair Shafique
  • 2,475
  • 1
  • 30
  • 39
1

As Per Android 5.0, you will be able to capture screen contents through MediaProjection API and you dont have to root the device.Try to project on SurfaceView and record from there.

SRK
  • 118
  • 2
  • 10
  • You can't record from a SurfaceView. But you can replace the SurfaceView's Surface with the Surface input to MediaRecorder or MediaCodec. – fadden May 07 '15 at 17:50
  • Can you share how to replace surfaceview's surface? – Ayyappa Sep 12 '21 at 19:17
0

Android doesn't provide any API exposing the frame buffers, you need to root your device and could use some source code from http://code.google.com/p/fastdroid-vnc/ for getting the raw frame buffer and then record it.

Remember, you need to root your device for doing this.

The simplest way using android kitkat is using ADB screenrecord command.

Suneesh
  • 469
  • 7
  • 21
0

there are few work arounds - which does not require you to root your device).

  • if you are creating a demo for your app, then you can use an emulator or bluestack and a desktop screen recorder to record just the emulator.

  • if you need to show the app in use on actual phone, then you can use another camera to record the app being used.

  • if you have to capture the screen and can hook the phone up to a computer, you can take screenshots of the phone screen from the desktop at a faster rate (doing the same as Dalvik Debug Monitor Device > Screen capture.), and then combine the images into a movie.

If you have to create an app, then you will have to explore the NDK.

Kinjal Dixit
  • 7,777
  • 2
  • 59
  • 68
  • 1
    Then how "EASY screen recorder" applicated created? This application does what I want. – Sohaib Ahmed Sep 02 '14 at 05:18
  • I mention the api in my question its mean I talk about programmatically – Sohaib Ahmed Sep 02 '14 at 05:20
  • Its mean every application in the google store they are developed by native app writen in c++. There is no way to record the screen in android its impossible in android? – Sohaib Ahmed Sep 02 '14 at 05:22
  • the NDK allows you to write parts of your application using C. My guess is that the C library provides access to the video framebuffer. The EASY screen recorder people say that if you do not want to root the device, then you have to connect to PC one time and run an installer from there. My guess is that the installer somehow installs the NDK part to the phone. – Kinjal Dixit Sep 02 '14 at 05:23
  • ok but easy screen recorder is able to to record the screen but in which way they did. Thery write the code in c++ or c becasue if it is not alow in android – Sohaib Ahmed Sep 02 '14 at 05:33