Fastest way to check if Video File have Following MetaData? - android

There are Number of ways to check video file Meta data , using FFmpegMediaMetadataRetriever(Slow but reliable) and using Native MediaMetadataRetriever(Slow and not reliable).
There are number of question answered in SO for same purpose to get MetaData using FFMPEG or Native Media api , like Q1 , Q2 , Q3 but they are not solving my problem.
My Problem:
Get following meta data from file(Video) of android directory:
Video have Sound/Audio or not?
Creation date and time
thumbnail of video file
Kindly let me know if you have any suggestion or code samples would be big help.

when i want check video has audio or not that time i created this method. method return True if Video has Audio otherwise False
just you pass Context and Uri of Your video file
private boolean setHasAudioOrNot(JoinVideoActivity activity, Uri uri) {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(activity.getApplicationContext(),uri);
Log.e("Command","audiohas?? " +retriever.extractMetadata(16));
return retriever.extractMetadata(16) != null;
}

Related

Extracting frame from video from storage device using MediaMetadataRetriever - IllegalArgumentException at setDataSource()

I want to extract one frame from video in my app. The video is chosen from my storage device. After trying to call setDataSource I'm getting an IllegalArgumentException.
Here is the part of my code:
MediaMetadataRetriever med = new MediaMetadataRetriever();
med.setDataSource(imageUri.toString());
A value of imageUri is:
content://com.android.providers.media.documents/document/video%3A59728
Is the path of my video in wrong format?
I have also tried to use FFmpegMediaMetadataRetriever.
use
med.setDataSource(context, imageUri)
if it does not work use MediaStore and get MediaStore URI

How can I get song metadata without using playUri using the Android SDK?

I want to get song metadata from a URI without starting to play/buffer that song.
The only way I can see of doing it right now is calling playUri() and then getMetadata() but I don't want to play it immediately.
Is there any other way?
Thanks!
Edit: Is there a way to do this via the SDK with non-local files?
Use MediaMetaDataRetreiver:
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(context, uri);
String artist
= retreiver.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
//etc
retriever.release(); //don't forget to call this when done

How can I get the location data of a video in Android?

I am trying to get the metadata for the video files stored on my app's user's phone. I can get the file name, id, date taken and so on. However, latitude and longitude data always returns as 0.0. I have been referring to this:
developer.android.com/reference/android/provider/MediaStore.Video.VideoColumns.html
Yes, I am already enabling use location in my settings. I have a very similar function to this for images which works fine.
public void getLocalVideoFiles(Context context) {
ContentResolver videoResolver = context.getContentResolver();
Uri videoUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
String test = getRealPathFromURI(context, videoUri);
Cursor videoCursor = videoResolver.query(videoUri, null, null, null, null);
if(videoCursor!=null && videoCursor.moveToFirst()){
//get columns
int latColumn = videoCursor.getColumnIndex
(MediaStore.Video.Media.LATITUDE);
int lonColumn = videoCursor.getColumnIndex
(MediaStore.Video.Media.LONGITUDE);
do {
String thisLat = Double.toString(videoCursor.getDouble(latColumn));
String thisLon = Double.toString(videoCursor.getDouble(lonColumn));
Log.d("video Latitude",thisLat);
Log.d("video Longitude",thisLon);
}
while (videoCursor.moveToNext());
}
return localClips;
}
The approach described here: Geotagging a captured video yields similar results (null value in the METADATA_KEY_LOCATION column).
So, my question is: does the built-in Android video tool record location data when creating videos? It seems like the answer is no, but I don't understand why there are columns for the location data if this is the case. If that is not the case, how can I access the video location data? I need the location of video files that have already been taken.
Thanks in advance!
Well i've just tested your assumption that google does not keep location data while recording video and it's incorrect.
For example: using my nexus 5 with version 5.1 i was able to get a geotag on a video i just took. you can try it by yourself and if your phone is rooted, just browse the MediaStore external DB (com.android.providers.media) using some SQLITE viewer
but let's say that google does not keep GeoTag. there are number of reasons why they would keep such a column:
To support other video libraries that do want to keep geo taggging
To allow users who are implementing Video recorder a way to save current location ( using FusedLocation or something similar). a way of doing it is just updating the relevant row in the DB for example:
getContentResolver().update(MediaStore.Video.Media.EXTERNAL_CONTENT_URI.buildUpon().appendPath("2152").build(), cv, null, null);
to support previous versions that did support tagging

How can i pause voice recording in Android?

