Temp



mv录音考虑:
1,播放完成后要直接保存录音
2,要自定义videoView,可以适应屏幕宽度:
public class MyVideo extends VideoView {


public MyVideo(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) 
{
  int width = getDefaultSize(0, widthMeasureSpec);
  int height = getDefaultSize(0, heightMeasureSpec);
  setMeasuredDimension(width , height);
}
}
3,在onpause界面写暂停音频和视频的操作。

4,录音文件跟原音频文件放在同一个目录下,并用同一个格式(.ACC)



package com.example.mediaplayerdemo;

import java.io.File;
import java.io.IOException;
import java.util.Locale;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.VideoView;

public class MainActivity extends Activity implements OnClickListener {

	private VideoView videoView;
	private Button back;
	private Button reRecord;
	private Button save;
	private TextView time;
	private String videoPath;
	private String audioPath;
	private File path_video;
	private File path_audio;
	private MediaPlayer mediaPlayer;
	private String totalTime;
	private String currentTime;
	private Handler handler = new Handler();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		System.out.println("onCreate");
		setContentView(R.layout.activity_main);
		videoView = (VideoView) findViewById(R.id.videoView);
		back = (Button) findViewById(R.id.back);
		reRecord = (Button) findViewById(R.id.reRecord);
		save = (Button) findViewById(R.id.save);
		time = (TextView) findViewById(R.id.time);
		File dir = Environment.getExternalStorageDirectory();
		path_video = new File(dir, "TAS_Demo/downSongs/62350Z1.mp4");
		path_audio = new File(dir, "TAS_Demo/downSongs/62350Z1.aac");
		videoPath = path_video.getAbsolutePath();
		audioPath = path_audio.getAbsolutePath();
		play();
	}

	@Override
	protected void onPause() {
		super.onPause();
		System.out.println("onPause");
		if (videoView.isPlaying()) {
			videoView.pause();
		}
		if (mediaPlayer != null && mediaPlayer.isPlaying()) {
			mediaPlayer.pause();
		}
	}

	private String parseMillisecond(int Millisecond) {
		return String.format(new Locale("ZH", "CN"), "%02d:%02d",
				Millisecond / 1000 / 60, (Millisecond / 1000) % 60);
	}

	private void play() {
		if (path_video.exists() && path_audio.exists()) {
			try {
				videoView.setVideoPath(videoPath);
				videoView.requestFocus();
				mediaPlayer = new MediaPlayer();
				mediaPlayer.setDataSource(audioPath);
				mediaPlayer.prepare();
				videoView.start();
				mediaPlayer.start();
				totalTime = parseMillisecond(mediaPlayer.getDuration());
				// totalTime=parseMillisecond(videoView.getDuration());
				handler.post(new Runnable() {

					@Override
					public void run() {
						if (videoView != null && mediaPlayer != null) {
							currentTime = parseMillisecond(mediaPlayer
									.getCurrentPosition());
							// currentTime=parseMillisecond(videoView.getCurrentPosition());
							time.setText(currentTime + "/" + totalTime);
							handler.postDelayed(this, 1000);
						}
					}
				});
			} catch (Exception e) {
				e.printStackTrace();
			}

		}
	}

	@Override
	public void onClick(View v) {

	}

}




    public class Utility {
        public static void setListViewHeightBasedOnChildren(ListView listView) {
            ListAdapter listAdapter = listView.getAdapter(); 
            if (listAdapter == null) {
                // pre-condition
                return;
            }


            int totalHeight = 0;
            for (int i = 0; i < listAdapter.getCount(); i++) {
                View listItem = listAdapter.getView(i, null, listView);
                listItem.measure(0, 0);
                totalHeight += listItem.getMeasuredHeight();
            }


            ViewGroup.LayoutParams params = listView.getLayoutParams();
            params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
            listView.setLayoutParams(params);
        }
    }



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值