14

Here is my videoview code :

    Uri uri = Uri.parse(vidurl);
    MediaController mediaController = new MediaController(this);
    videoView.setMediaController(mediaController);
    videoView.requestFocus();
    videoView.setVideoURI(uri);

    videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mp) {
            videoView.start();
        }
    });

Videos I try to play are stored in my server. They are sent there from the same app, using a custom camera. Here is video capturing parameters: ( Just in case something were wrong with those , I tried every combination, VP8 Format did stream , except the output had no audio and was rotated sideways)

    mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);

    if (currentCameraId == Camera.CameraInfo.CAMERA_FACING_BACK) {
        mMediaRecorder.setOrientationHint(90);
    } else {
        mMediaRecorder.setOrientationHint(270);
    }

    mMediaRecorder.setVideoSize(list.get(sizex).width, list.get(sizex).height);
    mMediaRecorder.setVideoEncodingBitRate(1500000);
    mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
    mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
    mMediaRecorder.setVideoFrameRate(30);
    mMediaRecorder.setMaxDuration(15000);
    mMediaRecorder.setOutputFile(getVidFile().getAbsolutePath());

I've been trying to solve this for a long time but I am out of ideas now. I would like to stream those videos in a videoview. But instead of that , I have to wait 10-20 seconds. After that ,either video starts or it gives me an error that video can't be played.

Additional information:

Project minimum sdk is 18 , but I can change it if that will help.

My testing device is Asus Zenfone 2 (5.0)

I didn't test with any other device

Videos are stored in godaddy linux host. www.mydomain.com/videos/

Video encoding is h264 Baseline Profile

Moov atom is at top ( after fytp(or something like that) ) just as recommended

I tried using third party video player libraries like exomedia

Some videos do work , for example :

http://www.html5videoplayer.net/videos/toystory.mp4

I checked that videos encoding. It's encoded in h264 MAIN PROFILE ( from my research , main profile isn't supported for most of android devices , baseline profile is recommended instead) AND MOOV ATOM IS AT LAST POSITION. But this video plays just fine... dafuq?

EDIT:Properties of that toystory video which works:

1

2

And here is a video captured from my app with parameteres given above(notice the moov atom is at right place, but this still doesn't work )

3

4

ManoDestra
  • 6,325
  • 6
  • 26
  • 50
  • Any error you find out ?? Instead of videoview.start() use mp.start() – Yogesh Rathi Aug 12 '16 at 17:41
  • 1
    Now I tried using mediplayer using a surfaceview and not forgetting to call prepareasync instead of prepare () , still didn't work. E/MediaPlayer: Error (1,-2147483648) –  Aug 13 '16 at 04:22

1 Answers1

1

Which network protocol is used when your video is streamed from server to app? Perhaps the network protocol you are using is not supported by VideoView. VideoView only supports limited protocols. According to android documents on "Supported media formats":

The following network protocols are supported for audio and video playback:

--RTSP (RTP, SDP)

--HTTP/HTTPS progressive streaming --HTTP/HTTPS live streaming draft protocol:

MPEG-2 TS media files only

Protocol version 3 (Android 4.0 and above)

Protocol version 2 (Android 3.x)

Not supported before Android 3.0

--Note: HTTPS is not supported before Android 3.1.

  • I don't know what is a network protocol. How do I check which one I'm using? –  Aug 18 '16 at 06:55
  • After examing your question again, I think the network protocol used is Progressive http.That should not be a problem. There are questions similar to yours :http://stackoverflow.com/questions/11540076/android-mediaplayer-error-1-2147483648 and http://stackoverflow.com/questions/4728085/cannot-play-certain-videos. Their answers metioned "For 3GPP and MPEG-4 containers, the moov atom must precede any mdat atoms, but must succeed the ftyp atom." In your question ,you mentioned your configuraiont is "Moov atom is at top ( after fytp(or something like that) )" .Maybe that is the problem. – Fenny Sunshine Aug 19 '16 at 06:12
  • according to this : http://www.adobe.com/devnet/video/articles/mp4_movie_atom.html my moov atom is at correct position –  Aug 19 '16 at 11:37