Android电影解码流为空

时间:2015-03-25 14:17:21

标签: android inputstream gif movie

我在sdcard中从gif文件创建对象影片。为此使用decodestream。操作结果影片为空。我也使用方法decodeFile和decodeByteArray。 我的代码

public GifView(Context context, InputStream inputStream) {
    super(context);
    gifInputStream = inputStream;
    init(context);
}

private void init(Context context){
    setFocusable(true);
    gifMovie = Movie.decodeStream(gifInputStream);
    movieWidth = gifMovie.width();
    movieHeight = gifMovie.height();
    movieDuration = gifMovie.duration();
}

1 个答案:

答案 0 :(得分:0)

 public GifView(Context context, AttributeSet attrs, 
   int defStyleAttr) {
  super(context, attrs, defStyleAttr);
  init(context);
 }

 private void init(Context context){
  setFocusable(true);
  gifInputStream = context.getResources()
    .openRawResource(R.drawable.image);

  gifMovie = Movie.decodeStream(gifInputStream);
  movieWidth = gifMovie.width();
  movieHeight = gifMovie.height();
  movieDuration = gifMovie.duration();
 }