尝试在 xamarinForms 项目中使用 libvlcsharp.forms。
需要播放资源视频文件。
安装了 libVLCsharp.Forms、VideoLan.LibVLC.Android、VideoLan.LibVLC.IOS
将 mp4 文件复制到 iosProject/Resources;标记为 BundleResource。
将相同的文件复制到 androidProject/Resources/raw;标记为 AndroidResource
- iOS可以从互联网播放
- Anroid可以播放和iOS一样的在线地址
- ios可以播放资源文件
- android不能播放相同的资源文件
错误> 媒体文件错误:////BigBuckBunny.mp4
以为它不喜欢我的 mp4 文件格式或类似的东西。
下载了它可以从 url 播放的文件。
而是尝试了那个。
相同的结果。
帮助 !!!
虽然它(android)可以从 url > http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4播放著名的 BigBuckBuny ,但它无法播放下载并复制到 AndroidProject/Resource/raw 的相同视频
XAML 部分:
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ParkinsonMobileApp.Pages.PhysicalActivitiesVideoDetail"
Padding="0"
Title="HomePage"
FlowDirection="LeftToRight"
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
ios:Page.UseSafeArea="False"
NavigationPage.HasNavigationBar="False"
xmlns:customViews="clr-namespace:ParkinsonMobileApp.Views"
BackgroundColor="White"
xmlns:vlc="clr-namespace:LibVLCSharp.Forms.Shared;assembly=LibVLCSharp.Forms"
Appearing="ContentPage_OnAppearing"
Disappearing="ContentPage_Disappearing">
<AbsoluteLayout
Padding="0"
Margin="0"
HorizontalOptions="Fill"
VerticalOptions="Fill">
<Image
x:Name="imgViewBackground"
Source="viewBackgroundBlurred.png"
Aspect="AspectFill"
AbsoluteLayout.LayoutFlags="All"
AbsoluteLayout.LayoutBounds="0,0,1,1" />
<vlc:MediaPlayerElement
x:Name="vlcPlayer"
MediaPlayer="{Binding MediaPlayer}"
LibVLC="{Binding LibVLC}"
EnableRendererDiscovery="True"
Padding="0"
Margin="0"
AbsoluteLayout.LayoutFlags="All"
AbsoluteLayout.LayoutBounds="0,0,1,1" />
<customViews:CustomNavigationBar
HorizontalOptions="Fill"
VerticalOptions="Start"
Padding="0"
Margin="0"
AbsoluteLayout.LayoutFlags="All"
AbsoluteLayout.LayoutBounds="0,0,1,1"
Theme="White"
ImgBackgroundIsVisible="False"
ButBackDisplayed="True"
ButsOnRightDisplayed="False"
TitleText="Egzersiz 001"
TitleIsDisplayed="True"
BackgroundColor="Transparent"
backClicked="CustomNavigationBar_backClicked" />
</AbsoluteLayout>
CodeBehind 数据绑定:
void ContentPage_OnAppearing(object sender, System.EventArgs e)
{
base.OnAppearing();
//pageViewModel = new VieoDetailViewModel("file://android_asset/024_1.mp4");
//pageViewModel = new VieoDetailViewModel("024_1.mp4");
pageViewModel = new VieoDetailViewModel("BigBuckBunny.mp4");
BindingContext = pageViewModel;
//MessagingCenter.Send(this, "AllowLandscape");
}
数据绑定模型:
public class VieoDetailViewModel : ViewModelBase
{
/// <summary>
/// Initialize LibVLC and playback when page appears
/// </summary>
public VieoDetailViewModel(String filePath)
{
Core.Initialize();
LibVLC = new LibVLC();
var media = new Media(LibVLC,
//"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4",
filePath,
//FromType.FromLocation
FromType.FromPath
);
MediaPlayer = new MediaPlayer(media) { EnableHardwareDecoding = true };
//MediaPlayer = new MediaPlayer(media);
MediaPlayer.Play(media);
}
/// <summary>
/// Gets the <see cref="LibVLCSharp.Shared.LibVLC"/> instance.
/// </summary>
public LibVLC _LibVLC;
public LibVLC LibVLC
{
get
{
return _LibVLC;
}
set
{
_LibVLC = value;
OnPropertyChanged("LibVLC");
}
}
/// <summary>
/// Gets the <see cref="LibVLCSharp.Shared.MediaPlayer"/> instance.
/// </summary>
public MediaPlayer _MediaPlayer;
public MediaPlayer MediaPlayer
{
get
{
return _MediaPlayer;
}
set
{
_MediaPlayer = value;
OnPropertyChanged("MediaPlayer");
}
}
}