layout_height="wrap_content"
? ? ? ? ? ? android:minHeight="40dp"
? ? ? ? ? ? android:minWidth="70dp"
? ? ? ? ? ? android:text="录制" />
? ? ? ? ? ? ? ? ? ? android:id="@+id/rv_stop"
? ? ? ? ? ? style="@style/mainactivitybtnstyle"
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:layout_marginLeft="10dip"
? ? ? ? ? ? android:minHeight="40dp"
? ? ? ? ? ? android:minWidth="70dp"
? ? ? ? ? ? android:text="停止" />
? ?
? ? ? ? ? ? android:layout_width="fill_parent"
? ? ? ? android:layout_height="fill_parent"
? ? ? ? android:gravity="center_horizontal"
? ? ? ? android:orientation="vertical" >
? ? ? ? ? ? ? ? ? ? android:id="@+id/rv_schedule"
? ? ? ? ? ? style="?android:attr/progressBarStyleHorizontal"
? ? ? ? ? ? android:layout_width="fill_parent"
? ? ? ? ? ? android:layout_height="wrap_content" />
? ? ? ? ? ? ? ? ? ? android:id="@+id/rv_record_time"
? ? ? ? ? ? android:layout_width="fill_parent"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:gravity="center"
? ? ? ? ? ? android:text="00:00:000"
? ? ? ? ? ? android:textColor="#FF750000"
? ? ? ? ? ? android:textSize="24sp"
? ? ? ? ? ? android:textStyle="bold" />
? ?
Activity代码,因为非常简单,就没有封装多线程什么的。
import java.io.File;
import java.text.SimpleDateFormat;
import android.content.Context;
import android.content.pm.FeatureInfo;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.ict.util.IOUtil;
public class RecordVideoActivity extends ActionBarActivity {
? ? private static final String TAG = "RecordVideo";
? ? private SurfaceView surfaceView;
? ? private MediaRecorder mediaRecorder;
? ? private boolean record;? ?
? ? private TextView testusername;
? ? private Camera camera;
? ?
? ? // 计时器相关
? ? private MyChronograph myChronograph;
? ? private TextView chronograph = null;
? ?
? ? private ProgressBar schedule;
? ? private boolean recordOver = false;
? ?
? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? // TODO Auto-generated method stub
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.recordvideo);
? ? ? ? setTitle("录制视频");
? ? ? ? mediaRecorder = new MediaRecorder();
? ? ? ? surfaceView = (SurfaceView) this.findViewById(R.id.surfaceView);
? ? ? ? this.surfaceView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
? ? ? ? this.surfaceView.getHolder().setFixedSize(320, 240);//设置分辨率
? ? ? ? testusername = (EditText)findViewById(R.id.rv_testusername);
? ? ? ? chronograph = (TextView)findViewById(R.id.rv_record_time);
? ? ? ? schedule = (ProgressBar)findViewById(R.id.rv_schedule);
? ? ? ? schedule.setMax(60);
? ? ? ? ButtonClickListener listener = new ButtonClickListener();
? ? ? ? Button stopButton = (Button) this.findViewById(R.id.rv_stop);
? ? ? ? Button recordButton = (Button) this.findViewById(R.id.rv_record);
? ? ? ? stopButton.setOnClickListener(listener);
? ? ? ? recordButton.setOnClickListener(liste