VideoView Stream load not buffering enough
Asked Answered
F

4

6

my android app streams a video online in a VideoView. When playing a video from a file, it works fine, or even streaming live (an m3u8); It's always streaming from the same source, and when I use an external player/browser, it likewise streams fine (so I don't think this is an issue with the source, which is a variation of a file like this: https://publish.dvlabs.com/democracynow/360/dn2016-0810.mp4

The Android Monitor logs this just before the crash:

10-13 12:02:56.204 32460-32748/com.workingagenda.democracydroid D/MediaHTTPConnection: filterOutInternalHeaders: key=User-Agent, val= stagefright/1.2 (Linux;Android 6.0.1)
10-13 12:02:56.205 32460-32472/com.workingagenda.democracydroid D/MediaHTTPConnection: proxy null port 0
10-13 12:02:57.904 32460-32460/com.workingagenda.democracydroid D/MediaPlayer: getMetadata
10-13 12:02:58.438 32460-377/com.workingagenda.democracydroid W/MediaPlayer: info/warning (3, 0)

and then I get these logs when it crashes:

10-13 12:05:33.812 32460-32472/com.workingagenda.democracydroid W/MediaHTTPConnection: readAt 26869519 / 241 => java.net.ProtocolException: unexpected end of stream
10-13 12:08:32.480 32460-3546/com.workingagenda.democracydroid E/MediaPlayer: error (1, -1004)
10-13 12:08:32.480 32460-32460/com.workingagenda.democracydroid E/MediaPlayer: Error (1,-1004)
10-13 12:08:32.481 32460-32460/com.workingagenda.democracydroid D/VideoView: Error: 1,-1004

                                                                         [ 10-13 12:08:32.512  5066:  453 E/         ]
                                                                         Destroy C2D instance

                                                                         [ 10-13 12:08:32.512  5066:  453 E/         ]
                                                                         Destroy C2D instance
10-13 12:08:32.635 32460-32472/com.workingagenda.democracydroid E/MediaPlayer: error (1, -1004)
10-13 12:08:32.668 32460-32460/com.workingagenda.democracydroid E/MediaPlayer: Error (1,-1004)
10-13 12:08:32.668 32460-32460/com.workingagenda.democracydroid D/VideoView: Error: 1,-1004

To be more precise about my question:

  1. I'd like to know what this error, E/MediaPlayer: Error (1,-1004) is (as I haven't found any info on the web about it).
  2. If it is what I suspect, basically as end of file/stream error, then I am hoping to get some help buffering or otherwise loading the video in such a way to avoid this?

I've seen this question, Android Streaming with MediaPlayer: Error(1, -1004) and 3GPP video, but the answers aren't much help.

I've found a function, MediaPlayer.prepareAsync(), here https://developer.android.com/reference/android/media/MediaPlayer.html#prepareAsync(), this is automatically called when a VideoView opens a video, but this doesn't seem to work.

Edit

So the solution brought me to Google's ExoPlayer, which was pretty easy to swap in for my VideoView, and it works like a charm.

  1. Add ExoPlayer as dependency
  2. Change view in layout to SimpleExoPlayerView
  3. Initialize SimpleExoPlayer in Activity
  4. Initialize MediaSource and attach to player
  5. Remember to release() when no longer needed.

And with that, streaming works seamlessly.

Firedrake answered 13/10, 2016 at 16:39 Comment(2)
Use github.com/google/ExoPlayerExeter
Yes... that is the solutionFiredrake
A
1

Android MediaPlayer class doesn't provide access to lower level settings such as buffer size.

Form log -1004 means: public static final int MEDIA_ERROR_IO

For me this code is work fine:

try{
    MediaController mediaController = new MediaController(this);

    Uri video = Uri.parse(url);

    mediaController.setAnchorView(videoView);
    videoView.requestFocus();
    videoView.setMediaController(mediaController);
    videoView.setVideoURI(video);

    videoView.setOnPreparedListener(new OnPreparedListener()
    {

        @Override
        public void onPrepared(MediaPlayer arg0)
        {
            videoView.start();
        }
    });
}catch (Exception e) {
    e.printStackTrace();
}

