How to add video playback and resource to android application

sebap123 picture sebap123 · Dec 25, 2011 · Viewed 27.7k times · Source

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?

Answer

Aleks G picture Aleks G · Dec 25, 2011

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).