中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

android中怎么打開video文件

發布時間:2021-07-19 15:15:29 來源:億速云 閱讀:1187 作者:Leah 欄目:移動開發

本篇文章為大家展示了android中怎么打開video文件,內容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。

先建立錄像窗口 map_video.xml

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" />

android中怎么打開video文件

主類 ArcHFVideo.java

android中怎么打開video文件

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

// 設置計時器不可見

timer.setVisibility(View.GONE);

// 設置緩存路徑

mRecVedioPath = new File(Environment.getExternalStorageDirectory()

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

if (!mRecVedioPath.exists()) {

mRecVedioPath.mkdirs();

}

// 綁定預覽視圖

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

}

/*

* 定時器設置,實現計時

*/

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

}

}

}

};

/*

* 格式化時間

*/

public String format(int i) {

String s = i + "";

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

s = "0" + s;

}

return s;

}

}

android中怎么打開video文件

打開指定路徑的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);

上述內容就是android中怎么打開video文件,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注億速云行業資訊頻道。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

青海省| 祥云县| 盘锦市| 定远县| 南汇区| 土默特右旗| 松原市| 华池县| 界首市| 龙里县| 哈尔滨市| 晋宁县| 达尔| 藁城市| 抚松县| 南阳市| 海原县| 东辽县| 南开区| 磐石市| 昌图县| 吕梁市| 科技| 康乐县| 伊川县| 荣昌县| 浦县| 南康市| 磐安县| 巴楚县| 小金县| 泉州市| 广宗县| 南召县| 和田县| 界首市| 江达县| 紫云| 南部县| 鸡西市| 增城市|