DVG
DVG

Reputation: 898

VideoView: Unable to open content and setDataSource failed

I am not able to open any video file with my application. i got a piece of code from StackOverFlow and used it, but it isn't working for me. I have the link as per it is on my gallery. But it is throwing the runtime error that content can't be opened. but i can play it with other players, this was a video taken with the phone btw...

public class VideoActivity extends Activity {

private VideoView mVideoView;
String path = "/storage/emulated/0/DCIM/Camera/VID_20151013_150537120.mp4";
//https://www.youtube.com/watch?v=r-M9Xhk026A

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_video);
    mVideoView = (VideoView) findViewById(R.id.surface_view);
    mVideoView.setVideoPath(path);
    mVideoView.setMediaController(new MediaController(this));
    mVideoView.requestFocus();
    mVideoView.start();
    //Bundle bundle = getIntent().getExtras();
    //String url = bundle.getString("url", "");
    //playVideoFromUrl(url);
}

private void playVideoFromUrl(String url) {
     mVideoView.setVideoURI(Uri.parse(url));
     mVideoView.setMediaController(new MediaController(this));
     mVideoView.requestFocus();
     mVideoView.start();
}  }

Error Logs are :

  I/OpenGLRenderer: Initialized EGL, version 1.4
  D/OpenGLRenderer: Enabling debug mode 0
      W/art: Suspending all threads took: 13.357ms
      W/VideoView: Unable to open content: /storage/emulated/0/DCIM/Camera/VID_20151013_150537120.mp4
      W/VideoView: java.io.IOException: setDataSource failed.
      W/VideoView:     at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1076)
      W/VideoView:     at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1022)
      W/VideoView:     at android.media.MediaPlayer.setDataSource(MediaPlayer.java:974)
      W/VideoView:     at android.widget.VideoView.openVideo(VideoView.java:352)
      W/VideoView:     at android.widget.VideoView.access$2100(VideoView.java:72)
      W/VideoView:     at android.widget.VideoView$7.surfaceCreated(VideoView.java:629)
      W/VideoView:     at android.view.SurfaceView.updateWindow(SurfaceView.java:579)
      W/VideoView:     at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:176)
      W/VideoView:     at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:847)
      W/VideoView:     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1986)
      W/VideoView:     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1077)
      W/VideoView:     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5884)
      W/VideoView:     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
      W/VideoView:     at android.view.Choreographer.doCallbacks(Choreographer.java:580)
      W/VideoView:     at android.view.Choreographer.doFrame(Choreographer.java:550)
      W/VideoView:     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
      W/VideoView:     at android.os.Handler.handleCallback(Handler.java:739)
      W/VideoView:     at android.os.Handler.dispatchMessage(Handler.java:95)
      W/VideoView:     at android.os.Looper.loop(Looper.java:135)
      W/VideoView:     at android.app.ActivityThread.main(ActivityThread.java:5312)
      W/VideoView:     at java.lang.reflect.Method.invoke(Native Method)
      W/VideoView:     at java.lang.reflect.Method.invoke(Method.java:372)
      W/VideoView:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
      W/VideoView:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
      D/VideoView: Error: 1,0

Upvotes: 3

Views: 6519

Answers (3)

Anthone
Anthone

Reputation: 2290

You only need

But take care this is a RuntimePermission too

if (ContextCompat.checkSelfPermission(this,
                        Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED ) {
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 0);
            return false;
}

Upvotes: 0

I tried with the permissions of WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE and it did not work.

In my case, it was enough to place the permit

<uses-permission android: name = "android.permission.INTERNET" />

Upvotes: 1

Namita
Namita

Reputation: 99

Check for the Permissions in AndroidManifest.xml.

uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"

uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"

This may help out.

Upvotes: 0

Related Questions