[英]Playing video as Splash Screen in Android using Xamarin
I am trying to play a video as a Splash Screen in Android using Xamarin
. 我正在尝试使用Xamarin
在Android中将视频作为启动屏幕播放。 I found the link below but I am getting file not found exception
. 我找到了下面的链接,但我正在获取file not found exception
。 I tried passing the path a few different ways but haven't had any success. 我尝试以几种不同的方式来走这条路,但没有成功。
My video Splash.mp4
is in drawable folder inside Resources and SplashActivity.cs
file is at project level. 我的视频Splash.mp4
在Resources内的drawable文件夹中,而SplashActivity.cs
文件在项目级别。
play video in Android using Xamarin 使用Xamarin在Android中播放视频
[Activity(Label = "SplashVideo", MainLauncher = true, NoHistory = true)]
public class SplashVideo : Activity, MediaPlayer.IOnPreparedListener, ISurfaceHolderCallback
{
VideoView videoView;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.VideoLayout);
videoView = FindViewById<VideoView>(Resource.Id.SampleVideoView);
play();
}
MediaPlayer player = new MediaPlayer();
void play()
{
ISurfaceHolder holder = videoView.Holder;
holder.SetType(SurfaceType.PushBuffers);
holder.AddCallback(this);
Android.Content.Res.AssetFileDescriptor afd = Resources.Assets.OpenFd("Splash.mp4");
if (afd != null)
{
player.SetDataSource(afd.FileDescriptor, afd.StartOffset, afd.Length);
player.Prepare();
player.Start();
}
}
public void SurfaceCreated(ISurfaceHolder holder)
{
Console.WriteLine("SurfaceCreated");
player.SetDisplay(holder);
}
public void SurfaceDestroyed(ISurfaceHolder holder)
{
Console.WriteLine("SurfaceDestroyed");
player.SetDisplay(null);
}
public void SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int w, int h)
{
Console.WriteLine("SurfaceChanged");
}
public void OnPrepared(MediaPlayer mp)
{
throw new NotImplementedException();
}
}
视频必须位于资源文件夹中,不能绘制
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.