Analysis of video files in Android assets files _android

Source: Internet
Author: User

This article illustrates the problem of video files in Android playback assets files. Share to everyone for your reference, specific as follows:

Today did a function, is to play the project inside the video file, not playing SD card video files.

I started trying to put the video files in the assets file directory.

This is because it was written before WebView loaded the assets folder:

WebView = new WebView (this);
Webview.loadurl (file:///android_asset/sample3_8.html);

And so on, I try to put the video video.3gp in the assets directory and write the following code:

Intent it = new Intent (intent.action_view);
Uri uri = uri.parse (name);
It.setdataandtype (URI, "video/3gp");
StartActivity (IT);

Launched the Android player, prompting for some information (not logged), presumably means that the file cannot be played on the path below/Unable to find the path file.

Google a bit, the Chinese web page there is little solution to the explanation, according to the Convention, to http://stackoverflow.com search answers, found this post:

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

The final solution to the video files in the Android Project project is:

1. Put the video file under the Res/raw file of Project engineering.

2. The video file must be an Android support video format (3GP,WMV,MP4), and the name must be lowercase, data, underscores, for example: My_video_file.mp4

3. When you refer to this resource file in your code, you must use the Rstatics class and remove the suffix of the file: R.raw.my_video_file

4. This activity class should have a helper method Getpackagename () that makes it easier for you to construct the correct URI in your code.

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 ();

For more information on Android-related content readers can view the site: "Android Multimedia application Development Skills Summary", "Android Development introduction and Advanced Course", "Android debugging techniques and common problems solution summary", " Android Multimedia How-to Summary (audio, video, audio, etc), summary of Android Basic components usage, Android View tips Summary, Android layout layout tips and a summary of Android controls usage

I hope this article will help you with the Android program.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.