It seemed to have been something relating to the source of the stream, because some sources eventually played on the device, but the one we needed, never played.

If you can see then you know some problem with your stream by the log.

MediaHTTPConnection: readAt 26869519 / 241 => java.net.ProtocolException: unexpected end of stream

That exception is thrown by FixedLengthInputStream when the expected number of bytes (usually set in the content-length header of the response) is larger than the actual data in the response. Check that the content-length header is correct. (If you're supplying your own value for the content length, make sure it is correct.)

For more detail please see this post unexpected end of stream error

Other this one also help you, Please check this link that how to create long time buffer for MediaPlayer

Angora answered 13/1, 2017 at 12:30 Comment(1)
So that last link brought me to ExoPlayer... that's what I neededFiredrake
D
0

The VideoView on Android isn't the best, if you use VLC you'll get a much smoother experience buffering video.

Here are instructions on how to compile VLC from source for Android: https://wiki.videolan.org/AndroidCompile/

Decanal answered 11/1, 2017 at 4:2 Comment(0)
B
0

Using VideoView in streaming video may cause sometime problem. I also faced so many issue.

Use JieCaoVideoPlayer library to stream Video. It allows more options available.

https://github.com/lipangit/JieCaoVideoPlayer

Just import it

compile 'fm.jiecao:jiecaovideoplayer:5.3'

Add in your layout like normal view

<fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard
   android:id="@+id/videoplayer"
   android:layout_width="match_parent"
   android:layout_height="200dp"/>

Set URL which you want to play

JCVideoPlayerStandard jcVideoPlayerStandard = (JCVideoPlayerStandard) findViewById(R.id.videoplayer);
jcVideoPlayerStandard.setUp("http://2449.vod.myqcloud.com/2449_22ca37a6ea9011e5acaaf51d105342e3.f20.mp4"
                        , JCVideoPlayerStandard.SCREEN_LAYOUT_NORMAL, "Video");
jcVideoPlayerStandard.thumbImageView.setImage("http://p.qpic.cn/videoyun/0/2449_43b6f696980311e59ed467f22794e792_1/640");
Bills answered 13/1, 2017 at 5:53 Comment(1)
Yes, It is a weird but we just want the code so just ignore it. Library is good for streaming videosBills
T
0
   implementation 'android.arch.lifecycle:extensions:1.1.0'
implementation 'android.arch.lifecycle:compiler:1.1.0'
implementation 'cn.jzvd:jiaozivideoplayer:7.0.5'

<cn.jzvd.JzvdStd
        android:id="@+id/video_player"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


    JzvdStd jzvdStd;

 jzvdStd = (JzvdStd) findViewById(R.id.video_player);

    jzvdStd.setUp(getIntent().getExtras().getString("id"), getIntent().getExtras().getString("title"), 0);

    jzvdStd.setScreenFullscreen();
    jzvdStd.backButton.setVisibility(View.GONE);
    jzvdStd.batteryLevel.setVisibility(View.GONE);
    jzvdStd.batteryTimeLayout.setVisibility(View.GONE);
    jzvdStd.titleTextView.setVisibility(View.GONE);
    jzvdStd.dismissBrightnessDialog();
    jzvdStd.dismissVolumeDialog();
    jzvdStd.dissmissControlView();
    jzvdStd.dismissProgressDialog();
    jzvdStd.startVideo();
    Glide.with(jzvdStd.getContext()).load(getIntent().getExtras().getString("thumb")).into(jzvdStd.thumbImageView);



 @Override
public void onBackPressed() {
    if (Jzvd.backPress()) {
        super.onBackPressed();
        return;
    }
    super.onBackPressed();

}

@Override
public void onDestroy() {
    super.onDestroy();

}

@Override
protected void onPause() {
    super.onPause();
    Jzvd.releaseAllVideos();
}
Tieshatieup answered 26/4, 2021 at 3:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.