这个接上一个写的实现拍小视频和传到服务器的 

界面是这个样子滴.

我也知不知道怎么给图片搞小一点o(╯□╰)o

布局文件是这样的【认真脸】

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#2B2B2B"
android:orientation="vertical"> <LinearLayout
android:id="@+id/ll_historydatadetail_title"
android:layout_width="match_parent"
android:layout_height="51dp"
android:background="@color/titlecolor"
android:orientation="horizontal"> <ImageButton
android:id="@+id/imb_back"
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:background="@null"
android:src="@mipmap/upload_video_esc" /> </LinearLayout> <FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=""> <cn.com.jwtimes.www.jwtimes.view.MovieRecorderView
android:id="@+id/movieRecorderView"
android:layout_width="match_parent"
android:layout_height="0dp" /> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"> <TextView
android:id="@+id/textView_release_to_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="50dp"
android:background="#99b31921"
android:padding="2dp"
android:text="松开取消"
android:textColor="#ffffff"
android:visibility="gone" />
</RelativeLayout>
</FrameLayout> <FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/datadetailtext"> <RelativeLayout
android:id="@+id/rl_bottom_root"
android:layout_width="match_parent"
android:layout_height="wrap_content"> <TextView
android:id="@+id/textView_up_to_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:background="#33000000"
android:text="上移取消"
android:textColor="#ffffff"
android:visibility="gone" /> <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
android:layout_marginTop="15dp"
android:orientation="horizontal"> <TextView
android:id="@+id/textView_count_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#707070"
android:textSize="14sp" />
</LinearLayout> <ProgressBar
android:id="@+id/progressBar_loading"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="5dp" /> <Button
android:id="@+id/shoot_button"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_below="@+id/progressBar_loading"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:layout_marginTop="40dp"
android:background="@drawable/voidbutton"
android:text="按住拍"
android:textColor="#fff" />
</RelativeLayout>
</FrameLayout>
</LinearLayout>

中间发现一个特务就是混进来的自定义录制视频的的MovieRecorderView这个家伙

