Android: how to play video from assets?

后端 未结 5 1906
梦谈多话
梦谈多话 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 16:18

    Instead of accessing from assests,You must copy the video into your project's res/raw folder. Create raw folder under res folder. It must be in a supported format (3gp, wmv, mp4 ) and named with lower case, numerics, underscores and dots in its filename likewise:video_file.mp4.

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

提交回复
热议问题