我正在尝试使用Xamarin Android项目中的VideoView播放本地mp4视频文件。视频在调试模式下工作,但在发布模式下崩溃。
这就是我所做的。
我在资源文件夹中创建了一个“Raw”文件夹,并将视频文件放入其中。我确保将Build属性设置为“Android资源”,并且我也尝试使用和不检查“复制”输出目录“选项也是。
我尝试过不同大小的视频文件:5MB,1.2MB和740KB(均为单独)
var videoView = FindViewById<VideoView> (Resource.Id.SampleVideoView);
var mediControls = new MediaController (this);
var uri = Android.Net.Uri.Parse("android.resource://" + PackageName + "/"+Resource.Raw.testvideo);
videoView.SetVideoURI(uri);
videoView.SetMediaController (mediControls);
videoView.Visibility = ViewStates.Visible;
videoView.Start ();
以下是抛出的异常
[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] Java.Lang.RuntimeException: Exception of type 'Java.Lang.RuntimeException' was thrown.
[MonoDroid] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x00028>
[MonoDroid] at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (intptr,intptr,intptr,Android.Runtime.JValue*) <0x000e7>
[MonoDroid] at Android.App.Activity.SetContentView (int) <0x001d3>
[MonoDroid] at Talkative_Parents.EulaActivity.OnCreate (Android.OS.Bundle) <0x00033>
[MonoDroid] at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) <0x0005b>
[MonoDroid] at (wrapper dynamic-method) object.a9697909-b7c3-4854-9da3-0ca8569ec268 (intptr,intptr,intptr) <0x00043>
[MonoDroid] --- End of managed exception stack trace ---
[MonoDroid] java.lang.NullPointerException
[MonoDroid] at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:392)
[MonoDroid] at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:246)
[MonoDroid] at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
[MonoDroid] at md58b22d079704faa69564ee4d4fd03e330.EulaActivity.n_onCreate(Native Method)
[MonoDroid] at md58b22d079704faa69564ee4d4fd03e330.EulaActivity.onCreate(EulaActivity.java:30)
[MonoDroid] at android.app.Activity.performCreate(Activity.java:5541)
[MonoDroid] at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
[MonoDroid] at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2368)
[MonoDroid] at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464)
[MonoDroid] at android.app.ActivityThread.access$900(ActivityThread.java:172)
[MonoDroid] at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
[MonoDroid] at android.os.Handler.dispatchMessage(Handler.java:102)
[MonoDroid] at android.os.Looper.loop(Looper.java:146)
[MonoDroid] at android.app.ActivityThread.main(ActivityThread.java:5653)
[MonoDroid] at java.lang.reflect.Method.invokeNative(Native Method)
[MonoDroid] at java.lang.reflect.Method.invoke(Method.java:515)
[MonoDroid] at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
[MonoDroid] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
[MonoDroid] at dalvik.system.NativeStart.main(Native Method)
[Xamarin.Insights] Warning: Could not write journal: Internal error Flush
[Xamarin.Insights] {"InnerException": null,"HelpLink": null,"HResult": -2146233087,"Message": "Internal error Flush","Source": "System","StackTrace": " at System.IO.Compression.DeflateStreamNative.CheckResult (Int32 result, System.String where) [0x00000] in <filename unknown>:0 \n at System.IO.Compression.DeflateStreamNative.Flush () [0x00000] in <filename unknown>:0 \n at System.IO.Compression.DeflateStream.Flush () [0x00000] in <filename unknown>:0 \n at System.IO.Compression.GZipStream.Flush () [0x00000] in <filename unknown>:0 \n at Xamarin.InsightsCore.IOWriter.WriteDiskImage (System.String fileName, System.String stringToWrite) [0x00000] in <filename unknown>:0 ","TargetSite": "CheckResult","Data": {},"getType": "System.IO.IOException"}
[Xamarin.Insights] Warning: Unhandled exception: System.IO.IOException: Internal error Flush
[Xamarin.Insights] at System.IO.Compression.DeflateStreamNative.CheckResult (Int32 result, System.String where) [0x00000] in <filename unknown>:0
[Xamarin.Insights] at System.IO.Compression.DeflateStreamNative.Flush () [0x00000] in <filename unknown>:0
[Xamarin.Insights] at System.IO.Compression.DeflateStream.Flush () [0x00000] in <filename unknown>:0
[Xamarin.Insights] at System.IO.Compression.GZipStream.Flush () [0x00000] in <filename unknown>:0
[Xamarin.Insights] at Xamarin.InsightsCore.IOWriter.WriteDiskImage (System.String fileName, System.String stringToWrite) [0x00000] in <filename unknown>:0
[Xamarin.Insights] Warning: Unhandled exception: Java.Lang.RuntimeException: Exception of type 'Java.Lang.RuntimeException' was thrown.
[Xamarin.Insights] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x00028>
[Xamarin.Insights] at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (intptr,intptr,intptr,Android.Runtime.JValue*) <0x000e7>
[Xamarin.Insights] at Android.App.Activity.SetContentView (int) <0x001d3>
[Xamarin.Insights] at Talkative_Parents.EulaActivity.OnCreate (Android.OS.Bundle) <0x00033>
[Xamarin.Insights] at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) <0x0005b>
[Xamarin.Insights] at (wrapper dynamic-method) object.a9697909-b7c3-4854-9da3-0ca8569ec268 (intptr,intptr,intptr) <0x00043>
[Xamarin.Insights]
[Xamarin.Insights] --- End of managed exception stack trace ---
[Xamarin.Insights] java.lang.NullPointerException
[Xamarin.Insights] at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:392)
[Xamarin.Insights] at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:246)
[Xamarin.Insights] at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
[Xamarin.Insights] at md58b22d079704faa69564ee4d4fd03e330.EulaActivity.n_onCreate(Native Method)
[Xamarin.Insights] at md58b22d079704faa69564ee4d4fd03e330.EulaActivity.onCreate(EulaActivity.java:30)
[Xamarin.Insights] at android.app.Activity.performCreate(Activity.java:5541)
[Xamarin.Insights] at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
[Xamarin.Insights] at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2368)
[Xamarin.Insights] at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464)
[Xamarin.Insights] at android.app.ActivityThread.access$900(ActivityThread.java:172)
[Xamarin.Insights] at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
[Xamarin.Insights] at android.os.Handler.dispatchMessage(Handler.java:102)
[Xamarin.Insights] at android.os.Looper.loop(Looper.java:146)
[Xamarin.Insights] at android.app.ActivityThread.main(ActivityThread.java:5653)
[Xamarin.Insights] at java.lang.reflect.Method.invokeNative(Native Method)
[Xamarin.Insights] at java.lang.reflect.Method.invoke(Method.java:515)
[Xamarin.Insights] at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
[Xamarin.Insights] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
[Xamarin.Insights] at dalvik.system.NativeStart.main(Native Method)