Android movie import player gif image file exception Ioexception.reset

Source: Internet
Author: User

When you use movie to play an GIF picture, you can normally import a GIF file in assets, such as:

The code is as follows Copy Code

Is=context.getresources (). Openrawresource (R.drawable.mygif);
Movie = Movie.decodestream (IS);

However, when the network picture is loaded locally, the following error is reported:

The code is as follows Copy Code

Java.io.IOException
At Java.io.InputStream.reset (inputstream.java:218)
At Android.graphics.Movie.decodeStream (Native method)
At Android.graphics.Movie.decodeTempStream (movie.java:74)
At Android.graphics.Movie.decodeFile (movie.java:59)

I declared the permission in Androidmanifest.xml:

The code is as follows Copy Code

<uses-permission android:name= "Android.permission.INTERNET"/>
<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>

Solution:

  code is as follows copy code

InputStream is = null;
    try {
        is = new Bufferedinputstream (new FileInputStream (New File (Getcachedir (), "Mygif.gif")), 16 * 1024);
        Is.mark (16 * 1024);
   } catch (FileNotFoundException e) {
       //TODO Auto-generated Catch block
        e.printstacktrace ();
    }
Movie = Movie.decodestream (is);

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.