我想从设备中获取已保存视频的长度。我尝试使用$("#targetIframe").attr("src", url);
setTimeout(function(){
$("#targetIframe").find("head").append('<link rel="stylesheet" type="text/css" href="http://localhost:9090/html/flows/header.css">');
}, 100);
,但我的应用程序崩溃了。我在Android 6.0上测试它但它根本不工作。
以下是我的活动。
MediaMetadataRetriever
答案 0 :(得分:0)
尝试这个
MediaPlayer mp = MediaPlayer.create(getActivity(), Uri.parse(Environment.getExternalStorageDirectory() + "/Downloads/" + "vid" + ".mp4")); // Downloads is the folder and vid is video file.
int duration = mp.getDuration();
mp.release();
这对我有用。
答案 1 :(得分:0)
试试这个:
MediaPlayer mp = MediaPlayer.create(getActivity(), Uri.parse(Environment.getExternalStorageDirectory() + "/Downloads/" + "vid" + ".mp4")); // Downloads is the folder and vid is video file.
mp.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
int duration = mp.getDuration();
mp.release();
}
});