简体   繁体   中英

How to play local video in assets folder in Xamarin Android

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 ();
    }
}

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM