我目前正在使用Xamarin.Forms及其Media Plugin为我的应用录制视频。我已按照插件上的说明进行操作。 readme但是当我尝试录制视频时它仍然会给我这个错误。
Java.Lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference
06-22 16:21:24.741 I/mono-stdout( 3232): Java.Lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0
06-22 16:21:24.741 I/mono-stdout( 3232): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0
at Java.Interop.JniEnvironment+StaticMethods.CallStaticObjectMethod (Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00069] in <bd30a18775d94dc8b6263aecd1ca9077>:0
at Android.Runtime.JNIEnv.CallStaticObjectMethod (System.IntPtr jclass, System.IntPtr jmethod, Android.Runtime.JValue* parms) [0x0000e] in <d855bac285f44dda8a0d8510b679b1e2>:0
at Android.Support.V4.Content.FileProvider.GetUriForFile (Android.Content.Context context, System.String authority, Java.IO.File file) [0x00078] in <3e239b9681084d42bb949c1e01ef500e>:0
06-22 16:21:24.743 I/mono-stdout( 3232): at Java.Interop.JniEnvironment+StaticMethods.CallStaticObjectMethod (Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00069] in <bd30a18775d94dc8b6263aecd1ca9077>:0
06-22 16:21:24.743 I/mono-stdout( 3232): at Android.Runtime.JNIEnv.CallStaticObjectMethod (System.IntPtr jclass, System.IntPtr jmethod, Android.Runtime.JValue* parms) [0x0000e] in <d855bac285f44dda8a0d8510b679b1e2>:0
06-22 16:21:24.743 I/mono-stdout( 3232): at
Android.Support.V4.Content.FileProvider.GetUriForFile (Android.Content.Context context, System.String authority, Java.IO.File file) [0x00078] in <3e239b9681084d42bb949c1e01ef500e>:0
at Plugin.Media.MediaPickerActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00212] in C:\projects\mediaplugin\src\Media.Plugin.Android\MediaPickerActivity.cs:172
06-22 16:21:24.745 I/mono-stdout( 3232): at Plugin.Media.MediaPickerActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00212] in C:\projects\mediaplugin\src\Media.Plugin.Android\MediaPickerActivity.cs:172
这是我的代码
await CrossMedia.Current.Initialize();
if (!CrossMedia.Current.IsTakeVideoSupported || !CrossMedia.Current.IsCameraAvailable)
{
await DisplayAlert("Error", "Taking video is not supported on your device", "Ok");
return;
}
MediaFile file = await CrossMedia.Current.TakeVideoAsync(new StoreVideoOptions() // Exception thrown here
{
Name = "video.mp4",
Directory = "DefaultVideos"
});
这是我的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" package="com/myapp">
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="25" />
<uses-permission android:name="android.permission.CAPTURE_VIDEO_OUTPUT" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera"
android:required="true" />
<application android:label="MyApp" android:icon="@drawable/Icon">
<provider android:name="android.support.v4.content.FileProvider"
android:authorities="com.myapp.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"></meta-data>
</provider>
</application>
</manifest>
这是我的AssemblyInfo.cs
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Android.App;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MyApp")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MyApp")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
// Add some common permissions, these can be removed if not needed
[assembly: UsesPermission(Android.Manifest.Permission.Internet)]
和我的file_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="my_images" path="Pictures" />
<external-path name="my_movies" path="Videos" />
</paths>
编辑:更改后
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" package="com/myapp">
到
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" package="com.myapp">
我现在收到一个新错误:
06-23 14:55:25.305 I/mono-stdout( 3010): Java.Lang.IllegalArgumentException:
Failed to find configured root that contains /storage/emulated/0/Android/data/com.myapp/files/Movies/DefaultVideos/video.mp4
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0
at Java.Interop.JniEnvironment+StaticMethods.CallStaticObjectMethod (Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00069] in <bd30a18775d94dc8b6263aecd1ca9077>:0
at Android.Runtime.JNIEnv.CallStaticObjectMethod (System.IntPtr jclass, System.IntPtr jmethod, Android.Runtime.JValue* parms) [0x0000e] in <d855bac285f44dda8a0d8510b679b1e2>:0
at Android.Support.V4.Content.FileProvider.GetUriForFile (Android.Content.Context context, System.String authority, Java.IO.File file) [0x00078] in <3e239b9681084d42bb949c1e01ef500e>:0
06-23 14:55:25.305 I/mono-stdout( 3010): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0
at Plugin.Media.MediaPickerActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00212] in C:\projects\mediaplugin\src\Media.Plugin.Android\MediaPickerActivity.cs:172
关于这个错误的两件事似乎很奇怪。第一个是错误顶部的路径com.myapp
而不是com/myapp
。第二个是在错误的底部,它引用了一条不存在的路径,我不知道如何改变。