Мы разрабатываем приложение Xamarin.Froms, и у нас возникли некоторые проблемы с видеопроигрывателем: текущий код работает нормально при отладке или, в частности, когда включена среда выполнения shred.
Пакет:
<PackageReference Include="LibVLCSharp.Forms" Version="3.4.6" />
<PackageReference Include="Xamarin.Forms" Version="4.7.0.1239" />
<TargetFramework>netstandard2.0</TargetFramework>
Android Пакет:
<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>