自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

android錄像/打開(kāi)video文件

移動(dòng)開(kāi)發(fā) Android
本文將講述android錄像/打開(kāi)video文件的方法,希望這些代碼對(duì)各位有用。

先建立錄像窗口 map_video.xml

 

[[73532]]

 

android:layout_width="fill_parent"

android:layout_height="fill_parent" >

 

android:id="@+id/arc_hf_video_view"

android:layout_width="fill_parent"

android:layout_height="fill_parent" />

 

android:id="@+id/arc_hf_video_timer"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_margin="40dp"

android:textColor="#ffff0000"

android:textSize="35dp"

android:textStyle="bold" >

 

 

android:id="@+id/arc_hf_video_btn"

android:layout_width="wrap_content"

android:layout_height="fill_parent"

android:layout_alignParentRight="true"

android:gravity="center"

android:orientation="vertical" >

 

android:id="@+id/arc_hf_video_start"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@drawable/arc_hf_video_start" />

 

android:id="@+id/arc_hf_video_return"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@drawable/arc_hf_video_return" />

 

 

 

[[73532]]

 

主類(lèi) ArcHFVideo.java

 

[[73532]]

 

public class ArcHFVideo extends Activity implements SurfaceHolder.Callback {

private Button mVideoStartBtn, mVideoReturnBtn;

private SurfaceView mSurfaceview;

private MediaRecorder mMediaRecorder;

private SurfaceHolder mSurfaceHolder; //

private File mRecVedioPath;

private File mRecAudioFile;

private TextView timer;

private int hour = 0;

private int minute = 0;

private int second = 0;

private boolean bool;

private int parentId;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

WindowManager.LayoutParams.FLAG_FULLSCREEN);

getWindow().setFormat(PixelFormat.TRANSLUCENT);

setContentView(R.layout.map_video);

parentId = getIntent().getIntExtra("parentId", 0);

timer = (TextView) findViewById(R.id.arc_hf_video_timer);

mVideoStartBtn = (Button) findViewById(R.id.arc_hf_video_start);

mVideoReturnBtn = (Button) findViewById(R.id.arc_hf_video_return);

mSurfaceview = (SurfaceView) this.findViewById(R.id.arc_hf_video_view);

// 設(shè)置計(jì)時(shí)器不可見(jiàn)

timer.setVisibility(View.GONE);

// 設(shè)置緩存路徑

mRecVedioPath = new File(Environment.getExternalStorageDirectory()

.getAbsolutePath() + "/hfdatabase/temp/");

if (!mRecVedioPath.exists()) {

mRecVedioPath.mkdirs();

}

// 綁定預(yù)覽視圖

SurfaceHolder holder = mSurfaceview.getHolder();

holder.addCallback(ArcHFVideo.this);

holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

mVideoStartBtn.setOnClickListener(new Button.OnClickListener() {

private boolean isRecording = true;

@Override

public void onClick(View v) {

Drawable iconStart = getResources().getDrawable(

R.drawable.arc_hf_video_start);

Drawable iconStop = getResources().getDrawable(

R.drawable.arc_hf_video_stop);

if (isRecording) {

mVideoStartBtn.setBackgroundDrawable(iconStop);

bool = true;

if (mMediaRecorder == null)

mMediaRecorder = new MediaRecorder();

else

mMediaRecorder.reset();

mMediaRecorder.setPreviewDisplay(mSurfaceHolder

.getSurface());

mMediaRecorder

.setVideoSource(MediaRecorder.VideoSource.CAMERA);

mMediaRecorder

.setAudioSource(MediaRecorder.AudioSource.MIC);

mMediaRecorder

.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);

mMediaRecorder

.setVideoEncoder(MediaRecorder.VideoEncoder.H264);

mMediaRecorder

.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

mMediaRecorder.setVideoSize(176, 144);

mMediaRecorder.setVideoFrameRate(15);

try {

mRecAudioFile = File.createTempFile("Vedio", ".3gp",

mRecVedioPath);

} catch (IOException e1) {

e1.printStackTrace();

}

mMediaRecorder.setOutputFile(mRecAudioFile

.getAbsolutePath());

try {

mMediaRecorder.prepare();

timer.setVisibility(View.VISIBLE);

handler.postDelayed(task, 1000);

mMediaRecorder.start();

} catch (Exception e) {

e.printStackTrace();

}

isRecording = !isRecording;

} else {

mVideoStartBtn.setBackgroundDrawable(iconStart);

if (mMediaRecorder != null) {

mMediaRecorder.stop();

bool = false;

timer.setText(format(hour) + ":" + format(minute) + ":"

+ format(second));

mMediaRecorder.release();

mMediaRecorder = null;

audioRename();

}

isRecording = !isRecording;

}

}

});

