我正在尝试在我的应用中在videoview上运行avi / mp4视频,但当应用程序打开时出现“无法播放此视频”时,我正在我的手机上进行测试。
videoView = (VideoView)findViewById(R.id.videoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.setVideoPath("/sdcard/"+file);
videoView.start();
日志:
03-28 20:52:30.723 8474-8474/mjksites.loopvideo D/MediaPlayer﹕ getMetadata
03-28 20:52:30.842 8474-8491/mjksites.loopvideo W/MediaPlayer﹕ info/warning (3, 0)
03-28 20:52:32.530 8474-8490/mjksites.loopvideo E/MediaPlayer﹕ error (1, -1004)
03-28 20:52:32.538 8474-8474/mjksites.loopvideo E/MediaPlayer﹕ Error (1,-1004)
03-28 20:52:32.538 8474-8474/mjksites.loopvideo D/VideoView﹕ Error: 1,-1004
答案 0 :(得分:0)
Android不支持AVI视频容器格式 - 您看到的消息是您尝试播放不支持的视频格式时会收到的正常消息。
请点击此处查看支持的格式的最新列表:
请注意,您说您正在尝试播放'avi / mp4'视频 - 这是不寻常的,因为AVI和MP4是替代视频容器,因此视频通常是一种格式或其他格式。
更新回答
好的 - 我已经在评论中检查了下面发布的视频,它肯定会在Android 4.4.2设备上播放。
以下代码有效(它播放了您的视频),在您的应用中尝试可能很有用(更新后使用您自己的视图ID,视频路径等)。它用于片段,但如果是您的用例,则可以为活动更改它:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_item_detail, container, false);
//Create the video player and set the video path
videoPlayerView = (VideoView) rootView.findViewById(R.id.video_area);
if (videoPlayerView == null) {
Log.d("ItemDetailFragment","onCreateView: videoPlayerView is null");
return null;
}
//Set the video path and make sure the first frame is shown instead of a black screen
videoPlayerView.setVideoPath(selectedVideoItem.videoPath);
videoPlayerView.seekTo(100);
//Set the MediaController (the video control bar) to match the size of the VideoView - this trick
//from a StackOverflow answer makes sure it is sized correctly, calling setAnchroView after the
//Video is actually loaded and hence knows it right sze.
final Context mContext = this.getActivity();
videoPlayerView.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
//Add a listener for the size change to correctly set the controls
mp.setOnVideoSizeChangedListener(new OnVideoSizeChangedListener() {
@Override
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
//Add Media Controller and set its position on the screen.
mediaController = new MediaController(mContext);
videoPlayerView.setMediaController(mediaController);
mediaController.setAnchorView(videoPlayerView);
}
});
}
});
return rootView;
}
此外,请确保您的应用有权读取外部存储空间,因为媒体播放器错误有时是由潜在问题引起的,并且没有非常有用的报告。以下行应该在您的清单中:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />