8
I’m developing an app for android, one of the screens of the same should generate thumbnails videos and display them in a list. Like the image below.
I was able to generate thumbnails of images, but I tried several ways to generate thumbnails of videos, and nothing is displayed on the screen when I test the application. My last attempt was to create only a thumbnail of a video, but as in other attempts nothing is shown.
Currently the code is as follows below:
<?xml version="1.0" encoding="utf-8"?>
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="patricia.videothumbnail.MainActivity">
<ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Titulo do Video"
android:id="@+id/textView"
android:layout_alignBottom="@+id/iv"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="20sp"
android:gravity="center"
android:background="@color/primary"
android:textColor="@color/icons"
/>
</RelativeLayout>
Java
import android.app.Activity;
import android.provider.MediaStore.Video.Thumbnails;
public class MainActivity extends AppCompatActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView thumbnail_mini = (ImageView)findViewById(R.id.iv);
//caminho para o video, testei de diversas formas
//1ª tentativa
String filePath = "android.resource://" + getPackageName() + "/" + R.raw.destruction;
//2º tentativa
//String filePath = "/storage/external_SD/destruction.mp4";
Bitmap bmThumbnail;
// MINI_KIND: 512 x 384 thumbnail
bmThumbnail = ThumbnailUtils.createVideoThumbnail(filePath, Thumbnails.MINI_KIND);
thumbnail_mini.setImageBitmap(bmThumbnail);
}
}
According to the Android documentation and several examples I found, this code should work. Does anyone have an idea of what might be missing, or any other solution?
ps: for a suggestion I tried to use the Glide library, I continue with the same problem.
Is there an error in the console or the
Bitmap
does not appear? My suggestion would be to use theGlide
for two reasons: he can recover a thumbnail for videos and he does it asynchronously, which is the best way if he is planning to do it in an Adapter.– Wakim
No error is shown on the console, the bitmap just doesn’t appear on the screen.
– Patrícia Ribeiro
I tried to use the library with video and nothing is displayed, with images worked. : / ?
– Patrícia Ribeiro
This was the result. https://www.dropbox.com/s/mhu1d8l7ymqri0i/Captura%20de%20tela%202016-02-19%2019.42.05.png? dl=0
– Patrícia Ribeiro