mVideoReturnBtn.setOnClickListener(new Button.OnClickListener() {

@Override

public void onClick(View v) {

if (mMediaRecorder != null) {

mMediaRecorder.stop();

mMediaRecorder.release();

mMediaRecorder = null;

}

audioRename();

finish();

}

});

}

@Override

public void surfaceCreated(SurfaceHolder holder) {

mSurfaceHolder = holder;

}

@Override

public void surfaceChanged(SurfaceHolder holder, int format, int width,

int height) {

mSurfaceHolder = holder;

}

@Override

public void surfaceDestroyed(SurfaceHolder holder) {

mSurfaceview = null;

mSurfaceHolder = null;

mMediaRecorder = null;

}

/*

* 生成Audio文件名字

*/

protected void audioRename() {

String path = Environment.getExternalStorageDirectory()

.getAbsolutePath()

+ "/hfdatabase/video/"

+ String.valueOf(parentId) + "/";

String fileName = new SimpleDateFormat("yyyyMMddHHmmss")

.format(new Date()) + ".3gp";

File out = new File(path);

if (!out.exists()) {

out.mkdirs();

}

out = new File(path, fileName);

mRecAudioFile.renameTo(out);

}

/*

* 定時(shí)器設(shè)置,實(shí)現(xiàn)計(jì)時(shí)

*/

private Handler handler = new Handler();

private Runnable task = new Runnable() {

public void run() {

if (bool) {

handler.postDelayed(this, 1000);

second++;

if (second < 60) {

timer.setText(format(second));

} else if (second < 3600) {

minute = second / 60;

second = second % 60;

timer.setText(format(minute) + ":" + format(second));

} else {

hour = second / 3600;

minute = (second % 3600) / 60;

second = (second % 3600) % 60;

timer.setText(format(hour) + ":" + format(minute) + ":"

+ format(second));

}

}

}

};

/*

* 格式化時(shí)間

*/

public String format(int i) {

String s = i + "";

if (s.length() == 1) {

s = "0" + s;

}

return s;

}

}

 

[[73532]]

 

打開(kāi)指定路徑的video文件

File f = new File(filePath);

Intent intent = new Intent();

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

intent.setAction(android.content.Intent.ACTION_VIEW);

intent.setDataAndType(Uri.fromFile(f), "video/*");

startActivity(intent);

【編輯推薦】

  1. 91分析Android與IOS游戲及軟件下載比例數(shù)據(jù)
  2. Android程序開(kāi)發(fā)的環(huán)境配置
  3. Android程序開(kāi)發(fā)基礎(chǔ)之——頁(yè)面?zhèn)髦?/a>
責(zé)任編輯:冰凝兒 來(lái)源: 博客園
相關(guān)推薦

2009-06-19 16:42:00

Java語(yǔ)言

2021-01-11 08:00:00

工具軟件視頻

2009-03-22 10:52:36

CCNA屏幕錄像視頻

2021-11-17 22:16:01

Windows 17Windows微軟

2009-12-16 10:10:16

Ruby打開(kāi)關(guān)閉文件

2011-07-26 11:08:23

iOS 錄像 錄音

2017-01-11 10:57:29

video使用JS庫(kù)

2023-04-07 08:32:31

模塊Python

2010-10-14 16:18:21

MySQL表鎖情況

2010-07-21 09:57:46

Perl文件

2009-07-07 08:51:00

微軟Windows 7新功能

2016-09-27 16:23:51

向日葵Android6.5

2021-11-26 09:10:19

Linux文件命令

2023-11-22 11:22:57

AI模型

2012-05-03 09:51:09

HTML5

2010-09-10 10:04:37

Android NDKAndroid

2011-03-08 15:08:29

羅技科技高清視頻串流

2022-10-24 07:55:31

2022-05-09 14:44:50

修復(fù)工具包office

2016-09-29 22:36:40

點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)