努力在Android中使用VideoView播放URL视频

时间:2016-12-09 09:30:48

标签: android video

您好我在我的应用程序中使用VideoView来播放网址视频

但使用我的以下代码网址视频并未正确缓冲 并坚持玩 请帮助我如何完美地播放URL视频

需要遵循异步流程,请用一些代码解释我

代码: -

public class MainActivity extends AppCompatActivity {

    ProgressBar progressBar = null;
    VideoView mVideoView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        progressBar = (ProgressBar) findViewById(R.id.progressbar);
        mVideoView = (VideoView) findViewById(R.id.videoView1);
        progressBar.setVisibility(View.VISIBLE);

        MediaController mediaController = new MediaController(this);
        mediaController.setAnchorView(mVideoView);
        Uri video = Uri.parse("http://www.ebookfrenzy.com/android_book/movie.mp4");

        mVideoView.setMediaController(mediaController);
        mVideoView.setVideoURI(video);

        mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

            public void onPrepared(MediaPlayer arg0) {
                progressBar.setVisibility(View.GONE);
                mVideoView.start();
            }
        });

    }
}

2 个答案:

答案 0 :(得分:0)

你可以试试这个,你错过了对VideoView的请求焦点

public class MainActivity extends AppCompatActivity {
    ProgressBar progressBar = null;
    VideoView mVideoView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        progressBar = (ProgressBar) findViewById(R.id.progressbar);
        mVideoView = (VideoView) findViewById(R.id.videoView1);
        progressBar.setVisibility(View.VISIBLE);

        MediaController mediaController = new MediaController(this);
        mediaController.setAnchorView(mVideoView);
        Uri video = Uri.parse("http://www.ebookfrenzy.com/android_book/movie.mp4");

        mVideoView.setMediaController(mediaController);
        mVideoView.setVideoURI(video);
       // Request focus was missing         
        videoview.requestFocus();
        mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

            public void onPrepared(MediaPlayer arg0) {
                progressBar.setVisibility(View.GONE);
                mVideoView.start();
            }
        });

    } }

答案 1 :(得分:0)

我的建议是第一次下载视频,如下所示,

我的建议是第一次下载视频,如下所示,

- Class: text
  Output: "Welcome to Part 1\nPlaying with Numbers!!!"

然后从外部存储开始播放