Search code examples
androidvideo-streamingioexceptionandroid-video-player

Android VideoView setDataSource failed.: status=0x80000000


I know there are countless questions on stackoverflow describing this error and I have gone through each one of them in detail. Unfortunately none of the solution worked for me. I can't believe streaming a video is such a pain.

This is my code.

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

Now I have tried to play the video from this url,

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

But always getting error

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

One common answer for this kind of questions is to try out with different video files, because not all devices support every video codecs. I made sure that by downloading the video from the above link and adding it to raw folder in the bundle. Application played the same video from raw folder without any issues.

So why is VideoPlayer not playing videos from public domains, which it can play locally?


Solution

  • Without access to a debugger it's hard to say precisely what goes wrong.

    There are a few things that stick out though.

    First, your URL seems to be bounced a lot, there's a huge amount of redirects:

    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
    

    Second, the final mp4 is served with the text/plain MIME type.

    Third, the source uses the MPEG-4 Part 2 codec (Advanced Simple). If it plays when downloaded then it probably fails to detect its format using the original URL.

    Try to play the final URL directly to see if your issue is caused by the redirects or lack of proper MIME type/extension which can cause the player to fail to detect the format:

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