How do I reference the video file in my assets folder to play on my videoView using Xamarin Android. Not sure how to reference the assets folder properly.

public class VideoActivity : Activity
{
    protected override void OnCreate (Bundle bundle)
    {
        base.OnCreate (bundle);
        SetContentView (Resource.Layout.Video);
        var videoView = FindViewById<VideoView> (Resource.Id.SampleVideoView);

        var uri = Android.Net.Uri.Parse ("file:///android_asset/big_buck_bunny.mp4");
        videoView.SetVideoURI (uri);
        videoView.Start ();
    }
}
upvote
  flag
"file:///android_asset/" is only to load assets in webviews, Assets.OpenXX is the way to go – Benoit Jadinon

1 Answers 11

Try this:

var descriptor = Assets.OpenFd("big_buck_bunny.mp4");
var mediaPlayer = new MediaPlayer();
mediaPlayer.SetDataSource(descriptor.FileDescriptor, descriptor.StartOffset, descriptor.Length);
mediaPlayer.Prepare();
mediaPlayer.Start();
upvote
  flag
this only play's the audio – Mario Galván
upvote
  flag
you'll have to add the MediaPlayer to your view, video is technically playing, but in the background – Benoit Jadinon

Not the answer you're looking for? Browse other questions tagged or ask your own question.