Reputation: 4528
Actually I'm trying to find out the duration of video from URl
but it throws null pointer exception
try{
File file = new File("http://84.--.--.--:8--9/"+filename);
if ( file.toString().endsWith(".jpg")) {
//photo
} else if (file.toString().endsWith(".mp4")) {
//video
long mills = MediaPlayer.create(UploadFileService.this, Uri.parse(file.getAbsolutePath().toString())).getDuration();
Log.d("duration", "" + mills);
}
}catch(Exception e) {
e.printStackTrace();
}
}
Upvotes: 1
Views: 5343
Reputation: 3530
Use FFmpegMediaMetadataRetriever:
import wseemann.media.FFmpegMediaMetadataRetriever;
...
FFmpegMediaMetadataRetriever retriever = new FFmpegMediaMetadataRetriever();
retriever.setDataSource("some URL");
String time = retriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_DURATION);
int duration = Integer.parseInt(time);
retriever.release();
Upvotes: 1
Reputation: 3845
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(intent.getStringExtra("fileName"));
String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
int VideoDuration = Integer.parseInt(time);// This will give time in millesecond
Upvotes: 3
Reputation: 3624
You should try this,
I hope this works.
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(File.getPath()); // Enter Full File Path Here
String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
long timeInmillisec = Long.parseLong(time); // You will get time in milliseconds
Upvotes: 0
Reputation: 1005
You cloud try using the class MediaMetadataRetriever, you just need to set a datasource to an instace of it, then check for the information you're looking for.
Upvotes: 0