我有一个videoView,我想在其中显示来自URL的MP4视频。我在Andoird 4.0.2模拟器上尝试过,它工作正常。但是,在使用GingerBread硬件时尝试它,它崩溃了。我也尝试过姜饼模拟器,认为我的设备可能有问题,但仍然没有进展。当我点击“播放”按钮时,logcat会一次又一次地重复这些。
04-11 23:49:27.438: V/VideoViewDemo(413): path: http://173.193.24.66/~kanz/video/mp4/9.mp4
04-11 23:49:28.796: D/MediaPlayer(413): Couldn't open file on client side, trying server side
04-11 23:49:38.207: D/MediaPlayer(413): getMetadata
04-11 23:49:39.343: W/MediaPlayer(413): info/warning (701, 0)
04-11 23:49:39.346: I/MediaPlayer(413): Info (701,0)
04-11 23:49:45.556: W/MediaPlayer(413): info/warning (702, 0)
04-11 23:49:45.556: I/MediaPlayer(413): Info (702,0)
04-11 23:51:11.467: W/MediaPlayer(413): info/warning (701, 0)
04-11 23:51:11.467: I/MediaPlayer(413): Info (701,0)
04-11 23:51:22.096: W/MediaPlayer(413): info/warning (702, 0)
04-11 23:51:22.096: I/MediaPlayer(413): Info (702,0)
04-11 23:51:25.636: W/MediaPlayer(413): info/warning (701, 0)
04-11 23:51:25.636: I/MediaPlayer(413): Info (701,0)
04-11 23:51:37.127: W/MediaPlayer(413): info/warning (702, 0)
04-11 23:51:37.127: I/MediaPlayer(413): Info (702,0)
04-11 23:51:41.717: W/MediaPlayer(413): info/warning (701, 0)
04-11 23:51:41.717: I/MediaPlayer(413): Info (701,0)
04-11 23:51:54.086: W/MediaPlayer(413): info/warning (702, 0)
04-11 23:51:54.097: I/MediaPlayer(413): Info (702,0)
它没有显示任何错误,因此我可以知道哪条线正是导致问题的原因。这是Play按钮的代码:
try {
final String path = mPath.getText().toString();
Log.v(TAG, "path: " + path);
if (path == null || path.length() == 0) {
Toast.makeText(MainActivity.this, "File URL/path is empty",
Toast.LENGTH_LONG).show();
} else {
// If the path has not changed, just start the media player
if (path.equals(current) && mVideoView != null) {
mVideoView.setVideoURI(Uri.parse("http://173.193.24.66/~kanz/video/mp4/9.mp4"));
mVideoView.requestFocus();
mVideoView.start();
return;
}
current = path;
mVideoView.setVideoURI(Uri.parse(getDataSource(path)));
mVideoView.requestFocus();
mVideoView.start();
}
} catch (Exception e) {
Log.e(TAG, "error: " + e.getMessage(), e);
if (mVideoView != null) {
mVideoView.stopPlayback();
}
}
}
任何帮助都将受到高度赞赏。感谢。
答案 0 :(得分:0)
您可能想尝试此代码,
String videoSource = "http://173.193.24.66/~kanz/video/mp4/9.mp4";
myVideoView.setMediaController(new MediaController(this));
myVideoView.setVideoPath(videoSource);
myVideoView.requestFocus();
myVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
myVideoView.start();
}
});