Android VideoView setDataSource 失败。: status=0x80000000

Android VideoView setDataSource failed.: status=0x80000000

我知道在 Whosebug 上有无数的问题描述了这个错误,我已经详细了解了每一个问题。不幸的是 none 的解决方案对我有用。我无法相信流式传输视频是如此痛苦。

这是我的代码。

MainActivity.java

public class MainActivity extends AppCompatActivity{
    VideoView videoview;

    private static final String VIDEO_URL = "http://www.law.duke.edu/cspd/contest/finalists/viewentry.php?file=docandyou";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        videoview = (VideoView) findViewById(R.id.VideoView);

        try {
            MediaController mediacontroller = new MediaController(
                    MainActivity.this);
            mediacontroller.setAnchorView(videoview);
            videoview.setMediaController(mediacontroller);
            videoview.setVideoURI(Uri.parse(VIDEO_URL));

        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }

        videoview.requestFocus();
        videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            // Close the progress bar and play the video
            public void onPrepared(MediaPlayer mp) {
                videoview.start();
            }
        });
    }
}

activity_main.xml

<RelativeLayout 
    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=".MainActivity">

    <VideoView
        android:id="@+id/VideoView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true" />

</RelativeLayout>

AndroidManifest.xml

.......
<uses-permission android:name="ANDROID.PERMISSION.INTERNET"/>
<uses-permission android:name="ANDROID.PERMISSION.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="ANDROID.PERMISSION.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
........

现在我已尝试播放此 url、

中的视频

http://www.law.duke.edu/cspd/contest/finalists/viewentry.php?file=docandyou

但总是报错

E/MediaPlayer﹕ Unable to create media player
W/VideoView﹕ Unable to open content: http://www.law.duke.edu/cspd/contest/finalists/viewentry.php?file=docandyou
    java.io.IOException: setDataSource failed.: status=0x80000000

此类问题的一个常见答案是尝试使用不同的视频文件,因为并非所有设备都支持所有视频编解码器。我确保通过从上面 link 下载视频并将其添加到包中的原始文件夹。应用程序播放原始文件夹中的相同视频没有任何问题。

那么为什么 VideoPlayer 不能播放来自 public 个域的视频,而这些域可以在本地播放?

无法访问调试器,很难准确说出哪里出了问题。

但有几件事很突出。

首先,您的 URL 似乎被退回了很多,有大量的重定向:

curl -L -I "http://www.law.duke.edu/cspd/contest/finalists/viewentry.php?file=docandyou"
HTTP/1.1 302 Found
Date: Fri, 11 Sep 2015 08:05:01 GMT
Server: Apache/2.2.15
Location: https://law.duke.edu/cspd/contest/finalists/viewentry.php?file=docandyou
Connection: close
Content-Type: text/html; charset=iso-8859-1

HTTP/1.1 301 Moved Permanently
Date: Fri, 11 Sep 2015 08:05:02 GMT
Server: Apache/2.2.15
Location: http://cspd.law.duke.edu/contest/finalists/viewentry.php?file=docandyou
Connection: close
Content-Type: text/html; charset=iso-8859-1

HTTP/1.1 301 Moved Permanently
Date: Fri, 11 Sep 2015 08:05:02 GMT
Server: Apache/2.2.3 (CentOS)
Location: http://web.law.duke.edu/cspd/contest/finalists/viewentry.php?file=docandyou
Connection: close
Content-Type: text/html; charset=iso-8859-1

HTTP/1.1 302 Found
Date: Fri, 11 Sep 2015 08:05:02 GMT
Server: Apache/2.2.3 (CentOS)
X-Powered-By: PHP/5.1.6
Location: http://www.law.duke.edu/cspd/contest/finalists/entries/documentariesandyou.mp4
Connection: close
Content-Type: text/html; charset=UTF-8

HTTP/1.1 302 Found
Date: Fri, 11 Sep 2015 08:05:02 GMT
Server: Apache/2.2.15
Location: https://law.duke.edu/cspd/contest/finalists/entries/documentariesandyou.mp4
Connection: close
Content-Type: text/html; charset=iso-8859-1

HTTP/1.1 301 Moved Permanently
Date: Fri, 11 Sep 2015 08:05:03 GMT
Server: Apache/2.2.15
Location: http://cspd.law.duke.edu/contest/finalists/entries/documentariesandyou.mp4
Connection: close
Content-Type: text/html; charset=iso-8859-1

HTTP/1.1 301 Moved Permanently
Date: Fri, 11 Sep 2015 08:05:03 GMT
Server: Apache/2.2.3 (CentOS)
Location: http://web.law.duke.edu/cspd/contest/finalists/entries/documentariesandyou.mp4
Connection: close
Content-Type: text/html; charset=iso-8859-1

HTTP/1.1 200 OK
Date: Fri, 11 Sep 2015 08:05:03 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Thu, 05 Apr 2007 17:14:01 GMT
ETag: "101bfe0-5ac8cb-42d60b2758840"
Accept-Ranges: bytes
Content-Length: 5949643
Connection: close
Content-Type: text/plain; charset=UTF-8

其次,最后的 mp4 使用 text/plain MIME 类型提供。

第三,源使用MPEG-4 Part 2编解码器(高级简单)。如果它在下载时播放,那么它可能无法使用原始 URL.

检测其格式

尝试直接播放最后的 URL 以查看您的问题是否由重定向或缺少正确的 MIME type/extension 引起,这可能导致播放器无法检测格式:

http://web.law.duke.edu/cspd/contest/finalists/entries/documentariesandyou.mp4