package cn.com.jwtimes.www.jwtimes.view;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.media.MediaRecorder;
import android.media.MediaRecorder.AudioEncoder;
import android.media.MediaRecorder.AudioSource;
import android.media.MediaRecorder.OnErrorListener;
import android.media.MediaRecorder.OutputFormat;
import android.media.MediaRecorder.VideoEncoder;
import android.media.MediaRecorder.VideoSource;
import android.os.Build;
import android.os.Environment;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
import android.widget.LinearLayout; import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask; import cn.com.jwtimes.www.jwtimes.R; /**
* Created by 王超然 on 2016/6/3.
*/
public class MovieRecorderView extends LinearLayout implements OnErrorListener {
private static final String LOG_TAG = "MovieRecorderView"; private Context context; private SurfaceView surfaceView;
private SurfaceHolder surfaceHolder; private MediaRecorder mediaRecorder;
private Camera camera;
private Timer timer;//计时器 private int mWidth;//视频录制分辨率宽度
private int mHeight;//视频录制分辨率高度
private boolean isOpenCamera;//是否一开始就打开摄像头
private int recordMaxTime;//最长拍摄时间
private int timeCount;//时间计数
private File recordFile = null;//视频文件
private long sizePicture = ; public MovieRecorderView(Context context) {
this(context, null);
} public MovieRecorderView(Context context, AttributeSet attrs) {
this(context, attrs, );
} @TargetApi(Build.VERSION_CODES.HONEYCOMB)
public MovieRecorderView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.context = context; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MovieRecorderView, defStyle, );
mWidth = a.getInteger(R.styleable.MovieRecorderView_record_width, );//默认640
mHeight = a.getInteger(R.styleable.MovieRecorderView_record_height, );//默认360 isOpenCamera = a.getBoolean(R.styleable.MovieRecorderView_is_open_camera, true);//默认打开摄像头
recordMaxTime = a.getInteger(R.styleable.MovieRecorderView_record_max_time, );//默认最大拍摄时间为10s LayoutInflater.from(context).inflate(R.layout.movie_recorder_view, this);
surfaceView = (SurfaceView) findViewById(R.id.surfaceview);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(new CustomCallBack());
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); a.recycle();
} /**
* SurfaceHolder回调
*/
private class CustomCallBack implements Callback {
@Override
public void surfaceCreated(SurfaceHolder holder) {
if (!isOpenCamera)
return;
try {
initCamera();
} catch (IOException e) {
e.printStackTrace();
}
} @Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { } @Override
public void surfaceDestroyed(SurfaceHolder holder) {
if (!isOpenCamera)
return;
freeCameraResource();
}
} /**
* 初始化摄像头
*/
public void initCamera() throws IOException {
if (camera != null) {
freeCameraResource();
}
try {
if (checkCameraFacing(Camera.CameraInfo.CAMERA_FACING_BACK)) {
camera = Camera.open(Camera.CameraInfo.CAMERA_FACING_BACK);
} else if (checkCameraFacing(Camera.CameraInfo.CAMERA_FACING_FRONT)) {
camera = Camera.open(Camera.CameraInfo.CAMERA_FACING_FRONT);
}
} catch (Exception e) {
e.printStackTrace();
freeCameraResource();
((Activity) context).finish();
}
if (camera == null)
return; setCameraParams();
camera.setDisplayOrientation();
camera.setPreviewDisplay(surfaceHolder);
camera.startPreview();
camera.unlock();
} /**
* 检查是否有摄像头
*
* @param facing 前置还是后置
* @return
*/
private boolean checkCameraFacing(int facing) {
int cameraCount = Camera.getNumberOfCameras();
Camera.CameraInfo info = new Camera.CameraInfo();
for (int i = ; i < cameraCount; i++) {
Camera.getCameraInfo(i, info);
if (facing == info.facing) {
return true;
}
}
return false;
} /**
* 设置摄像头为竖屏
*/
private void setCameraParams() {
if (camera != null) {
Parameters params = camera.getParameters();
params.set("orientation", "portrait");
List<Camera.Size> supportedPictureSizes = params.getSupportedPictureSizes();
for (Camera.Size size : supportedPictureSizes) {
sizePicture = (size.height * size.width) > sizePicture ? size.height * size.width : sizePicture;
}
// LogUtil.e(LOG_TAG,"手机支持的最大像素supportedPictureSizes===="+sizePicture);
setPreviewSize(params);
camera.setParameters(params);
}
} /**
* 根据手机支持的视频分辨率,设置预览尺寸
*
* @param params
*/
private void setPreviewSize(Parameters params) {
if (camera == null) {
return;
}
//获取手机支持的分辨率集合,并以宽度为基准降序排序
List<Camera.Size> previewSizes = params.getSupportedPreviewSizes();
Collections.sort(previewSizes, new Comparator<Camera.Size>() {
@Override
public int compare(Camera.Size lhs, Camera.Size rhs) {
if (lhs.width > rhs.width) {
return -;
} else if (lhs.width == rhs.width) {
return ;
} else {
return ;
}
}
}); float tmp = 0f;
float minDiff = 100f;
float ratio = 3.0f / 4.0f;//TODO 高宽比率3:4,且最接近屏幕宽度的分辨率,可以自己选择合适的想要的分辨率
Camera.Size best = null;
for (Camera.Size s : previewSizes) {
tmp = Math.abs(((float) s.height / (float) s.width) - ratio);
Log.e(LOG_TAG, "setPreviewSize: width:" + s.width + "...height:" + s.height);
// LogUtil.e(LOG_TAG,"tmp:" + tmp);
if (tmp < minDiff) {
minDiff = tmp;
best = s;
}
} params.setPreviewSize(best.width, best.height);//预览比率 Log.e(LOG_TAG, "setPreviewSize BestSize: width:" + best.width + "...height:" + best.height); //TODO 大部分手机支持的预览尺寸和录制尺寸是一样的,也有特例,有些手机获取不到,那就把设置录制尺寸放到设置预览的方法里面
if (params.getSupportedVideoSizes() == null || params.getSupportedVideoSizes().size() == ) {
mWidth = best.width;
mHeight = best.height;
} else {
setVideoSize(params);
}
} /**
* 根据手机支持的视频分辨率,设置录制尺寸
*
* @param params
*/
private void setVideoSize(Parameters params) {
if (camera == null) {
return;
}
//获取手机支持的分辨率集合,并以宽度为基准降序排序
List<Camera.Size> previewSizes = params.getSupportedVideoSizes();
Collections.sort(previewSizes, new Comparator<Camera.Size>() {
@Override
public int compare(Camera.Size lhs, Camera.Size rhs) {
if (lhs.width > rhs.width) {
return -;
} else if (lhs.width == rhs.width) {
return ;
} else {
return ;
}
}
}); float tmp = 0f;
float minDiff = 100f;
float ratio = 3.0f / 4.0f;//高宽比率3:4,且最接近屏幕宽度的分辨率
Camera.Size best = null;
for (Camera.Size s : previewSizes) {
tmp = Math.abs(((float) s.height / (float) s.width) - ratio);
Log.e(LOG_TAG, "setVideoSize: width:" + s.width + "...height:" + s.height);
if (tmp < minDiff) {
minDiff = tmp;
best = s;
}
}
Log.e(LOG_TAG, "setVideoSize BestSize: width:" + best.width + "...height:" + best.height);
//设置录制尺寸
mWidth = best.width;
mHeight = best.height;
} /**
* 释放摄像头资源
*/
private void freeCameraResource() {
try {
if (camera != null) {
camera.setPreviewCallback(null);
camera.stopPreview();
camera.lock();
camera.release();
camera = null;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
camera = null;
}
} /**
* 创建视频文件
*/
private void createRecordDir() {
File sampleDir = new File(Environment.getExternalStorageDirectory() + File.separator + "SampleVideo/video/");
if (!sampleDir.exists()) {
sampleDir.mkdirs();
}
try {
//TODO 文件名用的时间戳,可根据需要自己设置,格式也可以选择3gp,在初始化设置里也需要修改
recordFile = new File(sampleDir, System.currentTimeMillis() + ".mp4");
// recordFile = new File(sampleDir, System.currentTimeMillis() + ".mp4");
// File.createTempFile(AccountInfo.userId, ".mp4", sampleDir);
// LogUtil.e(LOG_TAG, recordFile.getAbsolutePath());
} catch (Exception e) {
e.printStackTrace();
}
} /**
* 录制视频初始化
*/
private void initRecord() throws Exception {
mediaRecorder = new MediaRecorder();
mediaRecorder.reset();
if (camera != null)
mediaRecorder.setCamera(camera);
mediaRecorder.setOnErrorListener(this);
mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
mediaRecorder.setVideoSource(VideoSource.CAMERA);//视频源
mediaRecorder.setAudioSource(AudioSource.MIC);//音频源
mediaRecorder.setOutputFormat(OutputFormat.MPEG_4);//TODO 视频输出格式 也可设为3gp等其他格式
mediaRecorder.setAudioEncoder(AudioEncoder.AMR_NB);//音频格式
mediaRecorder.setVideoSize(mWidth, mHeight);//设置分辨率
// mediaRecorder.setVideoFrameRate(25);//TODO 设置每秒帧数 这个设置有可能会出问题,有的手机不支持这种帧率就会录制失败,这里使用默认的帧率,当然视频的大小肯定会受影响
// LogUtil.e(LOG_TAG,"手机支持的最大像素supportedPictureSizes===="+sizePicture);
if (sizePicture < ) {//这里设置可以调整清晰度
mediaRecorder.setVideoEncodingBitRate( * * );
} else if (sizePicture <= ) {
mediaRecorder.setVideoEncodingBitRate( * * );
} else {
mediaRecorder.setVideoEncodingBitRate( * * );
}
mediaRecorder.setOrientationHint();//输出旋转90度,保持竖屏录制 mediaRecorder.setVideoEncoder(VideoEncoder.H264);//视频录制格式
//mediaRecorder.setMaxDuration(Constant.MAXVEDIOTIME * 1000);
mediaRecorder.setOutputFile(recordFile.getAbsolutePath());
mediaRecorder.prepare();
mediaRecorder.start();
} /**
* 开始录制视频
*
* @param onRecordFinishListener 达到指定时间之后回调接口
*/
public void record(final OnRecordFinishListener onRecordFinishListener) {
this.onRecordFinishListener = onRecordFinishListener;
createRecordDir();
try {
//如果未打开摄像头,则打开
if (!isOpenCamera)
initCamera();
initRecord();
timeCount = ;//时间计数器重新赋值
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
timeCount++;
//progressBar.setProgress(timeCount);//设置进度条
if (onRecordProgressListener != null) {
onRecordProgressListener.onProgressChanged(recordMaxTime, timeCount);
} //达到指定时间,停止拍摄
if (timeCount == recordMaxTime) {
stop();
if (MovieRecorderView.this.onRecordFinishListener != null)
MovieRecorderView.this.onRecordFinishListener.onRecordFinish();
}
}
}, , );
} catch (Exception e) {
e.printStackTrace();
if (mediaRecorder != null) {
mediaRecorder.release();
}
freeCameraResource();
}
} /**
* 停止拍摄
*/
public void stop() {
stopRecord();
releaseRecord();
freeCameraResource();
} /**
* 停止录制
*/
public void stopRecord() {
//progressBar.setProgress(0);
if (timer != null)
timer.cancel();
if (mediaRecorder != null) {
mediaRecorder.setOnErrorListener(null);//设置后防止崩溃
mediaRecorder.setPreviewDisplay(null);
try {
mediaRecorder.stop();
} catch (Exception e) {
e.printStackTrace();
}
}
} /**
* 释放资源
*/
private void releaseRecord() {
if (mediaRecorder != null) {
mediaRecorder.setOnErrorListener(null);
try {
mediaRecorder.release();
} catch (Exception e) {
e.printStackTrace();
}
}
mediaRecorder = null;
} /**
* 获取当前录像时间
*
* @return timeCount
*/
public int getTimeCount() {
return timeCount;
} /**
* 设置最大录像时间
*
* @param recordMaxTime
*/
public void setRecordMaxTime(int recordMaxTime) {
this.recordMaxTime = recordMaxTime;
} /**
* 返回录像文件
*
* @return recordFile
*/
public File getRecordFile() {
return recordFile;
} /**
* 录制完成监听
*/
private OnRecordFinishListener onRecordFinishListener; /**
* 录制完成接口
*/
public interface OnRecordFinishListener {
void onRecordFinish();
} /**
* 录制进度监听
*/
private OnRecordProgressListener onRecordProgressListener; /**
* 设置录制进度监听
*
* @param onRecordProgressListener
*/
public void setOnRecordProgressListener(OnRecordProgressListener onRecordProgressListener) {
this.onRecordProgressListener = onRecordProgressListener;
} /**
* 录制进度接口
*/
public interface OnRecordProgressListener {
/**
* 进度变化
*
* @param maxTime 最大时间,单位秒
* @param currentTime 当前进度
*/
void onProgressChanged(int maxTime, int currentTime);
} @Override
public void onError(MediaRecorder mr, int what, int extra) {
try {
if (mr != null)
mr.reset();
} catch (Exception e) {
e.printStackTrace();
}
}
}

