Reputation: 1
I am trying to play a video as a Splash Screen in Android using Xamarin
. I found the link below but I am getting 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.
play video in Android using Xamarin
[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();
}
}
Upvotes: 0
Views: 1073