我无法在VideoView中全屏输出视频

时间:2014-03-20 04:04:22

标签: java android

我从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;
        }
    }
}

1 个答案:

答案 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();
    }
});