Question

I am accessing the videos directly from content provider without storing it in my database. But it is giving me 3gp audio file along with other video and 3gp videos. how could i filter only the video files.I am working for API 8

Was it helpful?

Solution

Try this since you are working on API 8, otherwise METADATA_KEY_HAS_VIDEO could have done the job if API level >= 10.
A work around using MediaPlayer. If media has height it means it is a video.

public boolean isVideoFile(File file) { 
        int height = 0;
        try {
            MediaPlayer mp = new MediaPlayer();
            FileInputStream fs;
            FileDescriptor fd;
            fs = new FileInputStream(file);
            fd = fs.getFD();
            mp.setDataSource(fd);
            mp.prepare(); 
            height = mp.getVideoHeight();
            mp.release();
        } catch (Exception e) {
            Log.e(TAG, "Exception trying to determine if 3gp file is video.", e);
        }
        return height > 0;
    }

Source

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top