How to play online videos in Android?

前端 未结 3 1064
忘掉有多难
忘掉有多难 2021-01-02 10:20

I am developing a sample media player app in Android to play online videos, I have developed some code to play videos. It plays video from SD card very well, but I am facing

3条回答
  •  迷失自我
    2021-01-02 10:53

    try like this

     VideoView v;
     MediaController mediaController;
     ProgressDialog progressDialog;
    

    then

    public void playvideo(String videopath) {
        Log.e("entered", "playvide");
        Log.e("path is", "" + videopath);
        try {
            progressDialog = ProgressDialog.show(VideoPlay.this, "",
                    "Buffering video...", false);
            progressDialog.setCancelable(true);
            getWindow().setFormat(PixelFormat.TRANSLUCENT);
    
            mediaController = new MediaController(VideoPlay.this);
    
            Uri video = Uri.parse(videopath);
            v.setMediaController(mediaController);
            v.setVideoURI(video);
    
            v.setOnPreparedListener(new OnPreparedListener() {
    
                public void onPrepared(MediaPlayer mp) {
                    progressDialog.dismiss();
                    v.start();
                }
            });
    
        } catch (Exception e) {
            progressDialog.dismiss();
            System.out.println("Video Play Error :" + e.getMessage());
        }
    
    }
    

    if still has problem "this video cannot be played" try to change video format , hope it will help u.

提交回复
热议问题