【问题标题】:Playing video as Splash Screen in Android using Xamarin使用 Xamarin 在 Android 中将视频作为启动画面播放
【发布时间】:2018-06-11 15:42:03
【问题描述】:

我正在尝试使用 Xamarin 在 Android 中将视频作为启动画面播放。我找到了下面的链接,但我收到了file not found exception。我尝试了几种不同的方式通过路径,但没有任何成功。

我的视频 Splash.mp4 位于 Resources 内的 drawable 文件夹中,SplashActivity.cs 文件位于项目级别。

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

【问题讨论】:

  • 请包含您的代码,而不是指向他人代码的链接。这将有助于更好地了解您可能做错了什么。
  • 至少向我们展示您如何告诉 Xamarin 文件位置在哪里...这可能是找出导致“找不到文件”问题的原因的快速方法。
  • 添加了我的代码。提前感谢您的帮助。
  • @user3660264 你能帮我解决这个问题吗?

标签: android video xamarin.android splash-screen


【解决方案1】:

视频必须在 assets 文件夹中,不可绘制

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-30
    • 2023-03-17
    • 2021-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多