Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MediaExtractor, MediaMetadataRetriever with Raw/Asset File

Tags:

I try to read a video file inside either raw/assets folder, I have tried the following approaches but none of them works. I am testing on API 16. Each approach, I try with and without mp4 extension. I really appreciate that somebody can help me with it

All approaches will not crash, MediaMetadataRetriever can set data source, but cannot get width, height and screenshot. VideoExtractor always return

06-04 16:44:10.519: E/FileSource(8695): Failed to open file FILE_PATH. (No such file or directory) 06-04 16:44:10.519: E/DecodeActivity(8695): Can't find video info! 

Approach 1:android.resource

String filePath = "android.resource://" + this.activity.getPackageName() + "/raw/green_backhand_slice"; videoExtractor.setDataSource(activity.getApplicationContext(), Uri.parse(filePath), null); metaRetriever.setDataSource(act.getApplication(), Uri.parse(filePath)); 

Approach 2: android_asset

this.filePath = "file:///android_asset/green_backhand_slice"; videoExtractor.setDataSource(activity.getApplicationContext(), Uri.parse(this.filePath), null); metaRetriever.setDataSource(act.getApplication(), Uri.parse(filePath)); 

Approach 3: asset file descriptor

AssetFileDescriptor assetFD = null; try {     assetFD = getAssets().openFd("green_backhand_slice.mp4"); } catch (IOException e) {     e.printStackTrace(); }  metaRetriever.setDataSource(assetFD.getFileDescriptor()); 
like image 414
vodkhang Avatar asked Jun 04 '14 06:06

vodkhang


People also ask

What is mediametadataretriever class in Android?

an MediaMetadataRetriever class provides a unified interface for retrieving frames and metadata from an input media file. It is located under android.media package.

What are mediametadataretriever constants used for?

These constants are used to retrieve media information. Although, the work done by many of the Constants is obvious from their name, here is a small description of each constant present in MediaMetadataRetriever class. The metadata key to retrieve the information about the album title of the data source.

What is the warranty for Microsoft mediametadataretriever?

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here. MediaMetadataRetriever class provides a unified interface for retrieving frame and meta data from an input media file.

Where do you store your raw asset file?

H ave you ever need to store your raw asset file (e.g. JSON, Text, mp3, pdf, etc) in your app? Where do you store them? There are two possible locations: 1) assets, 2) res/raw folder. Both of them seems to be the same, as they can read the file and generate InputStream as below But when to put where? 1. Flexible filename: assets is better


1 Answers

Here are some ways to do it:

1.raw:

final AssetFileDescriptor afd=getResources().openRawResourceFd(R.raw.t); mediaMetadataRetriever.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength()); 

2.raw as uri:

final String uriPath="android.resource://"+getPackageName()+"/raw/t"; final Uri uri=Uri.parse(uriPath); mediaMetadataRetriever.setDataSource(getApplication(),uri); 

3.assets:

final AssetFileDescriptor afd=getAssets().openFd("t.mp4"); mediaMetadataRetriever.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength()); 
like image 141
android developer Avatar answered Sep 21 '22 15:09

android developer