Android: how to play video from assets?

后端 未结 5 1903
梦谈多话
梦谈多话 2020-12-09 15:35

I am making an application in which I have to show video from assets folder in a Fragment. Can anyone help me do this? Do I need to use VideoView in XML?

5条回答
  •  佛祖请我去吃肉
    2020-12-09 15:54

    VideoView view = (VideoView)findViewById(R.id.videoView);
    String path = "android.resource://" + getPackageName() + "/" + R.raw.video_file;
    view.setVideoURI(Uri.parse(path));
    view.start();
    

    It's AkashG's code, but I remember that R here is not from the Android class. It's from your own project.

提交回复
热议问题