1

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>
usnkw
  • 31
  • 4
  • The native MediaElement in Xamarin.Forms is available now .You could update the version of XF to latest and check the docs from https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/mediaelement . – Lucas Zhang Aug 05 '20 at 14:26
  • 1
    can you share logs please? `new LibVLC("--verbose=2")` – mfkl Aug 05 '20 at 14:57
  • Is it getting linked out? You might need to [manually preserve it](https://learn.microsoft.com/en-us/xamarin/android/deploy-test/linker#preserving-code). – Andrew Aug 05 '20 at 18:00
  • Can you share logs please? Can you reproduce with the official samples? – mfkl Aug 06 '20 at 13:17
  • might get linked out but it's been fine up until now so I dont think so – mfkl Aug 06 '20 at 13:18
  • @mfkl I have the exact same problem with Forms - can you please check my log below? – neuromouse Feb 04 '21 at 18:03

1 Answers1

1

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

mfkl
  • 1,914
  • 1
  • 11
  • 21