I want to play a video from my assets or raw folder

前端 未结 6 1740
别那么骄傲
别那么骄傲 2020-12-05 05:55

I want to play a video from my assets or raw folder in my app in Android using VideoView I am getting the error as video cannot be played please anyone give me

相关标签:
6条回答
  • 2020-12-05 05:58

    When we include a video resource in /resource/raw/ or assets/, by default, it looks for the .mp4 format, it won't accept .wmv files. If you read video file from external locations(like: /mnt/sdcard/demo.wmv) then it'll accept them.

    0 讨论(0)
  • 2020-12-05 06:01

    Try:

       AssetFileDescriptor afd = getAssets().openFd(fileName);
       player.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(), afd.getLength());
    
    0 讨论(0)
  • 2020-12-05 06:04

    There are so many ways to go wrong with VideoView ! Mainly because the logcat gives you no help, always giving error UNKNOWN.

    I found this link was by far the best way to get started... A complete description so you can't go wrong. Thanks go to the author...

    http://androidexample.com/Play_Video_File_-_Android_Example/index.php?view=article_discription&aid=124&aaid=144

    0 讨论(0)
  • 2020-12-05 06:06

    A few things to note:

    1. You must copy the video into your project's res/raw folder.
    2. It must be in a supported format (3gp, wmv, mp4 ) and named with lower case, numerics, underscores and dots in its filename: my_video_file.mp4
    3. When you work with this resource in code, you will reference through the generated R statics - it will have the file extension removed: R.raw.my_video_file
    4. The Activity class has a helper method getPackageName() which can be used by your code when constructing the correct URI to your video.
    VideoView vv = (VideoView)this.findViewById(R.id.videoView)
    String uri = "android.resource://" + getPackageName() + "/" + R.raw.my_video_file;
    vv.setVideoURI(Uri.parse(uri));
    vv.start();
    

    There is more information on this here.

    0 讨论(0)
  • 2020-12-05 06:06

    You must include the package name in the uri:

      Uri uri = Uri.parse("android.resource://[package]/raw/video")
    

    or

      Uri uri = Uri.parse("android.resource://[package]/"+R.raw.video);
    

    Also, check out these examples.

    0 讨论(0)
  • 2020-12-05 06:23

    Make sure to write the file video name without extension.

    0 讨论(0)
提交回复
热议问题