简体   繁体   English

视频未在iOS项目中播放

[英]Video is not played in iOS project

I have used Plugin.MediaManager in my Xamarin.Forms application. 我在Xamarin.Forms应用程序中使用了Plugin.MediaManager。 It works perfectly in Android project, but in iOS project it does not. 它在Android项目中完美运行,但在iOS项目中则无效。

I have added 我已经添加了

VideoViewRenderer.Init();

in AppDelegate, and this is the code in the view: 在AppDelegate中,这是视图中的代码:

    async void PlayStop_Clicked(object sender, System.EventArgs e)
    {
        if (this.BtnPlayStop.Text == "Start Video")
        {
            string video = Path.Combine(_videoPath, this.viewModel.Item.Video);

            if (File.Exists(video))
            {
                await CrossMediaManager.Current.Play(video, MediaFileType.Video);

                this.BtnPlayStop.Text = "Stop Video";
            }
        }
        else
        {
            await CrossMediaManager.Current.Stop();

            this.BtnPlayStop.Text = "Start Video";
        }
    }

Code enters the first if, since button changes its text to 'Stop Video' but no video appears. 如果因为按钮将其文本更改为“停止视频”而没有视频出现,则代码进入第一个。 The video is a local mp4 file. 该视频是本地mp4文件。

As I told, this works perfect in Android. 就像我说的那样,这在Android上非常完美。

What's wrong? 怎么了?

Thanks 谢谢

Jaime 海梅

I have replaced the method that plays or stops the video by this one: 我已用此方法替换了播放或停止视频的方法:

    async void PlayStop_Clicked(object sender, System.EventArgs e)
    {
        if (this.BtnPlayStop.Text == "Iniciar Video")
        {
            string video = Path.Combine(_videoPath, this.viewModel.Item.Video);

            if (File.Exists(video))
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    _ = CrossMediaManager.Current.Play("file://" + video, MediaFileType.Video);
                });

                this.BtnPlayStop.Text = "Detener Video";
            }
        }
        else
        {
            await CrossMediaManager.Current.Stop();

            this.BtnPlayStop.Text = "Iniciar Video";
        }
    }

The "file://" part is important when loading local media files. 加载本地媒体文件时,“ file://”部分很重要。

With that method, it works in both Android and iOS. 使用这种方法,它可以在Android和iOS上运行。

Regards Jaime 问候海梅

Regards Jaime 问候海梅

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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