3

I'm beginner in android and want to play gif animation in android video view so my gif file in this image show:
enter image description here


and write this code for play that:

VideoView videoView = (VideoView)findViewById(R.id.video_view);
        videoView.setVideoPath("raw/newline.gif");
        videoView.start();


but when run that app,i get error,can not play this video,why?

user3671271
  • 551
  • 2
  • 8
  • 21

1 Answers1

2

Try this code:

Uri uri= Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.newline);
videoView.setVideoURI(uri);
videoView.start();

Your mistake is that you can't just specify a path to resource file. In this case you have to use Uri.

But AFAIK VideoView can't play gif. So check out this and this solutions.

Community
  • 1
  • 1
Lingviston
  • 5,479
  • 5
  • 35
  • 67