这个是抄的,感谢那个伟大的程序员,我踩在了巨人的肩膀上。 
button的样式:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#000"/>
<stroke android:width="1dp" android:color="#a0a0a0"/> <corners android:topLeftRadius="100dp"
android:topRightRadius="100dp"
android:bottomRightRadius="100dp"
android:bottomLeftRadius="100dp"
/> </shape>

然后是Activity:

package cn.com.jwtimes.www.jwtimes.ui.disaupload;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.DisplayMetrics;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast; import java.io.File;
import java.io.IOException; import cn.com.jwtimes.www.jwtimes.R;
import cn.com.jwtimes.www.jwtimes.view.MovieRecorderView; public class MovieRecorderActivity extends AppCompatActivity {
private static final String LOG_TAG = "RecordVideoActivity";
private static final int REQ_CODE = ;
private static final int RES_CODE = ;
/**
* 录制进度
*/
private static final int RECORD_PROGRESS = ;
/**
* 录制结束
*/
private static final int RECORD_FINISH = ; private MovieRecorderView movieRecorderView;
private Button buttonShoot;
private RelativeLayout rlBottomRoot;
private ProgressBar progressVideo;
private TextView textViewCountDown;
private TextView textViewUpToCancel;//上移取消
private TextView textViewReleaseToCancel;//释放取消
/**
* 是否结束录制
*/
private boolean isFinish = true;
/**
* 是否触摸在松开取消的状态
*/
private boolean isTouchOnUpToCancel = false;
/**
* 当前进度
*/
private int currentTime = ;
private ImageButton imb_back;
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case RECORD_PROGRESS:
progressVideo.setProgress(currentTime);
if (currentTime < ) {
textViewCountDown.setText("00:0" + currentTime);
} else {
textViewCountDown.setText("00:" + currentTime);
}
break;
case RECORD_FINISH:
if (isTouchOnUpToCancel) {//录制结束,还在上移删除状态没有松手,就复位录制
resetData();
} else {//录制结束,在正常位置,录制完成跳转页面
isFinish = true;
buttonShoot.setEnabled(false);
finishActivity();
}
break;
}
}
};
/**
* 按下的位置
*/
private float startY;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_movie_recorder);
initView(); } private void initView() { imb_back = (ImageButton) findViewById(R.id.imb_back);
imb_back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MovieRecorderActivity.this.finish();
overridePendingTransition(R.anim.anim_slide_left_in, R.anim.anim_slide_right_out);
}
}); movieRecorderView = (MovieRecorderView) findViewById(R.id.movieRecorderView);
buttonShoot = (Button) findViewById(R.id.shoot_button);
rlBottomRoot = (RelativeLayout) findViewById(R.id.rl_bottom_root);
//progressVideo = (DonutProgress) findViewById(R.id.progress_video);
progressVideo = (ProgressBar) findViewById(R.id.progressBar_loading);
textViewCountDown = (TextView) findViewById(R.id.textView_count_down);
textViewCountDown.setText("00:00");
textViewUpToCancel = (TextView) findViewById(R.id.textView_up_to_cancel);
textViewReleaseToCancel = (TextView) findViewById(R.id.textView_release_to_cancel); DisplayMetrics dm = getApplicationContext().getResources().getDisplayMetrics();
int width = dm.widthPixels;
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) movieRecorderView.getLayoutParams();
layoutParams.height = width * / ;//根据屏幕宽度设置预览控件的尺寸,为了解决预览拉伸问题
//LogUtil.e(LOG_TAG, "mSurfaceViewWidth:" + width + "...mSurfaceViewHeight:" + layoutParams.height);
movieRecorderView.setLayoutParams(layoutParams); FrameLayout.LayoutParams rlBottomRootLayoutParams = (FrameLayout.LayoutParams) rlBottomRoot.getLayoutParams();
rlBottomRootLayoutParams.height = width / * ;
rlBottomRoot.setLayoutParams(rlBottomRootLayoutParams); //处理触摸事件
buttonShoot.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
textViewUpToCancel.setVisibility(View.VISIBLE);//提示上移取消 isFinish = false;//开始录制
startY = event.getY();//记录按下的坐标
movieRecorderView.record(new MovieRecorderView.OnRecordFinishListener() {
@Override
public void onRecordFinish() {
handler.sendEmptyMessage(RECORD_FINISH);
}
});
} else if (event.getAction() == MotionEvent.ACTION_UP) {
textViewUpToCancel.setVisibility(View.GONE);
textViewReleaseToCancel.setVisibility(View.GONE); if (startY - event.getY() > ) {//上移超过一定距离取消录制,删除文件
if (!isFinish) {
resetData();
}
} else {
if (movieRecorderView.getTimeCount() > ) {//录制时间超过三秒,录制完成
handler.sendEmptyMessage(RECORD_FINISH);
} else {//时间不足取消录制,删除文件
Toast.makeText(MovieRecorderActivity.this, "视频录制时间太短", Toast.LENGTH_SHORT).show();
resetData();
}
}
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
//根据触摸上移状态切换提示
if (startY - event.getY() > ) {
isTouchOnUpToCancel = true;//触摸在松开就取消的位置
if (textViewUpToCancel.getVisibility() == View.VISIBLE) {
textViewUpToCancel.setVisibility(View.GONE);
textViewReleaseToCancel.setVisibility(View.VISIBLE);
}
} else {
isTouchOnUpToCancel = false;//触摸在正常录制的位置
if (textViewUpToCancel.getVisibility() == View.GONE) {
textViewUpToCancel.setVisibility(View.VISIBLE);
textViewReleaseToCancel.setVisibility(View.GONE);
}
}
} else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
resetData();
}
return true;
}
}); progressVideo.setMax();
movieRecorderView.setOnRecordProgressListener(new MovieRecorderView.OnRecordProgressListener() {
@Override
public void onProgressChanged(int maxTime, int currentTime) {
MovieRecorderActivity.this.currentTime = currentTime;
handler.sendEmptyMessage(RECORD_PROGRESS);
}
});
} @Override
public void onResume() {
super.onResume();
checkCameraPermission();
} /**
* 检测摄像头和录音权限
*/
private void checkCameraPermission() {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED
|| ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
// Camera permission has not been granted.
Toast.makeText(this, "视频录制和录音没有授权", Toast.LENGTH_LONG);
this.finish();
} else {
resetData();
}
} /**
* 重置状态
*/
private void resetData() {
if (movieRecorderView.getRecordFile() != null)
movieRecorderView.getRecordFile().delete();
movieRecorderView.stop();
isFinish = true;
currentTime = ;
progressVideo.setProgress(); buttonShoot.setEnabled(true);
textViewUpToCancel.setVisibility(View.GONE);
textViewReleaseToCancel.setVisibility(View.GONE);
try {
movieRecorderView.initCamera();
} catch (IOException e) {
e.printStackTrace();
}
} @Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
isFinish = true;
movieRecorderView.stop();
} /**
* 递归删除目录下的所有文件及子目录下所有文件
*
* @param dir 将要删除的文件目录
* @return
*/
private boolean deleteDir(File dir) {
if (dir.isDirectory()) {
String[] children = dir.list();
//递归删除目录中的子目录下
for (int i = ; i < children.length; i++) {
if (!deleteDir(new File(dir, children[i]))) {
return false;
}
}
}
return dir.delete();
} // @Override
// public void onDestroy() {
// //TODO 退出界面删除文件,如果要删除文件夹,需要提供文件夹路径
// if (movieRecorderView.getRecordFile() != null) {
// File file = new File(movieRecorderView.getRecordFile().getAbsolutePath());
// if (file != null && file.exists()) {
// Log.e(LOG_TAG, "file.exists():" + file.exists());
// file.delete();
// }
// }
// super.onDestroy();
// }
//视频录制结束后,跳转的函数
private void finishActivity() {
if (isFinish) {
movieRecorderView.stop();
Intent intent = new Intent(this, SendMovieActivity.class);
Bundle bundle = new Bundle();
bundle.putString("text", movieRecorderView.getRecordFile().getAbsolutePath());
intent.putExtras(bundle);
startActivity(intent);
Toast.makeText(MovieRecorderActivity.this, "录制结束", Toast.LENGTH_SHORT);
MovieRecorderActivity.this.finish();
overridePendingTransition(R.anim.anim_slide_right_in, R.anim.anim_slide_left_out);
} } @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQ_CODE && resultCode == RES_CODE) {
setResult(RES_CODE);
finish();
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
MovieRecorderActivity.this.finish();
overridePendingTransition(R.anim.anim_slide_left_in, R.anim.anim_slide_right_out);
return false;
}
return super.onKeyDown(keyCode, event);
}
}

