1

我们正在开发一个 Xamarin.Froms 应用程序,我们在视频播放器方面遇到了一些问题,流动代码在调试中运行良好,或者更具体地说,在启用 shred 运行时时工作正常。

包裹:

    <PackageReference Include="LibVLCSharp.Forms" Version="3.4.6" />
    <PackageReference Include="Xamarin.Forms" Version="4.7.0.1239" />
    <TargetFramework>netstandard2.0</TargetFramework>

安卓包:

    <PackageReference Include="Xamarin.Forms" Version="4.7.0.1239" />
    <PackageReference Include="Xamarin.Android.Support.Design" Version="28.0.0.3" />
    <PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="28.0.0.3" />
    <PackageReference Include="Xamarin.Android.Support.v4" Version="28.0.0.3" />
    <PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="28.0.0.3" />
    <PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="28.0.0.3" />

页面背后的代码:

using LibVLCSharp.Shared;
using System;
using Xamarin.Forms;

namespace myTrekkaApp.Views
{
    public partial class TestPage : ContentPage
    {
        public TestPage()
        {
            InitializeComponent();
            Core.Initialize();
            LibVLC libVlc = new LibVLC();
            MediaPlayer mediaPlayer = new MediaPlayer(libVlc)
            {
                EnableHardwareDecoding = true,

            };
            mediaPlayer.Media = new Media(libVlc, new Uri("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4"));
            MediaPlayerElement.MediaPlayer = mediaPlayer;
            MediaPlayerElement.LibVLC = libVlc;
            MediaPlayerElement.IsVisible = true;
            mediaPlayer.Play();
        }
    }
}

页:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:vlc="clr-namespace:LibVLCSharp.Forms.Shared;assembly=LibVLCSharp.Forms"
             x:Class="myTrekkaApp.Views.TestPage">
    <vlc:MediaPlayerElement x:Name="MediaPlayerElement" />
</ContentPage>
4

1 回答 1

1

使用 r8 需要更多配置。

在您的 Xamarin.Android 应用根目录中创建一个名为“r8.cfg”的新文件。在此文件属性中,将 Build Action 设置为“ProguardConfiguration”。在此文件中,添加以下行:

-keep class org.videolan.** { *; }
-dontwarn org.videolan.**

https://code.videolan.org/videolan/LibVLCSharp/-/blob/3.x/docs/android.md

于 2021-02-05T03:12:16.670 回答