How to add video playback and resource to android application
Asked Answered
P

2

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?

Passim answered 25/12, 2011 at 12:28 Comment(0)
E
20

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

Earthy answered 25/12, 2011 at 12:37 Comment(2)
I made an example of this 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.Paracelsus
@Paracelsus 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.Earthy
F
-1
videoView = (VideoView) findViewById(R.id.videoview);

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

videoView.start();
Fogarty answered 1/12, 2020 at 15:20 Comment(2)
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.Aho
This basically repeats the code from the 9 year old accepted answer, and adds nothing new.Leonardo

© 2022 - 2024 — McMap. All rights reserved.