从URL流式传输视频并在VideoView中显示

时间:2017-03-31 08:15:24

标签: android video video-streaming android-videoview

我从“网址”流式传输视频几乎没有问题。 我正在使用“Camera Streaming”应用程序打开相机并给我一个像“192.168.0。??:8080”这样的网址。 我可以在我的电脑上在浏览器中传输该视频。

现在我的问题是如何将我的应用中的视频流式传输到VideoView

我尝试使用“setVideoURI()”在videoview中打开视频,但它说“无法播放此视频”。并在logcat中给我错误,如:

1)D / VideoView:错误:1,-2147483648

2)E / MediaPlayer:错误(1,-2147483648)

3)D / MediaPlayer:无法在客户端打开文件,尝试服务器端

你能帮我在VideoView中播放视频吗?

提前致谢! Darshan Popat

1 个答案:

答案 0 :(得分:0)

试试这段代码,这是出色的工作:

public class PlayVideo extends Activity
{


 private String videoPath ="url";

 private static ProgressDialog progressDialog;
 String videourl;  
    VideoView videoView ;


 protected void onCreate(Bundle savedInstanceState)
 {

  super.onCreate(savedInstanceState);
  setContentView(R.layout.play_video);

   videoView = (VideoView) findViewById(R.id.videoView);


   progressDialog = ProgressDialog.show(PlayVideo.this, "", "Buffering video...", true);
   progressDialog.setCancelable(true);  


      PlayVideo();

 }
 private void PlayVideo()
 {
  try
       {      
              getWindow().setFormat(PixelFormat.TRANSLUCENT);
              MediaController mediaController = new MediaController(PlayVideo.this);
              mediaController.setAnchorView(videoView);           

               Uri video = Uri.parse(videoPath );             
               videoView.setMediaController(mediaController);
               videoView.setVideoURI(video);
               videoView.requestFocus();              
               videoView.setOnPreparedListener(new OnPreparedListener()
               {

                   public void onPrepared(MediaPlayer mp)
                   {                  
                       progressDialog.dismiss();     
                       videoView.start();
                   }
               });           


            }
       catch(Exception e)
       {
                progressDialog.dismiss();
                System.out.println("Video Play Error :"+e.toString());
                finish();
       }   

 }
}