MainActivity.cs 1.55 KB
Newer Older
1
using Android.App;
2 3 4 5 6
using Android.OS;
using Android.Views;
using Android.Widget;
using VideoView = LibVLCSharp.Platforms.Android.VideoView;
using LibVLCSharp.Shared;
7
using LibVLCSharp.Android.Sample;
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

namespace LibVLCSharp.Android
{
    [Activity(Label = "@string/app_name", MainLauncher = true)]
    public class MainActivity : Activity
    {
        VideoView _videoView;
        LibVLC _libVLC;
        MediaPlayer _mediaPlayer;

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.main);
        }
        
        protected override void OnResume()
        {
            base.OnResume();

            Core.Initialize();

            _libVLC = new LibVLC();
            _mediaPlayer = new MediaPlayer(_libVLC);

            _videoView = new VideoView(this) { MediaPlayer = _mediaPlayer };
            AddContentView(_videoView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent));
Martin Finkel's avatar
Martin Finkel committed
35
            var media = new Media(_libVLC, "https://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4", FromType.FromLocation);
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
            var configuration = new MediaConfiguration();
            configuration.EnableHardwareDecoding();
            media.AddOption(configuration);
            _videoView.MediaPlayer.Play(media);
        }

        protected override void OnPause()
        {
            base.OnPause();

            _videoView.MediaPlayer.Stop();
            _videoView.Dispose();
        }
    }
}