~ubuntu-branches/ubuntu/lucid/gnome-subtitles/lucid

« back to all changes in this revision

Viewing changes to src/GnomeSubtitles/Video/Video.cs

  • Committer: Bazaar Package Importer
  • Author(s): Tiago Bortoletto Vaz
  • Date: 2007-12-03 20:52:52 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071203205252-2y6uuv4gcw9mi9n5
Tags: 0.7-1
* New upstream release;
* Add libxml-parser-perl to Build-Depends-Indep. Thanks to Lucas Nussbaum.
  (Closes: #445799);
* Fixes manpage issue with dpatch

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
        private VideoSubtitle subtitle = null;
34
34
        
35
35
        private bool isLoaded = false;
 
36
        private bool playPauseToggleIsSilent = false; //Used to indicate whether toggling the button should not issue the toggled signal
36
37
 
37
38
        /* Constant strings */
38
39
        private const string videoSetSubtitleStartIconFilename = "video-set-subtitle-start-16x.png";
53
54
                videoImageTable.Attach(videoFrameEventBox, 0, 1, 0, 1);
54
55
                videoImageTable.ShowAll();
55
56
                
 
57
                /* Set player */
56
58
                player = new Player();
57
 
                player.EndReached += OnPlayerEndReached;
 
59
                player.OnEndReached = OnPlayerEndReached;
 
60
                player.OnErrorCaught = OnPlayerErrorCaught;
58
61
                
59
62
                position = new VideoPosition(player);
60
63
                subtitle = new VideoSubtitle(position);
63
66
                
64
67
                /* Set the custom icons */
65
68
                SetCustomIcons();
 
69
                
 
70
                /* Connect signals */
 
71
                ConnectPlayPauseButtonSignals();
66
72
        }
67
73
        
68
74
        /* Public properties */
81
87
                videoArea.Show();
82
88
                
83
89
                /* Required for the vBox and children to be redrawn before launching the video player */
84
 
                Paned paned = Global.GetWidget(WidgetNames.MainPaned) as Paned;
85
 
                paned.ResizeChildren();
86
 
                Gdk.Window.ProcessAllUpdates();
 
90
                /*Paned paned = Global.GetWidget(WidgetNames.MainPaned) as Paned;
 
91
                paned.ResizeChildren(); TODO is this needed?
 
92
                Gdk.Window.ProcessAllUpdates();*/ 
87
93
        }
88
94
 
89
95
        public void Hide () {
91
97
        }
92
98
        
93
99
        /// <summary>Opens a video file.</summary>
94
 
        /// <exception cref="PlayerNotFoundException">Thrown if the player executable was not found.</exception>
95
100
        /// <exception cref="PlayerCouldNotOpenVideoException">Thrown if the player could not open the video.</exception>
