真诚求解!
package com.example.myapplication.ui.dashboard;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.MediaController;
import android.widget.VideoView;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import com.example.myapplication.R;
public class DashboardFragment extends Fragment {
@Override
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View root=inflater.inflate(R.layout.fragment_dashboard,
container, false);
VideoView videoView=root.findViewById(R.id.videoView);
videoView.setVideoURI(Uri.parse("android:resource://" +
"com.example.graduation_project/ui/knowledgeFragment/"+R.raw.cognition));
MediaController mediaController=new MediaController(getContext());
videoView.setMediaController(mediaController);
videoView.requestFocus();
return root;
}
}
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.dashboard.DashboardFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
LinearLayout>
androidx.constraintlayout.widget.ConstraintLayout>
I/zygote: Do partial code cache collection, code=28KB, data=30KB
After code cache collection, code=27KB, data=30KB
Increasing code cache capacity to 128KB
W/MediaPlayer: Couldn't open android:resource://com.example.graduation_project/ui/knowledgeFragment/2131755008: java.io.FileNotFoundException: No content provider: android:resource://com.example.graduation_project/ui/knowledgeFragment/2131755008
E/MediaPlayerNative: error (1, -2147483648)
E/MediaPlayer: Error (1,-2147483648)
D/VideoView: Error: 1,-2147483648
I/zygote: Do partial code cache collection, code=44KB, data=54KB
I/zygote: After code cache collection, code=44KB, data=54KB
Increasing code cache capacity to 256KB
I/zygote: JIT allocated 56KB for compiled code of void android.view.View.(android.content.Context, android.util.AttributeSet, int, int)
I/zygote: Do full code cache collection, code=103KB, data=74KB
After code cache collection, code=78KB, data=45KB
D/EGL_emulation: eglMakeCurrent: 0x9e705120: ver 2 0 (tinfo 0x9e703260)
I/chatty: uid=10084(u0_a84) RenderThread identical 2 lines
D/EGL_emulation: eglMakeCurrent: 0x9e705120: ver 2 0 (tinfo 0x9e703260)
D/EGL_emulation: eglMakeCurrent: 0x9e705120: ver 2 0 (tinfo 0x9e703260)
报错不是提示文件找不到吗