usnkw
usnkw

Reputation: 31

Xamarin Forms LibVLC Video is not shown in Release configuration

We are developing an Xamarin.Froms App and we got some problems with the video player the flowing code is working fine in debug or more specifically when shred runtime is enabled.

Package:

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

Android Package:

    <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" />

Code behind for page:

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

Page:

<?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>

Upvotes: 1

Views: 618

Answers (1)

mfkl
mfkl

Reputation: 2184

Using r8 needs a bit more config.

Create a new file in your Xamarin.Android app root named "r8.cfg". In this file properties, set the Build Action to "ProguardConfiguration". In this file, add the following lines:

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

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

Upvotes: 1

Related Questions