【问题标题】:Android VideoView setDataSource failed.: status=0x80000000Android VideoView setDataSource 失败。:状态=0x80000000
【发布时间】:2015-08-25 08:40:30
【问题描述】:

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

这是我的代码。

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" />
........

现在我尝试从这个网址播放视频,

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

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

那么为什么 VideoPlayer 不能播放来自公共域的视频,而它可以在本地播放呢?

【问题讨论】:

  • 陷入同样的​​问题..

标签: android video-streaming ioexception android-video-player


【解决方案1】:

如果没有调试器,就很难准确地说出哪里出了问题。

虽然有一些事情很突出。

首先,您的网址似乎被弹跳了很多次,有大量的重定向:

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 编解码器(Advanced Simple)。如果它在下载时播放,那么它可能无法使用原始 URL 检测其格式。

尝试直接播放最终到达网址,看看您的问题是否是由于重定向或缺少正确的 MIME 类型/扩展名而导致播放器无法检测到格式:

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

【讨论】:

  • 您是如何找到重定向并创建此测试输出的?你能分享一下信息或提示吗?
  • @MehulJoisar 我使用了curl -L(关注位置)。我在答案中发布了它的输出。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-06-04
  • 2013-04-30
  • 2018-10-26
  • 1970-01-01
  • 2011-06-15
  • 1970-01-01
  • 2013-12-08
相关资源
最近更新 更多