有没有办法让一个URL中的Andr​​oid扩展文件中的特定文件? [英] Is there a way to get a Url to a specific file in Android expansion file?

查看:124
本文介绍了有没有办法让一个URL中的Andr​​oid扩展文件中的特定文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个应用程序的PhoneGap,其中含有大量的音频和视频文件。在Android上的媒体文件,应该是在扩展文件保持应用程序的大小谷歌下播放50 MB的限制。

I am building a PhoneGap application, which contains large audio and video files. In Android the media files should be in an expansion file to keep the application size under the Google Play 50 MB limit.

我目前正在考虑两种方式来播放视频文件:

I'm currently considering two ways to play the video files:


  1. 解压(也许是暂时的),从扩展文件所需的视频文件到SD卡,得到它的URL,并启动媒体播放器应用程序。拆包需要花费一些时间,因此用户将不得不等待根据视频的大小在几秒钟。

  2. 使用Android的VideoView类写我自己的视频播放器的PhoneGap插件。这样我可以直接从扩展文件播放无需拆包首先将文件,并获得更多敏感的应用。

不过,我不知道是否有一种方式来获得一个网址到扩展文件中的视频文件?这将使我的应用程序的URL添加到与该用户的preferred媒体播放器应用程序启动的意图,我会preFER这种方法。

However, I wonder if there is a way to get a URL to the video files inside the expansion file? That would allow my application to add the URL to the Intent with which the user's preferred media player application is started and I would prefer this approach.

推荐答案

我发现自己的方式,通过内容提供商做到这一点。我有一个关于从问题的Andr​​oid播放电影扩展文件里面的内容提供商提示,虽然在这一问题的URL不用于启动外部应用程序。

I found myself a way to do this through a content provider. I got a hint about the Content Provider from question android play movie inside expansion file, although in that question the URL was not used to start an external application.

我们需要扩展谷歌的APEZProvider一个ContentProvider类:

We need a ContentProvider class that extends Google's APEZProvider:

public class ZipFileContentProvider extends APEZProvider {
    @Override
    public String getAuthority() {
        return "com.example.expansionexperiment.provider";
    }
}

和需要将其添加到清单和出口:

And it needs to be added to Manifest and exported:

<provider
    android:exported="true"
    android:name="com.example.expansionexperiment.ZipFileContentProvider"
    android:authorities="com.example.expansionexperiment.provider" />

在清单和在getAuthority()当局必须是相同的。

The authority in the manifest and in getAuthority() must be the same.

现在我们可以创建一个URI来扩充档案里面的文件:

Now we can create a Uri to the file inside Expansion File:

// Filename inside my expansion file
String filename = "video/video.mp4";
String uriString = "content://com.example.expansionexperiment.provider" +  File.separator + filename;
Uri uri = Uri.parse(uriString);

// Start video view intent
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "video/*");
startActivity(intent);

内容提供商提供,现在进入zip文件,这些文件在短短的URL。

The content provider provides now access to the zip file and the files within just with the URL.

不过,PhoneGap的传媒插件不支持内容提供商,因为如果该URL不以http开始,它插入/ SD卡/在URL的前面。 (!)因此,通过压缩内容提供商播放音频文件,你需要编写自己的音频插件。

However, PhoneGap's Media plugin does not support content providers, because if the URL does not start with http, it inserts "/sdcard/" in front of the URL. (!!!) Therefore, to play audio files through the zip content provider, you will need to write your own audio plugin.

这篇关于有没有办法让一个URL中的Andr​​oid扩展文件中的特定文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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