使用Movie播放GIF图片时,能正常导入assets中的gif文件,如:
代码如下 |
复制代码 |
is=context.getResources().openRawResource(R.drawable.mygif);
movie = Movie.decodeStream(is);
|
然而把网络图片加载到本地后,却报以下错误:
代码如下 |
复制代码 |
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)
|
我是在Androidmanifest.xml声明了权限:
解决办法:
代码如下 |
复制代码 |
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);
|