My aim is to pause in recording file.
I see in Android developer site its but Media Recorder have not pause option.
Java supports merge two audio file programatically but In android its not work.
Join two WAV files from Java?
And also I used default device audio recorder Apps which is available in all device but in Samsung few devices have not returened recording path.
Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
startActivityForResult(intent,REQUESTCODE_RECORDING);
Any one help for voice recording with pause functionality.
http://developer.android.com/reference/android/media/MediaRecorder.html
MediaRecorder does not have pause and resume methods. You need to use stop and start methods instead.
I had such a requirement in one of my projects, What we done was like make a raw file for saving recorded data in start of recording using AudioRecord , the for each resume we append the data to the same file
like
FileOutputStream fos= new FileOutputStream(filename, true);
here the filename is the name of the raw file and append the new recording data to it.
And when user stop the recording we will convert the entire raw file to .wav( or other) formats. Sorry that i cant post the entire code. Hope this will give you a direction to work.
You can refer my answer here if still have this issue. For API level >= 24 pause/resume methods are available in Android MediaRecorder class.
For API level < 24
Add below dependency in your gradle file:
compile 'com.googlecode.mp4parser:isoparser:1.0.2'
The solution is to stop recorder when user pause and start again on resume as already mentioned in many other answers in stackoverflow. Store all the audio/video files generated in an array and use below method to merge all media files. The example is taken from mp4parser library and modified little bit as per my need.
public static boolean mergeMediaFiles(boolean isAudio, String sourceFiles[], String targetFile) {
try {
String mediaKey = isAudio ? "soun" : "vide";
List<Movie> listMovies = new ArrayList<>();
for (String filename : sourceFiles) {
listMovies.add(MovieCreator.build(filename));
}
List<Track> listTracks = new LinkedList<>();
for (Movie movie : listMovies) {
for (Track track : movie.getTracks()) {
if (track.getHandler().equals(mediaKey)) {
listTracks.add(track);
}
}
}
Movie outputMovie = new Movie();
if (!listTracks.isEmpty()) {
outputMovie.addTrack(new AppendTrack(listTracks.toArray(new Track[listTracks.size()])));
}
Container container = new DefaultMp4Builder().build(outputMovie);
FileChannel fileChannel = new RandomAccessFile(String.format(targetFile), "rw").getChannel();
container.writeContainer(fileChannel);
fileChannel.close();
return true;
}
catch (IOException e) {
Log.e(LOG_TAG, "Error merging media files. exception: "+e.getMessage());
return false;
}
}
Use flag isAudio as true for Audio files and false for Video files.
You can't do it using Android API, but you can save a lot of mp4 files and merge it using mp4parser: powerful library written in Java. Also see my simple recorder with a "pause": https://github.com/lassana/continuous-audiorecorder.

video View don't play a local video

hi guys i read many example about play video in video view, but no one work for me, i get this error:
java.io.FileNotFoundException: /android.resource:/frt.com.maint/2130968576 (No such file or directory)
this is my code-------------------------------------------------------------------------:
FileInputStream fi = new FileInputStream("android.resource://frt.com.maint/" + R.raw.videointro);
MediaPlayer pl = new MediaPlayer();
pl.setDataSource(fi.getFD());
pl.prepare();
pl.start();
MediaPlayer don't have method setVideoURI, i use the first solution that you give me but i still get same error, after i use this code with videoview:
Uri video = Uri.parse("android.resource://frt.com.maint/videointro");
vidview_gdf.setVideoURI(video);
vidview_gdf.start();
but i get an error with message "you can not play the video"
p.s: additional info: introvideo.mp4 - 7 MB
You're trying to use the ID of the resource, which is just an int index.
Use the filename instead:
fi = new FileInputStream("android.resource://frt.com.maint/nitrovideo");
Or better:
StringBuilder videoURIPath = new StringBuilder();
videoURIPath.append("android.resource://");
videoURIPath.append(getPackageName() + "/");
videoURIPath.append("raw/");
videoURIPath.append(videoFileName);
pl.setVideoURI(Uri.parse(videoURIPath.toString());
Where videoFileName is a string of the name of your file.
Are you doing this on emulator or actual device?
I had a bit of bad experience with H.264 encoded video before. Basically, I tried to play it on the first GalaxyTab but it didn't work. Turned out that GalaxyTab I had didn't support H.264.
So, I would advise you to make sure that the default video player can play this file before proceed further. If that's not the case for you then I'm not sure what's wrong. Your code looks fine to me.

Categories

Resources