我从VideoView下载了一段视频。视频工作正常,但未在屏幕上显示。
其他问题是,如果我使用.3gp视频,那么它工作正常,但如果我使用.mp4视频,那么它会减慢。
以下是我的代码:
public class MyActivity extends Activity implements View.OnClickListener {
/**
* Called when the activity is first created.
*/
public Button btn;
public VideoView vv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn = (Button) findViewById(R.id.button);
btn.setOnClickListener(this);
vv = (VideoView) findViewById(R.id.videoView);
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.button:
vv.setVideoURI(Uri.parse("http://m.ochepyatki.ru/video.php?vkey=6991aa4&f=21395228200"));
vv.setMediaController(new MediaController(this));
vv.requestFocus(0);
vv.start();
break;
}
}
}
答案 0 :(得分:0)
1)用以下代码替换vv.setMediaController(new MediaController(this));
:
MediaController mediaCtrl = new MediaController(this);
mediaCtrl.setMediaPlayer(vv);
vv.setMediaController(mediaCtrl);
2)用以下代码替换vv.start()
:
vv.setOnPreparedListener(new OnPreparedListener()
{
public void onPrepared(MediaPlayer mp)
{
mp.start();
}
});