-1

I am trying to run a avi/mp4 video on the videoview in my app, but when the app open appears "can't play this video", i am testing on my mobile.

videoView = (VideoView)findViewById(R.id.videoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.setVideoPath("/sdcard/"+file);
videoView.start();

The log:

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
Matheus Weber
  • 194
  • 2
  • 3
  • 14

1 Answers1

0

Android does not support the AVI video container format - the message you are seeing is the normal message you would get when you try to play an unsupported video format.

See here for the up to date list of supported formats:

Note that you say you are trying to play an 'avi/mp4' video - this is unusual as AVI and MP4 are alternative video containers, so a video would normally be one format or there other.

Updated answer

Ok - I have checked the video posted below in the comments and it will definitely play on an Android 4.4.2 device.

The following code works (it played your video) and may be useful to try in your app (updated to use your own view id, video path etc). It is for use in a fragment, but you can change it for an activity if that is your use case:

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;
}

Also, make sure your app has permission to read external storage as media player errors are sometimes caused by underlying problems and not very helpfully reported. The following line should be in your manifest:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Massimiliano Kraus
  • 3,638
  • 5
  • 27
  • 47
Mick
  • 24,231
  • 1
  • 54
  • 120
  • I mean a AVI or a MP4 video, not one video with both formats. – Matheus Weber Mar 28 '15 at 23:25
  • Well, the AVI will give the error message but videos using an mp4 'contaner' should play so long as they match the details in the link above. One thing to check is the 'profile' of the video - is it baseline which is supported, or something else, e.g. mainline, which is not included in the list at the link. If you are able to share the mp4 video which does not play that would help. – Mick Mar 29 '15 at 00:52
  • As an aside - have you checked the path to the video is correct? I'm not sure the one above would actually get to the SD card on devices I have used. The usual path to a video you save on the SD card is: Environment.getExternalStorageDirectory() + videoFileName; – Mick Mar 29 '15 at 00:56
  • This is the video: http://www.ebookfrenzy.com/android_book/movie.mp4 , it is funny because when i put the url to play, it plays correctly, but when i download the movie and try to play, dont work. And unfortunately i have to download the video before. – Matheus Weber Mar 29 '15 at 19:30
  • 03-29 20:34:23.159 15295-15312/mjksites.loopvideo W/MediaPlayer﹕ info/warning (3, 0) 03-29 20:34:27.215 15295-15312/mjksites.loopvideo E/MediaPlayer﹕ error (1, -1004) 03-29 20:34:27.218 15295-15295/mjksites.loopvideo E/MediaPlayer﹕ Error (1,-1004) 03-29 20:34:27.218 15295-15295/mjksites.loopvideo D/VideoView﹕ Error: 1,-1004 03-29 20:34:55.651 15295-15295/mjksites.loopvideo D/MediaPlayer﹕ getMetadata 03-29 20:34:55.703 15295-15312/mjksites.loopvideo W/MediaPlayer﹕ info/warning (3, 0) – Matheus Weber Mar 29 '15 at 19:35