96
 
        public void Open (string filename) {
 
101
        public void Open (Uri videoUri) {
97
102
                Close();
98
103
 
99
 
                filename = Util.QuoteFilename(filename);
100
 
                
101
 
                player.Open(filename);
102
 
                player.SeekStart();
 
104
                player.Open(videoUri);
103
105
 
104
106
                SetControlsSensitivity(true);
105
107
                position.Enable();
111
113
        }
112
114
        
113
115
        public void Close () {
 
116
                if (!isLoaded)
 
117
                        return;
 
118
        
114
119
                isLoaded = false;
115
120
 
116
121
                float oldFrameRate = player.FrameRate; //Need to store this before closing the player
124
129
                frame.Child.Show();
125
130
                frame.Ratio = 1.67f;
126
131
                
127
 
                /* Update the PlayPause button */
128
 
                ToggleButton button = Global.GetWidget(WidgetNames.VideoPlayPauseButton) as ToggleButton;
129
 
                button.Active = false;
130
 
                
 
132
                SilentDisablePlayPauseButton();         
131
133
                SetControlsSensitivity(false);
132
134
 
133
135
                Global.GUI.Menus.SetVideoSensitivity(false);
150
152
        public void Quit () {
151
153
                player.Close();
152
154
        }
153
 
 
154
 
        public void TogglePlayPause () {
155
 
                ToggleButton button = Global.GetWidget(WidgetNames.VideoPlayPauseButton) as ToggleButton;
156
 
                button.Active = !button.Active; //Toggle() only emits the Toggled event
157
 
        }
158
 
        
159
 
        public void Play () {
160
 
                if (player.Paused)
161
 
                        player.Play();
162
 
        }
163
 
        
164
 
        public void Pause () {
165
 
                if (!player.Paused)
166
 
                        player.Pause();
167
 
        }
168
155
        
169
156
        public void Rewind () {
170
 
                player.Rewind(position.StepIncrement);
 
157
                player.Rewind(position.SeekIncrement);
171
158
        }
172
159
        
173
160
        public void Forward () {
174
 
                player.Forward(position.StepIncrement);
 
161
                player.Forward(position.SeekIncrement);
175
162
        }
176
163
        
177
164
        /// <summary>Seeks to the specified time.</summary>
178
165
        /// <param name="time">The time position to seek to, in seconds.</param>
179
 
        public void Seek (float time) {
 
166
        public void Seek (TimeSpan time) {
180
167
                if (!isLoaded)
181
168
                        return;
182
169
 
183
170
                player.Seek(time);
184
171
        }
185
172
        
186
 
        public void SeekToSelection () {
 
173
        public void SeekToSelection () { //TODO check out
187
174
                Subtitle subtitle = Global.GUI.View.Selection.Subtitle;
188
 
        float time = (float)subtitle.Times.Start.TotalSeconds;
 
175
        TimeSpan time = subtitle.Times.Start;
189
176
        Seek(time);
190
177
        }
191
178
        
192
179
        /* Private methods */
193
180
 
 
181
        private void Play () {
 
182
                player.Play();
 
183
        }
 
184
        
 
185
        private void Pause () {
 
186
                player.Pause();
 
187
        }
 
188
 
194
189
        private void LoadVideoWidget (Widget widget) {
195
190
                frame.Child = widget;
196
191
                widget.Realize();
224
219
                Global.GetWidget(WidgetNames.VideoSetSubtitleEndButton).Sensitive = sensitivity;
225
220
        }
226
221
        
 
222
        private void SilentDisablePlayPauseButton () {
 
223
                ToggleButton button = Global.GetWidget(WidgetNames.VideoPlayPauseButton) as ToggleButton;
 
224
                if (button.Active) {
 
225
                        playPauseToggleIsSilent = true;
 
226
                        button.Active = false;
 
227
                }               
 
228
        }
 
229
        
227
230
        /* Event members */
228
231
        
 
232
        private void ConnectPlayPauseButtonSignals () {
 
233
                ToggleButton button = Global.GetWidget(WidgetNames.VideoPlayPauseButton) as ToggleButton;
 
234
                button.Toggled += OnPlayPauseButtonToggled;
 
235
        }
 
236
        
 
237
        private void OnPlayPauseButtonToggled (object o, EventArgs args) {
 
238
                if (playPauseToggleIsSilent) {
 
239
                        playPauseToggleIsSilent = false;
 
240
                        return;
 
241
                }
 
242
 
 
243
        if ((o as ToggleButton).Active)
 
244
                        Play();
 
245
                else
 
246
                        Pause();
 
247
        }
 
248
        
229
249
        private void OnPlayerEndReached (object o, EventArgs args) {
230
250
                ToggleButton playPauseButton = Global.GetWidget(WidgetNames.VideoPlayPauseButton) as ToggleButton;
231
251
                playPauseButton.Active = false;
232
252
        }
 
253
        
 
254
        private void OnPlayerErrorCaught (string message) {
 
255
                Console.Error.WriteLine("Caught player error: " + message);
 
256
                Close();
 
257
                VideoErrorDialog dialog = new VideoErrorDialog(message);
 
258
                dialog.WaitForResponse();
 
259
        }
233
260
 
234
261
}
235
262