summaryrefslogtreecommitdiff
path: root/NewPlayer/NewPlayer/Views/MediaRenderingView.xaml.cs
blob: 7e4ef0c032a5d54d56b3490a87cb89bdcbadec43 (plain)
1
2
3
4
5
6
7
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using Xamarin.Forms;
using NewPlayer.Models;

namespace NewPlayer.Views
{
    public enum PlayerStatus
    {
        Playing,
        Paused,
        Stopped,
        Preparing,
    }

    public partial class MediaRenderingView : View
    {
        // Creating a bindable property named "Items" of type IEnumrable<MediaItem> which is owned by LibraryView and has default value null.
        public static readonly BindableProperty PlayingItemProperty = BindableProperty.Create("PlayingItem", typeof(MediaItem), typeof(MediaRenderingView), null);

        public MediaItem PlayingItem
        {
            get { return (MediaItem)GetValue(PlayingItemProperty); }
            set { SetValue(PlayingItemProperty, value); }
        }

        public string ItemPath
        {
            get { return PlayingItem?.Path; }
        }

        private PlayerStatus playerStatus;

        public PlayerStatus PlayerStatus
        {
            get
            {
                return playerStatus;
            }
            set
            {
                playerStatus = value;
                OnPropertyChanged();
            }
        }

        public int CurrentPosition
        {
            get
            {
                return PlayingItem != null ? PlayingItem.Position : 0;
            }
            set
            {
                if (PlayingItem != null)
                {
                    PlayingItem.Position = value;
                    OnPropertyChanged();
                }
            }
        }

        public MediaRenderingView()
        {
            InitializeComponent();
        }

        public void Play()
        {
            PlayerStatus = PlayerStatus.Playing;
        }

        public void Pause()
        {
            PlayerStatus = PlayerStatus.Paused;
        }

        public void Preparing()
        {
            PlayerStatus = PlayerStatus.Preparing;
        }

        public void Stop()
        {
            PlayerStatus = PlayerStatus.Stopped;
        }
    }
}