@H_403_1@我正在
Android中开发一个示例媒体播放器应用程序来播放在线视频,我已经开发了一些代码来播放视频.它很好地播放SD卡的视频,但我在这方面面临两个问题.
1-当我打开在线视频的应用程序时,它会显示视频,但它不播放视频,过了一会儿它会显示一条警告对话框,上面写着“抱歉,此视频无法播放”.
2-我有“进度条”的代码,但我不知道从互联网下载视频时将代码放在何处.
这是我的代码,你可以检查它.提前致谢.
myVideoView = (VideoView) findViewById(R.id.surface_view); try { myVideoView.setVideoURI(Uri.parse("http://www.MY_DOMAIN_NAME.com/videos/video1.mp4")); myVideoView.setMediaController(new MediaController(this)); myVideoView.requestFocus(); myVideoView.start(); } catch(Exception e) { Toast.makeText(getApplicationContext(),"No Media found",Toast.LENGTH_LONG).show(); }
解决方法
试试这样
VideoView v; MediaController mediaController; ProgressDialog progressDialog;
然后
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()); } }
如果仍有问题“此视频无法播放”尝试改变视频格式,希望它能帮到你.