我正在开发在Android中样本的媒体播放器应用程序来播放在线视频,我已经开发了一些code播放视频。它可以播放从SD卡的视频非常好,但我面临两个问题,在这方面。
1,当我打开在线视频应用程序它显示了视频,但不能播放视频,一段时间后,它会显示一个警告对话框有消息很抱歉,此视频无法播放。
2 - 我有$ C $下进度条,但我不知道放在哪里code当视频从互联网上下载。
下面是我的code,你可以检查它。先谢谢了。
myVideoView =(VideoView)findViewById(R.id.surface_view);
尝试
{
myVideoView.setVideoURI(Uri.parse(http://www.MY_DOMAIN_NAME.com/videos/video1.mp4));
myVideoView.setMediaController(新的MediaController(本));
myVideoView.requestFocus();
myVideoView.start();
}
赶上(例外五)
{
Toast.makeText(getApplicationContext(),没有媒体发现,Toast.LENGTH_LONG).show();
}
解决方案
试试这样
VideoView伏;
的MediaController的MediaController;
ProgressDialog progressDialog;
然后
公共无效的playVideo(字符串将videoPath){
Log.e(输入,playvide);
Log.e(路径,+将videoPath);
尝试 {
progressDialog = ProgressDialog.show(VideoPlay.this,,
缓冲视频...,假);
progressDialog.setCancelable(真正的);
。getWindow()和setFormat(PixelFormat.TRANSLUCENT);
的MediaController =新的MediaController(VideoPlay.this);
乌里视频= Uri.parse(将videoPath);
v.setMediaController(的MediaController);
v.setVideoURI(视频)
v.setOn preparedListener(新在preparedListener(){
公共无效于prepared(MediaPlayer的MP){
progressDialog.dismiss();
v.start();
}
});
}赶上(例外五){
progressDialog.dismiss();
的System.out.println(视频播放错误:+ e.getMessage());
}
}
如果仍然有问题,该视频无法播放 尝试改变视频格式,希望这将帮助ü。
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 two issues in this respect.
1- when I open the app for online videos it shows the video but it does not play the video and after a while it displays an alert dialog having message "Sorry, this video cannot be played".
2- I have code for "Progress bar", but I don't know where to put the code when the video is downloading from the internet.
Here is my code you can check it. Thanks in advance.
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();
}
解决方案
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.