简体   繁体   中英

Playing video as Splash Screen in Android using Xamarin

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();
    }
}

视频必须位于资源文件夹中,不能绘制

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM