来自Expansion FIle的VideoView MediaPlayer.prepareAsync()的IllegalStateException

时间:2014-08-13 21:10:09

标签: java android apk-expansion-files

我试图从我的应用程序的obb扩展中的zip中加载mp4文件。我正在使用和扩展APEZProvider来获取视频文件的URI。然而;在我设置URI之后,应用程序崩溃并出现IllegalStateException。

使用VideoView的活动:

public class LaunchScreen extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    setContentView(R.layout.activity_launch_screen);
    TextView lets_explore = (TextView) findViewById(R.id.lets_explore);
    TextView explore = (TextView) findViewById(R.id.explore);
    VideoView video = (VideoView) findViewById(R.id.launch_video);
    ImageButton up = (ImageButton) findViewById(R.id.up_arrow);
    Typeface montserrat = Typeface.createFromAsset(getAssets(), "fonts/Montserrat-Bold.ttf");
    Typeface montserratR = Typeface.createFromAsset(getAssets(), "fonts/Montserrat-Regular.ttf");
    lets_explore.setTypeface(montserratR);
    explore.setTypeface(montserrat);
    video.setVideoURI(ZipContentProvider.buildUri("video.mp4"));
    up.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(LaunchScreen.this, MainActivity.class);
            startActivity(i);
        }
    });
}
}

Custom ApezProvider:

public class ZipContentProvider extends APEZProvider {
private static final String AUTHORITY = "com.example.provider.ZipContentProvider";

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

    contentPath.append(AUTHORITY);
    contentPath.append(File.separator);
    contentPath.append(pathIntoApk);

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

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

Manifest中的提供者:

<provider android:authorities="net.multieducator.telaviv.provider.ZipContentProvider" android:name=".ZipContentProvider"></provider>

堆栈追踪:

08-14 01:01:30.953: W/asset(14263): AssetManager-->addDefaultAssets CIP path not exsit!
08-14 01:01:32.050: E/MediaPlayer(14263): setDataSource: Null fd! uri=content://net.multieducator.telaviv.provider.ZipContentProvider/video.mp4
08-14 01:01:32.050: E/MediaPlayer(14263): prepareAsync called in state 1
08-14 01:01:32.058: W/dalvikvm(14263): threadid=1: thread exiting with uncaught exception (group=0x40d3a9a8)
08-14 01:01:32.100: E/AndroidRuntime(14263): FATAL EXCEPTION: main
08-14 01:01:32.100: E/AndroidRuntime(14263): java.lang.IllegalStateException
08-14 01:01:32.100: E/AndroidRuntime(14263):    at android.media.MediaPlayer.prepareAsync(Native Method)
08-14 01:01:32.100: E/AndroidRuntime(14263):    at android.widget.VideoView.openVideo(VideoView.java:323)
08-14 01:01:32.100: E/AndroidRuntime(14263):    at android.widget.VideoView$6.surfaceCreated(VideoView.java:614)
08-14 01:01:32.100: E/AndroidRuntime(14263):    at android.view.SurfaceView.updateWindow(SurfaceView.java:617)
08-14 01:01:32.100: E/AndroidRuntime(14263):    at android.view.SurfaceView.access$000(SurfaceView.java:88)
08-14 01:01:32.100: E/AndroidRuntime(14263):    at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:183)
08-14 01:01:32.100: E/AndroidRuntime(14263):    at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:680)
08-14 01:01:32.100: E/AndroidRuntime(14263):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2123)
08-14 01:01:32.100: E/AndroidRuntime(14263):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1139)
08-14 01:01:32.100: E/AndroidRuntime(14263):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4872)
08-14 01:01:32.100: E/AndroidRuntime(14263):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:776)
08-14 01:01:32.100: E/AndroidRuntime(14263):    at android.view.Choreographer.doCallbacks(Choreographer.java:579)
08-14 01:01:32.100: E/AndroidRuntime(14263):    at android.view.Choreographer.doFrame(Choreographer.java:548)
08-14 01:01:32.100: E/AndroidRuntime(14263):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:762)
08-14 01:01:32.100: E/AndroidRuntime(14263):    at android.os.Handler.handleCallback(Handler.java:800)
08-14 01:01:32.100: E/AndroidRuntime(14263):    at android.os.Handler.dispatchMessage(Handler.java:100)
08-14 01:01:32.100: E/AndroidRuntime(14263):    at android.os.Looper.loop(Looper.java:194)
08-14 01:01:32.100: E/AndroidRuntime(14263):    at android.app.ActivityThread.main(ActivityThread.java:5431)
08-14 01:01:32.100: E/AndroidRuntime(14263):    at java.lang.reflect.Method.invokeNative(Native Method)
08-14 01:01:32.100: E/AndroidRuntime(14263):    at java.lang.reflect.Method.invoke(Method.java:525)
08-14 01:01:32.100: E/AndroidRuntime(14263):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
08-14 01:01:32.100: E/AndroidRuntime(14263):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
08-14 01:01:32.100: E/AndroidRuntime(14263):    at dalvik.system.NativeStart.main(Native Method)

非常感谢任何帮助。 :)

1 个答案:

答案 0 :(得分:4)

问题最有可能出现在apk扩展文件中,视频必须存储在未压缩的存档中,否则MediaPlayer无法对其进行解码。

为Windows创建未压缩文件的方式 - &gt;如果使用Winrar或任何其他存档程序,可能有压缩方法 Store ,请使用

在Linux或OS X上打开终端并键入

zip -r -0 [desiredZipFileName.obb] [要添加的文件夹/文件]