I'm developing an android application, one of the screens of it should generate thumbnails of videos and display them in a list. Like the image below.
Iwasabletogeneratethumbnailsofimages,butI'vetriedseveralwaystogeneratethethumbnailsofthevideos,andnothingisdisplayedonthescreenwhenItesttheapplication.Mylastattemptwastocreateonlyonethumbnailofavideo,butasintheotherattemptsnothingisdisplayed.
Currentlythecodeisasfollows:
<?xmlversion="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 documentation of Android and several examples that I found, this code should work. Does anyone have an idea of what might be missing, or some other solution?
ps: For a suggestion I've already tried using the Glide library, I still have the same problem.