在片段中,我有 videoview 并播放录制的 whit 模拟器相机 .mp4 视频。一切都很好,在模拟器中视频正在播放,但是在真实设备上,当我尝试播放另一个视频时,再次以 .mp4 格式用我的相机录制,屏幕变黑并黯然失色“BitmapFactory 类。找不到源”。我正在 4.0.4 设备上进行测试,目标是 8 到 17 api。图像在模拟器和真实设备上都可以正常打开。没有LOGcat错误,一切都是绿色的......
片段代码
public class PreviewFragment extends Fragment {
View view;
//variable
File file;
boolean image;
//views
VideoView videView;
ImageView imageView;
ImageButton imageButton;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if(container == null) {
return null;
}
view = inflater.inflate(R.layout.fragment_preview, container, false);
//elements
imageView = (ImageView) view.findViewById(R.id.imageView1);
videView = (VideoView) view.findViewById(R.id.videoView1);
//variables from activity
file = ((PreviewActivity)getActivity()).file;
image = ((PreviewActivity)getActivity()).image;
//main run
if(image == true) {
imageView.setImageURI(Uri.parse(file.getAbsolutePath()));
}
else {
videView.setVideoURI(Uri.parse(file.getAbsolutePath()));
videView.setMediaController(new MediaController(getActivity()));
videView.requestFocus();
videView.start();
}
return view;
}
}
和xml代码
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black" >
<VideoView
android:id="@+id/videoView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:contentDescription="@string/text_fullscreen" />