Java mp4文件的Android MediaPlayer Http流导致;未接受的终止流”;几分钟后,仅在Android 6(M)上

Java mp4文件的Android MediaPlayer Http流导致;未接受的终止流”;几分钟后,仅在Android 6(M)上,java,android,android-mediaplayer,android-videoview,android-6.0-marshmallow,Java,Android,Android Mediaplayer,Android Videoview,Android 6.0 Marshmallow,我目前正在开发一个Android应用程序,包括一个视频播放器,它使用Android的VideoView通过HTTP加载mp4视频文件。 它在安装了安卓5.1.1版的Nexus4和安装了安卓4.4的平板电脑上都能正常工作 然而,使用安卓6.0,视频流在几分钟后意外结束(在Nexus5和模拟器上测试)。 正如您在日志输出中所看到的,流播放大约5分钟,直到java.net.ProtocolException发生,再播放1分钟,直到缓冲区变空 10-16 11:08:21.030 4657-4657/.

我目前正在开发一个Android应用程序,包括一个视频播放器,它使用Android的VideoView通过HTTP加载mp4视频文件。 它在安装了安卓5.1.1版的Nexus4和安装了安卓4.4的平板电脑上都能正常工作

然而,使用安卓6.0,视频流在几分钟后意外结束(在Nexus5和模拟器上测试)。 正如您在日志输出中所看到的,流播放大约5分钟,直到java.net.ProtocolException发生,再播放1分钟,直到缓冲区变空

10-16 11:08:21.030 4657-4657/...app D/video: start
10-16 11:08:21.060 4657-4657/...app W/MediaPlayer: Couldn't open file on client side; trying server side: java.io.FileNotFoundException: No content provider: http://someurl...mp4
10-16 11:08:29.330 4657-4657/...app D/MediaPlayer: getMetadata
10-16 11:08:29.360 4657-4657/...app D/video: prepared
10-16 11:08:29.470 4657-4671/...app W/MediaPlayer: info/warning (3, 0)
10-16 11:09:19.930 4657-4664/...app W/art: Suspending all threads took: 10ms
10-16 11:14:32.550 4657-4664/...app W/art: Suspending all threads took: 10ms
10-16 11:23:46.940 4657-4671/...app W/MediaHTTPConnection: readAt 121022400 / 22592 => java.net.ProtocolException: unexpected end of stream
10-16 11:24:40.780 4657-4669/...app E/MediaPlayer: error (1, -1004)
10-16 11:24:40.780 4657-4657/...app E/MediaPlayer: Error (1,-1004)
10-16 11:24:40.780 4657-4657/...app D/VideoView: Error: 1,-1004
10-16 11:24:40.780 4657-6289/...app E/MediaPlayer: error (1, -1004)
10-16 11:24:40.790 4657-4713/...app E/MediaPlayer: error (1, -1004)
10-16 11:24:40.830 4657-4657/...app E/MediaPlayer: Error (1,-1004)
10-16 11:24:40.830 4657-4657/...app D/VideoView: Error: 1,-1004
10-16 11:24:40.840 4657-4657/...app E/MediaPlayer: Error (1,-1004)
10-16 11:24:40.840 4657-4657/...app D/VideoView: Error: 1,-1004
10-16 11:24:40.860 4657-4697/...app W/EGL_emulation: eglSurfaceAttrib not implemented
10-16 11:24:40.860 4657-4697/...app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xe0d7e740, error=EGL_SUCCESS
10-16 11:24:40.880 4657-6289/...app E/MediaPlayer: error (1, -1004)
10-16 11:24:40.880 4657-4713/...app E/MediaPlayer: error (1, -1004)
10-16 11:24:40.890 4657-4697/...app W/EGL_emulation: eglSurfaceAttrib not implemented
10-16 11:24:40.890 4657-4697/...app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xe11fbd80, error=EGL_SUCCESS
10-16 11:24:40.920 4657-4697/...app W/EGL_emulation: eglSurfaceAttrib not implemented
10-16 11:24:40.920 4657-4697/...app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xed7939e0, error=EGL_SUCCESS
10-16 11:24:40.950 4657-4657/...app E/MediaPlayer: Error (1,-1004)
10-16 11:24:40.950 4657-4657/...app D/VideoView: Error: 1,-1004
10-16 11:24:40.950 4657-4657/...app E/MediaPlayer: Error (1,-1004)
10-16 11:24:40.950 4657-4657/...app D/VideoView: Error: 1,-1004
10-16 11:24:41.010 4657-4697/...app W/EGL_emulation: eglSurfaceAttrib not implemented
10-16 11:24:41.010 4657-4697/...app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xe0ed12e0, error=EGL_SUCCESS
10-16 11:24:41.030 4657-4697/...app W/EGL_emulation: eglSurfaceAttrib not implemented
10-16 11:24:41.030 4657-4697/...app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xe0ed1300, error=EGL_SUCCESS
添加唤醒和wifi锁似乎并没有阻止这种行为

以下是视频播放器片段的布局配置:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".VideoActivity"
    android:keepScreenOn="true">

<VideoView
    android:id="@+id/video"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    />

    ...

问题似乎与提供商的视频编码有关,但仍仅限于与Android 6.0I流媒体音频文件相结合,长度为2-4小时。10-15分钟后,我在棉花糖6.01上也遇到了这个错误/MediaHTTPConnection:readAt 78154603/32768=>java.net.ProtocolException:意外的流结束
videoView = (VideoView) v.findViewById(R.id.video);
videoView.setOnCompletionListener(this);
videoView.setOnPreparedListener(this);
videoView.setVideoURI(videoUrl);
videoView.seekTo(0);
videoView.start();