我正在尝试使用Xamarin.Forms.Android在初始屏幕上播放视频。启动应用程序时,我只能看到白色的空白屏幕。视频播放完毕后,我的主要活动将按预期加载。我在调试日志中没有看到有关VideoView的任何异常。您能帮我个忙吗?谢谢。
我正在使用Xamarin.Forms共享项目。我安装了最新版本的Xamarin.Android.Support库。我创建了一个初始布局和初始活动。最低Android版本为4.4,目标版本为8.1(API级别27)。我将视频作为video.mp4文件放在Resources \ raw文件夹中。
SplashLayout:
<?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>
styles.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>
VideoSplashActivity.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.
答案 0 :(得分:0)
protected override void OnResume()
{
base.OnResume();
SimulateStartup();
}
似乎问题是OnResume覆盖中的“ SimulateStartup()”方法。我将其删除,然后按预期播放了视频。