ItemDetailViewModel.cs 808 Bytes
Newer Older
Martin Finkel's avatar
Martin Finkel committed
1
using LibVLCSharp.Shared;
2 3 4 5 6 7
using LocalNetwork.Models;

namespace LocalNetwork.ViewModels
{
    public class ItemDetailViewModel : BaseViewModel
    {
Martin Finkel's avatar
Martin Finkel committed
8 9 10 11 12
        readonly Item _item;

        public ItemDetailViewModel(Item item)
        {
            _item = item;
Martin Finkel's avatar
Martin Finkel committed
13 14

            _mediaPlayer = new MediaPlayer(item.Media);
Martin Finkel's avatar
Martin Finkel committed
15 16 17 18
        }

        private MediaPlayer _mediaPlayer;
        public MediaPlayer MediaPlayer
19
        {
Martin Finkel's avatar
Martin Finkel committed
20 21
            get => _mediaPlayer;
            private set => SetProperty(ref _mediaPlayer, value);
22
        }
Martin Finkel's avatar
Martin Finkel committed
23 24 25 26 27 28 29 30 31 32 33 34 35

        public void Play()
        {
            MediaPlayer = _mediaPlayer;
            MediaPlayer.Play();
        }

        public void Stop()
        {
            MediaPlayer.Stop();
            MediaPlayer.Dispose();
            _item.Media.Dispose();
        }
36
    }
Martin Finkel's avatar
Martin Finkel committed
37
}