我正在尝试从用户从其图库中选择的视频中获取一个帧。 我正在使用MediaMetadataRetreiver并且由于某种原因在“setDataSource”中获得非法参数。
我正在那里传递一串位置视频。我不知道我做错了什么,但它总是在那条线上崩溃。
代码示例
private void uploadData(final Uri videoUri, final String videoPath) {
if(videoUri != null){
UploadTask uploadTask = videoRef.putFile(videoUri);
uploadTask.addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
@Override
public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
if(task.isSuccessful())
Toast.makeText(getContext(), "Upload Complete", Toast.LENGTH_LONG).show();
progressBarUpload.setVisibility(View.INVISIBLE);
etTitleMusic.setText("");
progressDialog.dismiss();
createFrameFromVideo(videoPath);
String videoUrl = task.getResult().getDownloadUrl().toString();
}
}).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
updateProgress(taskSnapshot);
}
});
}else {
Toast.makeText(getContext(), "Nothing to upload", Toast.LENGTH_SHORT).show();
}
}
private void createFrameFromVideo(String videoPath) {
MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
mediaMetadataRetriever.setDataSource(videoPath);
Bitmap bmFrame = mediaMetadataRetriever.getFrameAtTime(5000000);
imageView.setImageBitmap(bmFrame);
imageView.setVisibility(View.VISIBLE);
}
在该行 mediaMetadataRetriever.setDataSource(videoPath); 它崩溃。
我做错了什么?
编辑 - 记录错误
12-02 13:40:39.212 15082-15082/com.world.bolandian.talent E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.world.bolandian.talent, PID: 15082
java.lang.IllegalArgumentException
at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:73)
at com.world.bolandian.talent.fragments.AddVideoAudioFragment.createFrameFromVideo(AddVideoAudioFragment.java:207)
at com.world.bolandian.talent.fragments.AddVideoAudioFragment.access$400(AddVideoAudioFragment.java:44)
at com.world.bolandian.talent.fragments.AddVideoAudioFragment$2.onComplete(AddVideoAudioFragment.java:187)
at com.google.firebase.storage.zzl.zzi(Unknown Source)
at com.google.firebase.storage.zzaa.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:742)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5571)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:745)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:635)