Reputation: 959
I work on Xamarin Forms to make a page with a video player to play a local mp4 for Xamarin.Android.
So, I created a "raw" folder in my Xamarin.Droid (in Resources folder) and put my video with AndroidResource for compiler.
I use this plugin to display my video, because I don't want to have Controller, and I want to loop my video.
But, it said : Can't play video.
I think it's because it didn't found the video...
I don't know how I can fix it.
Thanks for your help
Upvotes: 0
Views: 2237
Reputation: 16652
Must I put my video in drawable, or assets or raw...?
You will need to place your video in raw, and for plugin, I'm not going to suggest any third-party plugin here, you may choose by your self. I here use Custom Renderer
to create a custom view to play local video use the official control VideoView
of Android platform.
For example:
Create MyVideoView
in PCL:
public class MyVideoView : View
{
}
Create its renderer in Android project:
[assembly: ExportRenderer(typeof(MyVideoView), typeof(MyVideoViewRenderer))]
namespace NameSpace.Droid
{
public class MyVideoViewRenderer : ViewRenderer
{
private VideoView videoview;
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.View> e)
{
base.OnElementChanged(e);
if (e?.NewElement == null || e.OldElement != null)
{
return;
}
if (Control == null)
{
videoview = new VideoView(Xamarin.Forms.Forms.Context);
SetNativeControl(videoview);
videoview.SetVideoPath("android.resource://" + Android.App.Application.Context.PackageName + "/" + Resource.Raw.one);
videoview.Start();
}
}
}
}
Since I directly give the local path to VideoView
in renderer, you can simply use this control in xaml like this:
<local:MyVideoView HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />
And because it is official VideoView
, there're a lot of samples show how to use it together with MediaController
if you'd like to have transport controller for it.
Upvotes: 1