[英]Playing video as Splash Screen in Android using Xamarin
我正在嘗試使用Xamarin
在Android中將視頻作為啟動屏幕播放。 我找到了下面的鏈接,但我正在獲取file not found exception
。 我嘗試以幾種不同的方式來走這條路,但沒有成功。
我的視頻Splash.mp4
在Resources內的drawable文件夾中,而SplashActivity.cs
文件在項目級別。
[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.