我们正在开发一个 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>