纸上得来终觉浅,绝知此事要躬行,Android在5.0提供了MediaProjection来实现录屏,但是一直都没有尝试过,这里尝试了一下该方式进行录屏。
其实Demo已经写好很久了,但是始终有一个问题,在某些机型上会偏色,因此这里写出来看看是否有人遇到同样的问题,且希望告知解决方案。
录制
这里界面上有两个按钮,一个控制录制与暂停,另外一个是播放按钮,既然是录制,当然录制完成我们需要看看录制的效果。
布局界面如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.demo.example.activity.ScreenRecordActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal">
<Button
android:id="@+id/record"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="start"/>
<Button
android:id="@+id/play"
android:layout_width="wrap_content"
android:layout