在Android的Programmactically屏幕录像,不截屏 [英] Screen Recorder in Android Programmactically, not Screen shots

查看:313
本文介绍了在Android的Programmactically屏幕录像,不截屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要让像EASY屏幕录像机的应用程序。从哪里我要开始,因为我搜索了很多,但没有我发现开始使用任何链接。有是用于创建屏幕记录没有屏幕截图的API。我不想使用javacv屏幕截图制作视频。我只是想用户启动应用程序,然后点击开始记录按钮和什么都没有的用户在移动记录这些。

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)是否有任何的Andr​​oid API这一点。

1) Is there any api for this in android.

2)如何我可以创建在Android上的屏幕记录应用程序。

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

3)有没有在Android中,那么请参考我其他的API任何API,所以我可以在Android中使用。

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

我搜索了很多,但仍然没有能够创造出录音应用。
我有我添加code,它采取用后在结束具体时间处理它使用javacv创建视频,但我并不是因为喜欢这个,我必须写code中的截屏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.

如何EASY屏幕录像机开发创建这个应用程序?他们使用的API。我想创建这个应用程序的克隆。

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

推荐答案

对不起,迟到的答案,但这里是一个工作code.It将棒棒堂工作,上述

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;
        }

这篇关于在Android的Programmactically屏幕录像,不截屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