11

I have got problem with my idea on andriod app. I'd like to play video in it, but I don't want to download it from interenet. In other case, I want to have it on device.

So, person is download it from android market and can play video without downloading it. I have came up with some solutions for it but none is good.

First one was adding it to application resources, but you can't have video in there.

Second one was adding or better creating folder during install (more specyfic first onCreate method) and then copying there video from app. Well, not so bad option (you can for example download then one time only video from web using background service) but I have no idea how to delete in on uninstall since your app don`t know when it is unistalled.

So does anyone know or have any idea on it?

sebap123
  • 2,541
  • 6
  • 45
  • 81

2 Answers2

19

You can put a video into app resources - just put it into res/raw folder. You can play it like this:

VideoView videoview = (VideoView) findViewById(R.id.videoview);

Uri uri = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.splash);

videoview.setVideoURI(uri);
videoview.start();

The main thing to consider here is the size of your video. As video files can be quite large, your resulting apk file can also get unacceptably large. Personally, I would rarely want to download an app from the market that weighs in at 10 meg (there are exceptions, of course).

Aleks G
  • 56,435
  • 29
  • 168
  • 265
  • I made [an example of this](http://stackoverflow.com/a/41061887/3681880) that shows a little more context. I found that using `ffmpeg` I could get short video clips to a very reasonable size while still retaining acceptable quality. – Suragch Dec 09 '16 at 13:52
  • 1
    @Suragch whatever you consider "reasonable size" today is totally different from what "reasonable size" was 5 years ago. Today I won't hesitate publishing an app that's over 10 megs; 5 years ago, one of my client's requirements was that the overall app is not more than 1 meg. – Aleks G Dec 09 '16 at 14:05
-1
videoView = (VideoView) findViewById(R.id.videoview);

videoview.setVideoPath("android.resource://" getPackageName() + "/" + R.raw.nameofvideofile);

videoView.start();
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
  • 3
    While this may answer the question, it is better to include the essential parts of the answer as it will attract more upvotes and be clear to the user who asked the question what they have to change. – Tyler2P Dec 01 '20 at 19:25
  • 3
    This basically repeats the code from the 9 year old accepted answer, and adds nothing new. – Mark Rotteveel Dec 02 '20 at 11:10