Trying to use libvlcsharp.forms in xamarinForms project.
Need to play resource video files.
Installed libVLCsharp.Forms, VideoLan.LibVLC.Android, VideoLan.LibVLC.IOS
Copied an mp4 file to iosProject/Resources; marked as BundleResource.
Copied same file to androidProject/Resources/raw; marked as AndroidResource
- iOS can play from internet
- Anroid can play same online address as iOS
- ios can play resource file
- android can not play same resource file
Error > error with media file:////BigBuckBunny.mp4
Thought it did not like my mp4 file format or something like that.
downloaded the file which it could play from url.
tried that one instead.
same results.
Help !!!
While it(android) could play famous BigBuckBuny from url > http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4, it can not play same video downloaded and copied to AndroidProject/Resource/raw
XAML part:
<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 dataBinding:
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");
}
DataBinding Model:
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");
}
}
}