我把那个跳出页面就删除的给注释掉了,因为我要点击这个小的,把url传到播放的页面让他全屏播放。

Android 仿微信朋友圈拍小视频上传到服务器的更多相关文章

  1. vue 仿微信朋友圈9张图上传功能

    项目需求要求用户上传商品的时候可以一次性上传9张图,多余9张提示‘只能上传9张图’,并且每张图右上角有个删除按钮,图片也可以点击放大. 出来的效果图如下: 话不多说,上代码: <el-form- ...

  2. Android 仿微信朋友圈发动态功能(相册图片多选)

    代码分享 代码名称: 仿微信朋友圈发动态功能(相册图片多选) 代码描述: 仿微信朋友圈发动态功能(相册图片多选) 代码托管地址: http://www.apkbus.com/android-15276 ...

  3. Android 仿微信朋友圈添加图片

    github地址(欢迎下载Demo) https://github.com/zhouxu88/WXCircleAddPic 老习惯,先上图,着急用的朋友,直接带走Demo,先拿来用吧,毕竟老板催的紧, ...

  4. Android 仿微信朋友圈发表图片拖拽和删除功能

    朋友圈实现原理 我们使用 Android Device Monitor 来分析朋友圈发布图片的界面实现原理.如果需要分析其他应用的界面实现也是采用这种方法哦. 打开 Android Device Mo ...

  5. Android仿微信朋友圈,全文收起功能,附源码

    在众多的社交类软件中,朋友圈是必不可少的,可以与好友.同学等分享自己的日常和有意思的事情,在开发社交类App时,朋友圈发表的内容你不可能让他全部显示,全部显示的话用户体验度会非常不好,这时就要用到全文 ...

  6. Android 仿微信朋友圈查看

    项目要做一个类似于这样的功能,就做了. 项目下载地址:http://download.csdn.net/detail/u014608640/9917626 一,看下效果: 二.activity类 pu ...

  7. Android 高仿微信朋友圈动态, 支持双击手势放大并滑动查看图片。

    转载请注明出处:http://blog.csdn.net/sk719887916/article/details/40348873 作者skay: 最近参与了开发一款旅行APP,其中包含实时聊天和动态 ...

  8. Android NineGridLayout — 仿微信朋友圈和QQ空间的九宫格图片展示自定义控件

    NineGridLayout 一个仿微信朋友圈和QQ空间的九宫格图片展示自定义控件. GitHub:https://github.com/HMY314/NineGridLayout 一.介绍 1.当只 ...

  9. 试用友盟SDK实现Android分享微信朋友圈

    社会化分享是眼下必学且火热的功能.之前有写第三方登录,那仅仅是社会化分享的一部分.今天来玩玩分享微信朋友圈. 为了方便操作,还是依照步骤写. 一,注冊 注冊应用已经在这里具体说明过了,这里就不多提了. ...

