XAML Xamarin表单视频播放器(MediaManager插件)

31moq8wy  于 2022-12-07  发布在  其他
关注(0)|答案(4)|浏览(203)

我对Xamarin很陌生...
我正在尝试创建一个像youtube一样的应用程序。我不知道如何在我的应用程序中播放视频。我试过使用MediaManager插件https://github.com/martijn00/XamarinMediaManager,但根本弄不明白。
如果有人能建议一个不同的插件,或者详细解释如何使用MediaManager插件,那将是非常棒的。
插件上的文档很糟糕,我根本看不懂。
到目前为止,我有:我只是想通过点击按钮来播放视频。
XAML文件:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="App2.Video_Play_Page"
         Title="Video_Play_Page"
         BackgroundColor="#4B1388">
<ContentPage.Content>
    <StackLayout Padding="10, 10, 10, 10">

        <Label Text="video Player..." />

        <Button Clicked="PlayVideo" Text="Play me!"/>
    </StackLayout>
</ContentPage.Content>

Xaml.cs档案:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

using Plugin.MediaManager;

namespace App2
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Video_Play_Page : ContentPage
{
    public Video_Play_Page()
    {
        InitializeComponent();
    }

    private void PlayVideo(object sender, EventArgs e)
    {
        CrossMediaManager.Current.Play("https://www.youtube.com/watch?v=Gm8bQxnold0");
    }
}
}

注意:我不知道我是否安装正确。如果有人能解释一下,那也太好了。

3hvapo4f

3hvapo4f1#

你那里几乎什么都有。
您需要示例化播放器,如
在.xaml文件中

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="App2.Video_Play_Page"
    Title="Video_Play_Page"
    BackgroundColor="#4B1388"
    xmlns:forms="clr-namespace:Plugin.MediaManager.Forms;assembly=Plugin.MediaManager.Forms">
    <ContentPage.Content>
        <StackLayout Padding="10, 10, 10, 10">

            <Label Text="video Player..." />
            <forms:VideoView />
            <Button Clicked="PlayVideo" Text="Play me!"/>
        </StackLayout>
    </ContentPage.Content>

或在.xaml.cs文件中

new VideoView { };

但是对于你的代码我建议第一个选择。
然后你会告诉插件,你想重现视频,而不是音频。

private void PlayVideo(object sender, EventArgs e)
{
    CrossMediaManager.Current.Play("https://www.youtube.com/watch?v=Gm8bQxnold0", MediaFileType.Video);
}

我不是舒尔如果插件再现视频与youtube的网址,如果这不工作,你应该取代网址与一个绝对的网址一样
https://sec.ch9.ms/ch9/37af/240037cc-e74a-421a-9946-7ce4205d37af/DiAndIocForXamarinForms.mp4
Here is a video to help you

mpbci0fu

mpbci0fu2#

你应该把表单:VideoView放在你的Xaml文件中这里是一个在Xamarin中使用它的示例。表单,检查这个https://github.com/martijn00/XamarinMediaManager/tree/develop/Samples/Forms

ahy6op9u

ahy6op9u3#

Xamarin社区工具包

我建议您查看Xamarin.Community.Toolkit中的MediaElement
它是一个跨平台的视频播放器,在以下位置有详细的文档:
https://learn.microsoft.com/en-us/xamarin/community-toolkit/views/mediaelement
您可以用C#生成MediaElement,就像用Xamarin创建任何其他控件一样。它的工作方式与Image控件非常相似:允许您设置外观,是否显示平台默认视频控件等...
如果你对Xamarin很陌生,这里有一个来自上面链接的例子:

<MediaElement Source="https://sec.ch9.ms/ch9/5d93/a1eab4bf-3288-4faf-81c4-294402a85d93/XamarinShow_mid.mp4"
              ShowsPlaybackControls="True" />

和C#中的对等用法:

MediaElement videoPlayer = new MediaElement
{

    Source = "https://sec.ch9.ms/ch9/5d93/a1eab4bf-3288-4faf-81c4294402a85d93/XamarinShow_mid.mp4",
    ShowsPlaybackControls = false

};

它可以添加到任何视图中,添加方式与添加LabelButton或继承View类的任何其他控件相同。
Gerald Versluis(Xamarin团队成员)的一个实用教程可以在这里找到,它详细介绍了你可以用插件做的所有事情(以及一些常见错误和如何修复它们):
https://www.youtube.com/watch?v=yJAKkz17WDo

nafvub8i

nafvub8i4#

如果还有人感兴趣的话,这是一个适用于使用Xamarin的Android和iOS的简单工作示例。CommunityToolkit的MediaElement
xam-mediaelement-sample

相关问题