如何在Xamarin Android的资源文件夹中播放本地视频

时间:2013-10-31 16:42:07

标签: android xamarin.android xamarin

如何使用Xamarin Android引用我的assets文件夹中的视频文件以在我的videoView上播放。不确定如何正确引用资产文件夹。

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

1 个答案:

答案 0 :(得分:2)

试试这个:

var descriptor = Assets.OpenFd("big_buck_bunny.mp4");
var mediaPlayer = new MediaPlayer();
mediaPlayer.SetDataSource(descriptor.FileDescriptor, descriptor.StartOffset, descriptor.Length);
mediaPlayer.Prepare();
mediaPlayer.Start();