public class MainActivity extends AppCompatActivity {
Private static final String TAG="MainActivity - v. v.";
private String path;
Private VideoView VideoView;
Private MediaController MediaController;
Private File File;
@ Override
Protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Path=Environment. External.getexternalstoragedirectory (.) getAbsolutePath () + "/one. Mp4";
The file=new file (path);
VideoView=the findViewById (R.i d.v ideoview);
MediaController=new mediaController (this);
CheckPermissionAndPlayVideo ();
}
Private void checkPermissionAndPlayVideo () {
Int I=ContextCompat. CheckSelfPermission (this, the Manifest. Permission. READ_EXTERNAL_STORAGE);
if (i !=PackageManager. PERMISSION_GRANTED) {
ActivityCompat. RequestPermissions (this, new String [] {the Manifest. Permission. READ_EXTERNAL_STORAGE}, 999);
} else {
PlayVideo ();
}
}
Private void playVideo () {
VideoView. SetMediaController (mediaController);
VideoView. SetVideoPath (path);
VideoView. Start ();
}
@ Override
Public void onRequestPermissionsResult (int requestCode, @ NonNull String [] permissions, @ NonNull int [] grantResults) {
If (requestCode==999) {
If (grantResults. Length & gt; 0 & amp; & GrantResults [0]==PackageManager. PERMISSION_GRANTED) {
PlayVideo ();
} else {
Toast. MakeText (this, "to take SDcard permissions", Toast. LENGTH_SHORT), show ();
}
}
}
}
& lt; ? The XML version="1.0" encoding="utf-8"?>Package="com. Example. Myapplication" & gt; Android: allowBackup="true"
The android: icon="@ mipmap/ic_launcher"
Android: label="@ string/app_name"
Android: roundIcon="@ mipmap/ic_launcher_round"
Android: supportsRtl="true"
Android: theme="@ style/AppTheme" & gt;
Android: authorities="com. Imooc. The provider"
The android: name="androidx. Core. Content. FileProvider"
Android: grantUriPermissions="true"
Android: exported="false" & gt;
<meta - data
The android: name="android. Support. FILE_PROVIDER_PATHS"
Android: resource="@ XML/file_path" & gt;
& lt; ? The XML version="1.0" encoding="utf-8"?>Name="name", "
Path="" & gt;
There is an error, can't play video
The 2020-03-15 09:57:30. 328, 8615-8741/com. Example. Myapplication D/HiTouch_PressGestureDetector: onAttached, package=com. Example. Myapplication, windowType=1, mHiTouchRestricted=false
2020-03-15 09:57:30. 332, 8615-8615/com. Example. Myapplication W/MediaPlayer: Couldn 't open the uri in attemptDataSource
The 2020-03-15 09:57:30. 334, 8615-8615/com. Example. Myapplication W/VideoView: Unable to open the content:/storage/emulated/0/one. Mp4
Java. IO. FileNotFoundException:/storage/emulated/0/one. Mp4: open failed: EACCES (Permission denied)
The at libcore. IO. IoBridge. Open (IoBridge. Java: 496)
The at Java. IO. FileInputStream. & lt; init> (a FileInputStream. Java: 159)
An android. Media. The MediaPlayer. SetDataSource (MediaPlayer. Java: 1264)
An android. Media. The MediaPlayer. SetDataSource (MediaPlayer. Java: 1208)
An android. Media. The MediaPlayer. SetDataSource (MediaPlayer. Java: 1124)
An android. Media. The MediaPlayer. SetDataSource (MediaPlayer. Java: 1145)
. An android widget. The VideoView. OpenVideo (VideoView. Java: 412)
. An android widget. The VideoView. Access the $2200 (83) VideoView. Java:
An android. Widget. VideoView $7. SurfaceCreated (VideoView. Java: 694)
An android. View. SurfaceView. UpdateSurface (SurfaceView. Java: 786)
An android. View. SurfaceView $2. OnPreDraw (SurfaceView. Java: 162)
An android. View. ViewTreeObserver. DispatchOnPreDraw (ViewTreeObserver. Java: 1088)
An android. View. ViewRootImpl. PerformTraversals (ViewRootImpl. Java: 2944)
An android. View. ViewRootImpl. DoTraversal (ViewRootImpl. Java: 1857)
An android. View. ViewRootImpl $TraversalRunnable. Run (ViewRootImpl. Java: 8089)
At android. View. Choreographer $CallbackRecord. Run (1057) Choreographer. Java:
An android. View. Choreographer. DoCallbacks (Choreographer. Java: 875)
An android. View. Choreographer. DoFrame (Choreographer. Java: 776)
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull