Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android VideoView中的非法状态例外';扩展文件中的s MediaPlayer.prepareAsync()_Android_Android Videoview_Apk Expansion Files - Fatal编程技术网

Android VideoView中的非法状态例外';扩展文件中的s MediaPlayer.prepareAsync()

Android VideoView中的非法状态例外';扩展文件中的s MediaPlayer.prepareAsync(),android,android-videoview,apk-expansion-files,Android,Android Videoview,Apk Expansion Files,我有一个扩展文件(zip),里面装满了mp4视频,我想用VideoView播放这些视频。调用videoView.setVideoURI()时,它会在我的videoView的openVideo()中抛出和IllegalStateException(在状态1中调用prepareAsync)。我从扩展的APEZProvider类检索视频的URI public class ExpansionAPEZProvider extends APEZProvider { private static final

我有一个扩展文件(zip),里面装满了mp4视频,我想用VideoView播放这些视频。调用videoView.setVideoURI()时,它会在我的videoView的openVideo()中抛出和IllegalStateException(在状态1中调用prepareAsync)。我从扩展的APEZProvider类检索视频的URI

public class ExpansionAPEZProvider extends APEZProvider {

private static final String AUTHORITY = AndroidApplication.getApplication().getPackageName() + ".provider." + ExpansionAPEZProvider.class.getSimpleName();

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

        String newPath = contentPath.toString();

        return Uri.parse(newPath);
    }
}
扩展文件按如下方式打包并重命名为“main.3.com.my.application.obb”

视频视图:

Uri uri = ExpansionAPEZProvider.buildUri("vid_intro.mp4");
videoView = (VideoView) activity.findViewById(R.id.videoview);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();
自定义APEZ提供程序类

public class ExpansionAPEZProvider extends APEZProvider {

private static final String AUTHORITY = AndroidApplication.getApplication().getPackageName() + ".provider." + ExpansionAPEZProvider.class.getSimpleName();

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

        String newPath = contentPath.toString();

        return Uri.parse(newPath);
    }
}
buildUri()返回如下URI

"content://com.my.application.provider.ExpansionAPEZProvider/vid_intro.mp4"

清单中的提供程序:

<provider android:name=".ExpansionAPEZProvider"
        android:authorities="com.my.application.provider.ExpansionAPEZProvider"
        android:exported="false"
        android:multiprocess="true">

        <meta-data
            android:name="mainVersion"
            android:value="3"/>
    </provider>

谢谢你的帮助,我修好了。zip/obb文件一定已损坏。我按照上面的帖子所述通过终端再次打包,现在它可以工作了。我花了很长时间才找到问题。 用FileNotFoundException或IOException代替IllegalStateException对我定位问题会更有帮助

    V/WindowManager(  749): Adding window Window{683bb62 u0 SurfaceView} at 13 of 21 (before Window{22e3dff1 u0 com.my.application/com.my.application.activity.StartActivity})
    I/MediaFocusControl(  749):  AudioFocus  requestAudioFocus() from android.media.AudioManager@2335d19 req=1flags=0x0
    E/MediaPlayer(15769): prepareAsync called in state 1
    D/AndroidRuntime(15769): Shutting down VM
    E/AndroidRuntime(15769): FATAL EXCEPTION: main
    E/AndroidRuntime(15769): Process: com.my.application, PID: 15769
    E/AndroidRuntime(15769): java.lang.IllegalStateException
    E/AndroidRuntime(15769):    at android.media.MediaPlayer.prepareAsync(Native Method)
    E/AndroidRuntime(15769):    at android.widget.VideoView.openVideo(VideoView.java:356)
    E/AndroidRuntime(15769):    at android.widget.VideoView.access$2100(VideoView.java:72)
    E/AndroidRuntime(15769):    at android.widget.VideoView$7.surfaceCreated(VideoView.java:628)
    E/AndroidRuntime(15769):    at android.view.SurfaceView.updateWindow(SurfaceView.java:580)
    E/AndroidRuntime(15769):    at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:176)
    E/AndroidRuntime(15769):    at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944)
    E/AndroidRuntime(15769):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1970)
    E/AndroidRuntime(15769):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
    E/AndroidRuntime(15769):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885)
    E/AndroidRuntime(15769):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
    E/AndroidRuntime(15769):    at android.view.Choreographer.doCallbacks(Choreographer.java:580)
    E/AndroidRuntime(15769):    at android.view.Choreographer.doFrame(Choreographer.java:550)
    E/AndroidRuntime(15769):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
    E/AndroidRuntime(15769):    at android.os.Handler.handleCallback(Handler.java:739)
    E/AndroidRuntime(15769):    at android.os.Handler.dispatchMessage(Handler.java:95)
    E/AndroidRuntime(15769):    at android.os.Looper.loop(Looper.java:135)
    E/AndroidRuntime(15769):    at android.app.ActivityThread.main(ActivityThread.java:5254)
    E/AndroidRuntime(15769):    at java.lang.reflect.Method.invoke(Native Method)
    E/AndroidRuntime(15769):    at java.lang.reflect.Method.invoke(Method.java:372)
    E/AndroidRuntime(15769):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
    E/AndroidRuntime(15769):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
    W/ActivityManager(  749):   Force finishing activity 1 com.my.application/.activity.StartActivity
    W/DropBoxManagerService(  749): Dropping: data_app_crash (1630 > 0 bytes)
    I/WindowManager(  749): Screenshot max retries 4 of Token{2d07c562 ActivityRecord{3b01f344 u0 com.my.application/.activity.StartActivity t8900 f}} appWin=Window{683bb62 u0 SurfaceView} drawState=3