1

I developed an activity where load a gif. In my Galaxy S III mini the gif load normaly, but in moto x... =(

The error occurs in line: movie.draw(canvas, 0, 0);

My class Gif extends from View

The code is:

protected void onDraw(Canvas canvas) {

    float escala = getEscala(canvas);
    setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int)(movie.height()*escala)));
    canvas.scale(escala,escala);
    canvas.drawColor(Color.TRANSPARENT);

    super.onDraw(canvas);
    long horaAtual = android.os.SystemClock.uptimeMillis();
    if (movieStart == 0) {
        movieStart = horaAtual;
    }
    if (movie != null) {
        int sequencia = (int) ((horaAtual - movieStart) % movie.duration());
        movie.setTime(sequencia);
        movie.draw(canvas, 0, 0);
        this.invalidate();
    }
}



private void initializeView() {
            if (inputStreamGif == null) {
                inputStreamGif = getContext().getResources().openRawResource(+R.drawable.carregando);
            }
            movie = Movie.decodeStream(inputStreamGif);
            movieStart = 0;
            this.invalidate();
        }

Layout element:

<view.elements.Gif
                    android:id="@+id/ivExercicio"
                    android:minHeight="900dp"
                    android:tag="carregando"
                    android:contentDescription="@string/contentDescription"
                    android:layout_gravity="center"
                    android:gravity="center"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"/>

The error:

E/Adreno-ES20﹕ <check_framebuffer_attachment:854>: Invalid texture format! Returning error!

E/Adreno-ES20﹕ <check_framebuffer_object_status:1237>: Framebuffer color attachment incomplete. Returning GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT!

E/Adreno-ES20﹕ <check_framebuffer_attachment:854>: Invalid texture format! Returning error!

E/Adreno-ES20﹕ <check_framebuffer_object_status:1237>: Framebuffer color attachment incomplete. Returning GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT!
Jean Carlos
  • 1,613
  • 3
  • 18
  • 26

1 Answers1

0

Solved.

My InputStream in some smartphones was null, so I get the byte array of my gifs and decode to Movie.

Code:

    private void initializeView() {
            if(array != null){
                movie = Movie.decodeByteArray(array, 0, array.length);
                movieStart = 0;
                this.invalidate();
            }

        }

protected void onDraw(Canvas canvas) {
        //BaseActivity.alertarThread(a, "Escala = " + escala + " - Movie L = " + movie.width() + " - Size W = " + w);

        setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0));

        if(movie == null) return;

        setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) (movie.height() * escala)));
        canvas.scale(escala, escala);
        //canvas.drawColor(Color.TRANSPARENT);

        super.onDraw(canvas);
        long horaAtual = android.os.SystemClock.uptimeMillis();
        if (movieStart == 0) {
            movieStart = horaAtual;
        }
        int duracao = movie.duration();
        if(duracao > 0)
        {
            sequencia = (int) ((horaAtual - movieStart) % movie.duration());
        }
        movie.setTime(sequencia);
        movie.draw(canvas, 0, 0);
        this.invalidate();
    }

But now I avoid the error, but in some android the gif doesn't show.

Basically I did not solve, only avoid throw. In my undertand this is a problem of memory or the extraction of image from sdcard.

Jean Carlos
  • 1,613
  • 3
  • 18
  • 26