があるアクティビティがありVideoView
ます。URLから動画を再生しています。私がやっていることは、スムーズにプレイするためProgressDialog
であり、アクティビティの開始時に を付けました。onPreparedListener
そして、それがうまくスムーズに再生されるように、内部でそれを却下します。しかし、それでも役に立ちません。ビデオは 10 ~ 20 秒間再生するように再生され、5 ~ 10 秒間停止し、継続します。Google Play Workout Trainerでアプリケーションを見たことがあります。このアプリケーションでは、ユーザーがビデオを見始めると、ビデオhorizontal progress bar
がバッファリングされ、接続が遅いか WI-FI かに関係なくスムーズに再生されます。progressbar
ビデオを開始する前にそれを完了するだけで済みます。私のアプリケーションで同じことを実装する方法を知りたいですか?
私がやっていることは以下です:
public class StartExerciseActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.show_exercise);
tileTextView = (TextView) findViewById(R.id.titleText);
timerTextView = (TextView) findViewById(R.id.timertxt);
timerRemainTextView = (TextView) findViewById(R.id.timeremaintxt);
videoView = (VideoView) findViewById(R.id.video_view);
stopButton = (Button) findViewById(R.id.stopbut);
pauseButton = (Button) findViewById(R.id.pausesbut);
progressDialog = ProgressDialog.show(StartExerciseActivity.this, "",
"Buffering video...", true);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
tileTextView.setText(Constant.NEWS_TITLE);
timerTextView.setText(Constant.VIDEO_TIME);
video_url = Constant.VIDEO_NAME;
try {
Uri video = Uri.parse(video_url);
// videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
progressDialog.dismiss();
videoView.start();
updateSeekProgress();
RelativeLayout.LayoutParams videoviewlp = new RelativeLayout.LayoutParams(400, 400);
videoviewlp.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
videoviewlp.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
videoView.setLayoutParams(videoviewlp);
videoView.invalidate();
// DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics);
// android.widget.LinearLayout.LayoutParams params = (android.widget.LinearLayout.LayoutParams) videoView.getLayoutParams();
// params.width = metrics.widthPixels;
// params.height = metrics.heightPixels;
// params.leftMargin = 0;
// videoView.setLayoutParams(params);
}
});
} catch (Exception e) {
progressDialog.dismiss();
System.out.println("Video Play Error :" + e.getMessage());
}
pauseButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
if (count == 0) {
videoView.pause();
count = 1;
pauseButton.setBackgroundResource(R.drawable.playbut);
} else if (count == 1) {
videoView.start();
pauseButton.setBackgroundResource(R.drawable.pausebut);
count = 0;
}
}
});
stopButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
videoView.stopPlayback();
pauseButton.setBackgroundResource(R.drawable.playbut);
}
});
}
助けてください。ありがとう。