public long getvideoDuration(String url){
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(context, Uri.parse(url));
String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
long timeInmillisec = Long.parseLong( time );
long duration = timeInmillisec / 1000;
long hours = duration / 3600;
long minutes = (duration - hours * 3600) / 60;
long seconds = duration - (hours * 3600 + minutes * 60);
return seconds;
}
我正在尝试使用以上代码从youtube网址获取视频的持续时间.....但在retriever.setDataSource(context, Uri.parse(url))
Error: java.lang.IllegalArgumentException at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:83)