0
在片段中,我有videoview並播放錄製的白色模擬器攝像頭.mp4視頻。一切都很好,在視頻播放的模擬器中,但在真實設備上,當我嘗試播放另一個視頻時,再次記錄下我的相機.mp4格式的屏幕變黑和日食悲傷的「BitmapFactory類。未找到源」。我正在測試4.0.4設備,目標是從8到17 api。圖像在模擬器和實際設備上開放良好。沒有logcat的錯誤,都是綠色...只有在真實設備上的VideoView錯誤
片段代碼
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" />