使用 Xamain.Forms.Android 在初始屏幕中播放视频



我正在尝试使用Xamarin.Forms.Android在启动屏幕上播放视频。当我启动应用程序时,我只能看到一个白色的空白屏幕。视频完成后,我的主要活动将按预期加载。我在调试日志中没有看到有关 VideoView 的任何异常。你能帮助或重定向我吗?谢谢。

我正在使用Xamarin.Forms共享项目。我安装了最新版本的Xamarin.Android.Support库。我创建了一个启动布局和启动活动。最低安卓版本为 4.4,目标版本为 8.1(API 级别 27(。我将视频作为视频.mp4文件放在资源\原始文件夹中。

启动画面布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="center"
android:id="@+id/appSplash"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<VideoView
android:id="@+id/splashVideo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true" />
</RelativeLayout>

款式.xml:

<resources>
<style name="MyTheme" parent="MyTheme.Base">
</style>
<!-- Base theme applied no matter what API -->
<style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
<item name="windowNoTitle">true</item>
<!--We will be using the toolbar so no need to show ActionBar-->
<item name="windowActionBar">false</item>
<!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette-->
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#1A1E83</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#1A1E83</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">#2B9E94</item>
<!--<item name="android:textColorPrimary">#FFFFFF</item>-->
<item name="actionMenuTextColor">#FFFFFF</item>
<item name="android:textColorSecondary">#FFFFFF</item>
<item name="android:colorActivatedHighlight">@android:color/transparent</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight and colorSwitchThumbNormal. -->
<item name="windowActionModeOverlay">true</item>
<item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
<!--Back Button OverWrite-->
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>
<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#FF4081</item>
</style>
<style name="DrawerArrowStyle" parent="@style/Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#FFFFFF</item>
</style>
<style name="AppToolbarTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:colorBackground">#FFFFFF</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:textColorPrimary">#FFFFFF</item>
</style>
<!--<item name="android:windowBackground">@drawable/splash_screen_land</item>-->
<style name="MyTheme.Splash" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowActionBar">true</item>
</style>
</resources>

视频飞溅活动.cs

[Activity(Icon = "@drawable/icon", Theme = "@style/MyTheme.Splash", ScreenOrientation = ScreenOrientation.Portrait, MainLauncher = true, NoHistory = true)]
public class VideoSplashActivity : AppCompatActivity
{
VideoView videoView;
static readonly string TAG = "X:" + typeof(VideoSplashActivity).Name;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Log.Debug(TAG, "VideoSplashActivity.OnCreate");
//set layout view
SetContentView(Resource.Layout.SplashLayout);
//access video view
videoView = FindViewById<VideoView>(Resource.Id.splashVideo);
//access the video
string videoPath = $"android.resource://{Application.PackageName}/{Resource.Raw.video}";
videoView.SetVideoPath(videoPath);
videoView.Start();
videoView.Completion += (sender,args)=>
{
SimulateStartup();
};
}
protected override void OnResume()
{
base.OnResume();
SimulateStartup();
}
private void SimulateStartup()
{
Log.Debug(TAG, "Startup work is finished - starting MainActivity.");
StartActivity(new Intent(Application.Context, typeof(MainActivity)));
}
}

调试日志的一部分

D/X:VideoSplashActivity(20832): VideoSplashActivity.OnCreate
D/Mono    (20832): DllImport searching in: '__Internal' ('(null)').
D/Mono    (20832): Searching for 'java_interop_jnienv_call_nonvirtual_object_method_a'.
D/Mono    (20832): Probing 'java_interop_jnienv_call_nonvirtual_object_method_a'.
D/Mono    (20832): Found as 'java_interop_jnienv_call_nonvirtual_object_method_a'.
D/Mono    (20832): DllImport searching in: '__Internal' ('(null)').
D/Mono    (20832): Searching for 'java_interop_jnienv_call_void_method_a'.
D/Mono    (20832): Probing 'java_interop_jnienv_call_void_method_a'.
D/Mono    (20832): Found as 'java_interop_jnienv_call_void_method_a'.
D/Mono    (20832): Assembly Ref addref Xamarin.Forms.Platform.Android[0xa55c6d00] -> Xamarin.Android.Support.v7.AppCompat[0xa55c6ac0]: 3
D/Mono    (20832): Image addref System[0x9417c8c0] -> System.dll[0x91551600]: 2
D/Mono    (20832): Prepared to set up assembly 'System' (System.dll)
D/Mono    (20832): Assembly System[0x9417c8c0] added to domain RootDomain, ref_count=1
D/Mono    (20832): AOT: image 'System.dll.so' not found: dlopen failed: library "/data/app/[PackageNameHere]-1/lib/arm/libaot-System.dll.so" not found
D/Mono    (20832): AOT: image '/Users/builder/jenkins/workspace/xamarin-android-d15-9/xamarin-android/external/mono/sdks/out/android-armeabi-v7a-release/lib/mono/aot-cache/arm/System.dll.so' not found: dlopen failed: library "/data/app/[PackageNameHere]-1/lib/arm/libaot-System.dll.so" not found
D/Mono    (20832): Config attempting to parse: 'System.dll.config'.
D/Mono    (20832): Config attempting to parse: '/Users/builder/jenkins/workspace/xamarin-android-d15-9/xamarin-android/external/mono/sdks/out/android-armeabi-v7a-release/etc/mono/assemblies/System/System.config'.
D/Mono    (20832): Assembly Ref addref netstandard[0x9417c620] -> System[0x9417c8c0]: 2
D/Mono    (20832): Assembly Ref addref Xamarin.Forms.Platform.Android[0xa55c6d00] -> Mono.Android[0x9417b960]: 32
D/Mono    (20832): Assembly Ref addref [AppNameHere].Droid[0xa55c49c0] -> Rg.Plugins.Popup[0xa55c5c80]: 2
Loaded assembly: System.dll [External]
D/X:VideoSplashActivity(20832): Startup work is finished - starting MainActivity.
protected override void OnResume()
{
base.OnResume();
SimulateStartup();
}

似乎问题是OnResume覆盖中的"模拟启动(("方法。我删除了它,然后按预期播放了视频。

最新更新