流与videoview视频 [英] Streaming video with videoview

查看:237
本文介绍了流与videoview视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的$下面的视频流C $ C:

My code below to streaming video:

VideoView vv = (VideoView)this.findViewById(R.id.screen_video);
Uri uri = Uri.parse(URL);
vv.setVideoURI(uri);
vv.start();

它的工作原理。 但是,如果该URL的视频的格式不是由Android手机或垫支持。 它显示一个对话框,并且不显示在屏幕上。 但它仍然流着黑色的屏幕。 我希望得到错误信息,并获得作为一个例外。 但我不知道如何得到它?

It works. But if the URL video's format not support by android phone or pad. It show a dialog, and not show the screen. But it still streaming with black screen. I want to get the error message, and access as an exception. But I don't know how to get it?

的另一个问题是,该流可通过低速无线崩溃原因。 如何检查等,而低转速的WiFi?

Another problem is that the streaming may crash cause by low speed wifi. How to check it to wait while low speed wifi?

推荐答案

试试这个code,它的工作,

try this code,it work,

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

 }
}

这篇关于流与videoview视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