Mediametadataretriever: Illegalargumentexception Thrown From Setdatasource()

Posted on

Here follow-up my onetime postal service “Get icon frame inwards video using MediaMetadataRetriever“, related of permission of “android.permission.READ_EXTERNAL_STORAGE” again.

It’s a onetime practise to recall icon frame from mp4 video. At the fourth dimension I wrote the post, it operate equally expected without involve permission of “android.permission.READ_EXTERNAL_STORAGE”. But now, yous bring to add together it inwards AndroidManifest.xml. Otherwise, the code mediaMetadataRetriever.setDataSource(uri) volition throw java.lang.IllegalArgumentException, caused by the path is invalid.


MainActivity.java

package com.example.androidmediametadataretriever;  import android.support.v7.app.ActionBarActivity; import android.graphics.Bitmap; import android.media.MediaMetadataRetriever; import android.os.Bundle; import android.widget.ImageView;  world bird MainActivity extends ActionBarActivity {   String uri = "/storage/emulated/0/DCIM/LEDrose.mp4";  ImageView capturedImageView;   @Override  protected void onCreate(Bundle savedInstanceState) {   super.onCreate(savedInstanceState);   setContentView(R.layout.activity_main);    capturedImageView = (ImageView) findViewById(R.id.capturedimage);    MediaMetadataRetriever mediaMetadataRetriever = novel MediaMetadataRetriever();    mediaMetadataRetriever.setDataSource(uri);   Bitmap bmFrame = mediaMetadataRetriever.getFrameAtTime(5000000);   capturedImageView.setImageBitmap(bmFrame);   }  } 

activity_main.xml

<LinearLayout 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:orientation="vertical"     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="com.example.androidmediametadataretriever.MainActivity" >      <TextView         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_gravity="center_horizontal"         android:autoLink="web"         android:text="https://rootandroid.org//"         android:textStyle="bold" />      <ImageView         android:id="@+id/capturedimage"         android:layout_width="match_parent"         android:layout_height="match_parent" />  </LinearLayout> 

Permission of “android.permission.READ_EXTERNAL_STORAGE” is needed inwards AndroidManifest.xml. And minSdkVersion bring to hold upward 10 or higher to use MediaMetadataRetriever inwards your code.

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.example.androidmediametadataretriever"     android:versionCode="1"     android:versionName="1.0" >      <uses-sdk         android:minSdkVersion="10"         android:targetSdkVersion="21" />     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>      <application         android:allowBackup="true"         android:icon="@drawable/ic_launcher"         android:label="@string/app_name"         android:theme="@style/AppTheme" >         <activity             android:name=".MainActivity"             android:label="@string/app_name" >             <intent-filter>                 <action android:name="android.intent.action.MAIN" />                  <category android:name="android.intent.category.LAUNCHER" />             </intent-filter>         </activity>     </application>  </manifest>