随机推荐

  1. Tarjan+LCA【洛谷P2783】 有机化学之神偶尔会做作弊

    [洛谷P2783] 有机化学之神偶尔会做作弊 题目背景 XS中学化学竞赛组教练是一个酷爱炉石的人. 有一天他一边搓炉石一边监考,而你作为一个信息竞赛的大神也来凑热闹. 然而你的化竞基友却向你求助了. ...

  2. 洛谷 P1036 选数

    嗯.... 这种类型的题在新手村出现还是比较正常的, 但是不知道为什么它的分类竟然是过程函数与递归!!!(难道这不是一个深搜题吗??? 好吧这就是一道深搜题,所以千万别被误导... 先看一下题目: 题 ...

  3. Super-Resolution Restoration of MISR Images Using the UCL MAGiGAN System 超分辨率恢复

    作者是伦敦大学学院Mullard空间科学实验室成像组,之前做过对火星图像的分辨率增强. 文章用了许多的图像处理方法获得特征和高分辨率的中间结果,最后用一个生产对抗网络获得更好的高分辨率结果. 用的数据 ...

  4. 图片滚动插件jquery bxslider

    https://www.cnblogs.com/axl234/p/4167196.html

  5. CodeForces - 593A -2Char(思维+暴力枚举)

    Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is th ...

  6. The MathType DLL cannot be found 一劳永逸的方法

    可能会看到下面的情况,然后实际上我们也能用过外部打开直接使用,那要你何用? 于是,我们找到这个文件,删除就OK 反正我写完论文就卸载了...

  7. 回滚revert和reset区别

    分享请标明来自: https://www.css3.io/hui-gun.html 背景 git是一个庞大的工具,我们要开始扫盲一些常用的命令.回滚代码在项目中必然会遇到,下面我们介绍在git中如何回 ...

  8. 如何 将下载离线 nupkg 文件 安装到VS2017

      https://www.cnblogs.com/cncc/articles/8276878.html   --------------------------------------------- ...

  9. ECharts基本设置

    theme = { // 全图默认背景 // backgroundColor: ‘rgba(0,0,0,0)’, // 默认色板 color: ['#ff7f50','#87cefa','#da70d ...

  10. RTT设备与驱动之SPI

    SPI全双工设备的操作分为主设备和从设备(可以多个,多线程下从设备访问主设备要先获得总线控制权) rt_device_t rt_device_find(const char* name);查找设备 s ...