문제

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

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top