问题描述
我正在尝试通过Android videoview播放视频.这是我的代码:
I am trying to play video by Android videoview. Here is my code:
super.onCreate(savedInstanceState);
setContentView(R.layout.video);
VideoView videoView = (VideoView) findViewById(R.id.videoView);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();
这可以正常工作,但是某些电话仍显示标题为无法播放视频"的对话框.
This works fine, however some phones still show dialog box with title "Cannot play video".
我的问题是如何禁用此通知窗口?我的意思是,我可以在调用videoView.start()之前检查视频文件是否受支持吗?还是可以禁用或阻止调用系统弹出通知窗口?
My question is how to disable this notification window? I mean, can I check if the video file is supported or not before calling videoView.start()? Or can I disable or prevent calling the system popup notification window?
如果电话不支持,我想跳过视频,而没有通知窗口.
I would like to simply skip the video if not supported by the phone, without the notification window.
推荐答案
在启动VideoView之前,我使用setOnErrorListener来检查视频是否可以播放.
I used setOnErrorListener before you start the VideoView to check if video will play.
// Restart if PROBLEM
myVideoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
public boolean onError(MediaPlayer mp, int what, int extra) {
// TODO Auto-generated method stub
Intent intent = getIntent();
overridePendingTransition(0, 0);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
finish();
overridePendingTransition(0, 0);
startActivity(intent);
return true;
}
});
myVideoView.start();
这篇关于如何通过代码检查android videoview是否支持文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!