File size: 5,225 Bytes
e26fba6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using MovieTube.Client.Scraper;
using ComponentFactory.Krypton.Toolkit;
using System.Diagnostics;

namespace MovieTube.Viewer
{
    public partial class WMPVideoPlayerWidget : BasePlayerWidget, IPlayerWidget
    {
        #region Fields

        private MovieLink currentPlayingLink;
        #endregion

        #region Constructor

        public WMPVideoPlayerWidget()
        {
            InitializeComponent();
            this.axWindowsMediaPlayer.stretchToFit = true;
        }


        #endregion

        #region Methods

        public bool PlayStart(MovieLink link, bool start = true)
        {
            this.headerGroupVideoPlayer.ValuesPrimary.Heading = String.Format("{0} - {1}", link.Parent.Name, link.Parent.ReleaseDate.Year);
            this.currentPlayingVideo = link;
            UpdateFavouriteButton(dataService.IsFavourite(this.currentPlayingVideo.Parent));

            SavePosition();
            this.currentPlayingLink = link;
            
            if (start)
                this.axWindowsMediaPlayer.URL = link.PlayUrl;
            
            return true;
        }

        public void PlayStop()
        {
            SavePosition();
            this.axWindowsMediaPlayer.URL = String.Empty;
            this.currentPlayingLink = null;
        }

        public void ActivateView()
        {
            try
            {
                if(this.axWindowsMediaPlayer.playState == WMPLib.WMPPlayState.wmppsPaused)
                    this.axWindowsMediaPlayer.Ctlcontrols.play();
            }
            catch { }
        }

        public void DeactivateView()
        {
            try
            {
                this.axWindowsMediaPlayer.Ctlcontrols.pause();
            }
            catch { }
        }

        public void TriggerSearch(Client.Scraper.SearchParameters param)
        {
            throw new NotImplementedException();
        }

        public void ShowBuffering()
        {

        }

        public void HideBuffering()
        {

        }

        private void UpdateFavouriteButton(bool fav)
        {
            this.buttonSpecHeaderFavourite.Checked = fav ?
                ButtonCheckState.Checked : ButtonCheckState.Unchecked;
        }

        private void ToggleFullScreen()
        {
            try
            {
                this.axWindowsMediaPlayer.stretchToFit = !this.axWindowsMediaPlayer.stretchToFit;
            }
            catch { }
        }

        private void SavePosition()
        {
            if (currentPlayingLink != null)
            {
                var pos = this.axWindowsMediaPlayer.Ctlcontrols.currentPosition - 5;
                currentPlayingLink.LastPosition = pos > 0 ? pos : 0;
            }

        }
        #endregion

        #region Events


        private void buttonSpecHeaderGroupFullscreen_Click(object sender, EventArgs e)
        {
            try
            {
                //if (this.axWindowsMediaPlayer.playState != WMPLib.WMPPlayState.wmppsUndefined &&
                //    this.axWindowsMediaPlayer.playState != WMPLib.WMPPlayState.wmppsStopped)
                    this.axWindowsMediaPlayer.fullScreen = true;
            }
            catch { }
        }

        private void buttonSpecHeaderFavourite_Click(object sender, EventArgs e)
        {
            UpdateFavouriteButton(ToggleFavourite());
        }

        private void buttonSpecHeaderGroupOriginal_Click(object sender, EventArgs e)
        {

            ToggleFullScreen();
        }

        private void axWindowsMediaPlayer_DoubleClickEvent(object sender, AxWMPLib._WMPOCXEvents_DoubleClickEvent e)
        {
            ToggleFullScreen();
        }

        private void axWindowsMediaPlayer_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
        {
            this.buttonSpecHeaderGroupOriginal.Enabled = this.buttonSpecHeaderGroupFullscreen.Enabled =  
                e.newState == (int) WMPLib.WMPPlayState.wmppsPlaying
                ? ButtonEnabled.True : ButtonEnabled.False;
            Debug.WriteLine(((WMPLib.WMPPlayState)e.newState).ToString());
        }

        private void axWindowsMediaPlayer_ErrorEvent(object sender, EventArgs e)
        {

        }


        private void axWindowsMediaPlayer_OpenStateChange(object sender, AxWMPLib._WMPOCXEvents_OpenStateChangeEvent e)
        {
            if (e.newState == (int)WMPLib.WMPOpenState.wmposMediaOpen)
                this.axWindowsMediaPlayer.Ctlcontrols.currentPosition = this.currentPlayingLink.LastPosition;
        }

        private void axWindowsMediaPlayer_PositionChange(object sender, AxWMPLib._WMPOCXEvents_PositionChangeEvent e)
        {
            SavePosition();
        }

        #endregion

        public PlayerType PlayerType
        {
            get { return Viewer.PlayerType.WMP; }
        }

      
        

       

    }
}