如何将视频播放和资源添加到android应用程序 [英] How to add video playback and resource to android application

查看:146
本文介绍了如何将视频播放和资源添加到android应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Android 应用程序的想法有异议.我想在其中播放视频,但不想从 Internet 下载.在其他情况下,我想在设备上使用它.

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.

第二个是在安装过程中添加或更好地创建文件夹(更具体的第一个 onCreate 方法),然后从应用程序复制视频.嗯,不错的选择(例如,您可以使用后台服务从网络下载一次视频),但我不知道如何在卸载时删除,因为您的应用不知道何时卸载.

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?

推荐答案

可以将视频放入应用资源 - 只需将其放入 res/raw 文件夹.你可以这样玩:

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

此处需要考虑的主要问题是视频的大小.由于视频文件可能非常大,因此生成的 apk 文件也可能变得无法接受.就我个人而言,我很少想从市场上下载重量为 10 兆的应用程序(当然也有例外).

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

这篇关于如何将视频播放和资源添加到android应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