Java.io.FileNotFoundException : No content provider: Error

Java.io.FileNotFoundException : No content provider: Error … here is a solution to the problem.

Java.io.FileNotFoundException : No content provider: Error

I’m using videoView.setVideoPath(); There was a problem copying the video

In fact the video cannot be reproduced: I don’t know why. The video path is correct.

Here is my code :

 public class MainActivity extends AppCompatActivity {

private VideoView videoView;
        private int position = 0;
        private MediaController mediaController;

@Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

videoView = (VideoView) findViewById(R.id.videoView);

 Set the media controller buttons
            if (mediaController == null) {
                mediaController = new MediaController(MainActivity.this);

 Set the videoView that acts as the anchor for the MediaController.
                mediaController.setAnchorView(videoView);

 Set MediaController for VideoView
                videoView.setMediaController(mediaController);
            }

try {
                 ID of video file.

String videoUrl="https://www.youtube.com/watch?v=JHdmkP-nfsA";
                videoView.setVideoPath(videoUrl);

} catch (Exception e) {
                Log.e("Error", e.getMessage());
                e.printStackTrace();
            }

videoView.requestFocus();

 When the video file ready for playback.
            videoView.setOnPreparedListener(new OnPreparedListener() {

public void onPrepared(MediaPlayer mediaPlayer) {

videoView.seekTo(position);
                    if (position == 0) {
                        videoView.start();
                    }

 When video Screen change size.
                    mediaPlayer.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() {
                        @Override
                        public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {

 Re-Set the videoView that acts as the anchor for the MediaController
                            mediaController.setAnchorView(videoView);
                        }
                    });
                }
            });

}

}

Can anyone help me?

Thank you in advance for !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Lokat:

Couldn't open https://www.youtube.com/watch?v=JHdmkP-nfsA: java.io.FileNotFoundException: No content provider: https://www.youtube.com/watch?v=JHdmkP-nfsA
10-29 12:27:28.419 25932-25932/com.example.marco.ud D/MediaPlayer: setDataSource IOException | SecurityException happend : 
                                                                   java.io.FileNotFoundException: No content provider: https://www.youtube.com/watch?v=JHdmkP-nfsA
                                                                       at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1137)
                                                                       at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:988)
                                                                       at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:911)
                                                                       at android.media.MediaPlayer.attemptDataSource(MediaPlayer.java:1102)
                                                                       at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1093)
                                                                       at android.widget.VideoView.openVideo(VideoView.java:356)
                                                                       at android.widget.VideoView.-wrap0(VideoView.java)
                                                                       at android.widget.VideoView$7.surfaceCreated(VideoView.java:632)
                                                                       at android.view.SurfaceView.updateWindow(SurfaceView.java:656)
                                                                       at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:172)
                                                                       at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:1013)
                                                                       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2510)
                                                                       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1519)
                                                                       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7113)
                                                                       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:927)
                                                                       at android.view.Choreographer.doCallbacks(Choreographer.java:702)
                                                                       at android.view.Choreographer.doFrame(Choreographer.java:638)
                                                                       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:913)
                                                                       at android.os.Handler.handleCallback(Handler.java:751)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                       at android.os.Looper.loop(Looper.java:154)
                                                                       at android.app.ActivityThread.main(ActivityThread.java:6780)
                                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)

Solution

You cannot play YouTube videos directly on VideoView or ExoPlayer, to do this, you must first download the video and then set the video to the method VideoView.setVideoPath("path").

The locale path

If you only want to play YouTube videos, use YouTube Android Player API , if you just want to play other remote videos (.mp4, .ogg, .3gp, etc.), use the method VideoView.setVideoURI("uri").

Example –

String videoUrl = "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4";

try {
         Start the MediaController
        MediaController mediacontroller = new MediaController(this);
        mediacontroller.setAnchorView(videoview);
         Get the URL from String videoUrl
        Uri video = Uri.parse(videoUrl);
        videoview.setMediaController(mediacontroller);
        videoview.setVideoURI(video);

} catch (Exception e) {
        Log.e("Error", e.getMessage());
        e.printStackTrace();
    }

videoview.setOnPreparedListener(new OnPreparedListener() {
        public void onPrepared(MediaPlayer mp) {
            videoview.start();
        }
    });

Related Problems and Solutions