gpt4 book ai didi

java - 来自扩展文件中的 VideoView MediaPlayer.prepareAsync() 的 IllegalStateException

转载 作者:行者123 更新时间:2023-12-01 18:28:10 35 4
gpt4 key购买 nike

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

使用 VideoView 的 Activity :

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

自定义 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;
}
}

list 中的提供者:

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

任何帮助将不胜感激。 :)

最佳答案

问题很可能出现在apk扩展文件中,视频必须存储在未压缩的存档中,否则MediaPlayer无法解码它们。

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

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

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

关于java - 来自扩展文件中的 VideoView MediaPlayer.prepareAsync() 的 IllegalStateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25296196/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com