get Media Duration - Android Media

Android examples for Media:Media Player

Description

get Media Duration

Demo Code


//package com.java2s;
import android.media.MediaPlayer;

import java.io.File;
import java.io.IOException;

public class Main {
    public static int getDuration(File f) throws IOException {
        MediaPlayer mediaPlayer = new MediaPlayer();
        mediaPlayer.setDataSource(f.getAbsolutePath());
        mediaPlayer.prepare();/*from w w w.ja  va  2 s  .c o  m*/

        int duration = mediaPlayer.getDuration();
        mediaPlayer.release();
        return duration;
    }
}

Related Tutorials