从扩展文件Android播放.mp4

时间:2015-01-28 19:38:37

标签: java android apk-expansion-files

我正在尝试使用android扩展文件,我正在尝试打包多个视频并在Android中的VideView中播放它们。我按照谷歌给出的所有说明,我知道有一些关于这个的帖子,我跟着他们,我仍然有一个错误。我确保在没有压缩的情况下压缩文件。所以我处于停滞状态。正如您所看到的,代码在APEZProvider.java:160失败。

我的错误是:

01-28 11:21:21.099: E/AndroidRuntime(3147): FATAL EXCEPTION: main
01-28 11:21:21.099: E/AndroidRuntime(3147): Process: com.myzendev.tourpure, PID: 3147
01-28 11:21:21.099: E/AndroidRuntime(3147): java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.AssetFileDescriptor com.myzendev.tourpure.android.vending.expansion.zipfile.ZipResourceFile.getAssetFileDescriptor(java.lang.String)' on a null object reference
01-28 11:21:21.099: E/AndroidRuntime(3147):     at com.myzendev.tourpure.android.vending.expansion.zipfile.APEZProvider.openAssetFile(APEZProvider.java:160)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at android.content.ContentProvider.openTypedAssetFile(ContentProvider.java:1486)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at android.content.ContentProvider.openTypedAssetFile(ContentProvider.java:1552)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at android.content.ContentProvider$Transport.openTypedAssetFile(ContentProvider.java:388)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1080)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:921)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:848)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at android.media.MediaPlayer.setDataSource(MediaPlayer.java:981)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at android.widget.VideoView.openVideo(VideoView.java:352)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at android.widget.VideoView.access$2100(VideoView.java:72)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at android.widget.VideoView$7.surfaceCreated(VideoView.java:628)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at android.view.SurfaceView.updateWindow(SurfaceView.java:579)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:176)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:847)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1956)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5779)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at android.view.Choreographer.doCallbacks(Choreographer.java:580)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at android.view.Choreographer.doFrame(Choreographer.java:550)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at android.os.Handler.handleCallback(Handler.java:739)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at android.os.Handler.dispatchMessage(Handler.java:95)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at android.os.Looper.loop(Looper.java:135)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at android.app.ActivityThread.main(ActivityThread.java:5221)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at java.lang.reflect.Method.invoke(Native Method)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at java.lang.reflect.Method.invoke(Method.java:372)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
01-28 11:21:21.099: E/AndroidRuntime(3147):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

清单:

<provider
        android:name=".ZipFileContentProvider"
        android:authorities="com.myzendev.ZipFileContentProvider">
    </provider>

这是我的代码:

public class ZipFileContentProvider extends APEZProvider {

    private static final String AUTHORITY = "com.myzendev.ZipFileContentProvider";

    @Override
    public String getAuthority() {
        return AUTHORITY;
    }

    public static Uri buildUri(String path) {
        StringBuilder contentPath = new StringBuilder("content://");

        contentPath.append(AUTHORITY);
        contentPath.append(File.separator);
        contentPath.append("new/");
        contentPath.append(path);

        return Uri.parse(contentPath.toString());
    }
}

的活动:

VideoView vv = (VideoView) rootView.findViewById(R.id.videoViewDay1);
Uri uri = ZipFileContentProvider.buildUri("corrosionvideo1.mp4");
vv.setVideoURI(uri);
vv.start();

0 个答案:

没有答案