Subversion Repository Public Repository

Nextrek

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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
/* 
    Copyright (c) 2011 Microsoft Corporation.  All rights reserved.
    Use of this sample source code is subject to the terms of the Microsoft license 
    agreement under which you licensed this sample source code and is provided AS-IS.
    If you did not accept the terms of the license agreement, you are not authorized 
    to use this sample source code.  For the terms of the license, please see the 
    license agreement between you and Microsoft.
  
    To see all Code Samples for Windows Phone, visit http://go.microsoft.com/fwlink/?LinkID=219604 
  
*/
using System;
using System.Windows;
using System.Windows.Media;
using Microsoft.Phone.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.BackgroundAudio;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using System.Collections.Generic;

namespace sdkBackgroundAudioPlayerCS
{
    

    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(MainPage_Loaded);
        }

        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            BackgroundAudioPlayer.Instance.PlayStateChanged += new EventHandler(Instance_PlayStateChanged);
            webBrowserTesto.Navigate(new Uri("Pirandello.htm", UriKind.Relative));
           
        }

        private DispatcherTimer timer = new DispatcherTimer();

        /// <summary>
        /// Checks to see if the BackgroundAudioPlayer is already playing.
        /// Initializes the UI controls accordingly.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (PlayState.Playing == BackgroundAudioPlayer.Instance.PlayerState)
            {
                //playButton.Content = "| |";     // Change to pause button
                txtCurrentTrack.Text = BackgroundAudioPlayer.Instance.Track.Title +
                                       " di " +
                                       BackgroundAudioPlayer.Instance.Track.Artist;
                     webBrowserTesto.Navigate(new Uri(BackgroundAudioPlayer.Instance.Track.Title + ".htm", UriKind.Relative));

                
                
            }

            else
            {
                //playButton.Content = ">";     // Change to play button
                txtCurrentTrack.Text = "";
            }

            StartTimer();
            
        }

        protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
        {
            timer.Stop();
            timer.Tick -= new EventHandler(timer_tick);
            BackgroundAudioPlayer.Instance.PlayStateChanged -= new EventHandler(Instance_PlayStateChanged);
        }


        /// <summary>
        /// Updates the UI with the current song data.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Instance_PlayStateChanged(object sender, EventArgs e)
        {
            switch (BackgroundAudioPlayer.Instance.PlayerState)
            {
                case PlayState.Playing:
                    PlayBtn.Source = new BitmapImage(new Uri("/AudioBookCandeloraCS;component/Images/pause.png", UriKind.Relative));
                    PrevBtn.Source = new BitmapImage(new Uri("/AudioBookCandeloraCS;component/Images/dietro.png", UriKind.Relative));
                    NextBtn.Source = new BitmapImage(new Uri("/AudioBookCandeloraCS;component/Images/avanti.png", UriKind.Relative));
                    break;

                case PlayState.Paused:
             
                case PlayState.Stopped:
                    PlayBtn.Source = new BitmapImage(new Uri("/AudioBookCandeloraCS;component/Images/PalyerBtn.png", UriKind.Relative));
                    break;
            }

            if (null != BackgroundAudioPlayer.Instance.Track)
            {
                txtCurrentTrack.Text = BackgroundAudioPlayer.Instance.Track.Title +
                                       " di " +
                                       BackgroundAudioPlayer.Instance.Track.Artist;

                webBrowserTesto.Navigate(new Uri(BackgroundAudioPlayer.Instance.Track.Title + ".htm", UriKind.Relative));

                slider1.Minimum = 0;
                slider1.Maximum = BackgroundAudioPlayer.Instance.Track.Duration.TotalMilliseconds;
                string text = BackgroundAudioPlayer.Instance.Track.Duration.ToString();
                EndTextBlock.Text = text.Substring(0, 8);
            }

      


        }


        #region Button Click Event Handlers

        /// <summary>
        /// Tells the background audio agent to skip to the previous track.
        /// </summary>
        /// <param name="sender">The button</param>
        /// <param name="e">Click event args</param>
        private void prevButton_Click(object sender, RoutedEventArgs e)
        {
            BackgroundAudioPlayer.Instance.SkipPrevious();
            slider1.Value = 0;

            // Prevent the user from repeatedly pressing the button and causing 
            // a backlong of button presses to be handled. This button is re-eneabled 
            // in the TrackReady Playstate handler.
            // prevButton.IsEnabled = false;
        }


        /// <summary>
        /// Tells the background audio agent to play the current 
        /// track or to pause if we're already playing.
        /// </summary>
        /// <param name="sender">The button</param>
        /// <param name="e">Click event args</param>
        private void playButton_Click(object sender, RoutedEventArgs e)
        {
            if (PlayState.Playing == BackgroundAudioPlayer.Instance.PlayerState)
            {
                BackgroundAudioPlayer.Instance.Pause();
                
            }
            else
            {
                BackgroundAudioPlayer.Instance.Play();
            }

        }

        /// <summary>
        /// Tells the background audio agent to skip to the next track.
        /// </summary>
        /// <param name="sender">The button</param>
        /// <param name="e">Click event args</param>
        private void nextButton_Click(object sender, RoutedEventArgs e)
        {
            
            BackgroundAudioPlayer.Instance.SkipNext();
            slider1.Value = 0;

            // Prevent the user from repeatedly pressing the button and causing 
            // a backlong of button presses to be handled. This button is re-eneabled 
            // in the TrackReady Playstate handler.
           // nextButton.IsEnabled = false;
        }

        #endregion Button Click Event Handlers

        private void PlayBtn_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (PlayState.Playing == BackgroundAudioPlayer.Instance.PlayerState)
            {
                BackgroundAudioPlayer.Instance.Pause();
                PlayBtn.Source = new BitmapImage(new Uri("/AudioBookCandeloraCS;component/Images/PalyerBtn.png", UriKind.Relative));
            }
            else
            {
                BackgroundAudioPlayer.Instance.Play();
                PlayBtn.Source =new BitmapImage(new Uri("/AudioBookCandeloraCS;component/Images/Pause.png", UriKind.Relative));
            }

        }

        private void image1_ImageFailed(object sender, ExceptionRoutedEventArgs e)
        {

        }

        private void NextBtn_ImageFailed(object sender, ExceptionRoutedEventArgs e)
        {

        }
 

        private void NextBtn_ImageFailed_1(object sender, ExceptionRoutedEventArgs e)
        {
           
        }

        private void PrevBtn_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
                BackgroundAudioPlayer.Instance.SkipPrevious();

                // Prevent the user from repeatedly pressing the button and causing 
                // a backlong of button presses to be handled. This button is re-eneabled 
                // in the TrackReady Playstate handler.

            
                
                /*
                if (this.webBrowserTesto.Source.Equals("Candelora Capitolo 1.htm"))
                {
                    webBrowserTesto.Navigate(new Uri("Pirandello.htm", UriKind.Relative));
                    
                    
                }
                else if (this.webBrowserTesto.Source.Equals("Candelora Capitolo 2.htm"))
                {
                    webBrowserTesto.Navigate(new Uri("Candelora Capitolo 1.htm", UriKind.Relative));
                    
                }
                else if (this.webBrowserTesto.Source.Equals("Candelora Capitolo 3.htm"))
                {
                    webBrowserTesto.Navigate(new Uri("Candelora Capitolo 2.htm", UriKind.Relative));
                    
                }*/
        }

        private void PrevBtn_ImageFailed(object sender, ExceptionRoutedEventArgs e)
        {

        }

        private void NextBtn_MouseLeftButtonUp_1(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
             BackgroundAudioPlayer.Instance.SkipNext();

                // Prevent the user from repeatedly pressing the button and causing 
                // a backlong of button presses to be handled. This button is re-eneabled 
                // in the TrackReady Playstate handler.
            

                
            /*if(this.webBrowserTesto.Source.Equals("Pirandello.htm")){
                 webBrowserTesto.Navigate(new Uri("Candelora Capitolo 1.htm",UriKind.Relative));
                }
            else if (this.webBrowserTesto.Source.Equals("Candelora Capitolo 1.htm")) {
                webBrowserTesto.Navigate(new Uri("Candelora Capitolo 2.htm", UriKind.Relative));
            }
            else if (this.webBrowserTesto.Source.Equals("Candelora Capitolo 2.htm"))
            {
                webBrowserTesto.Navigate(new Uri("Candelora Capitolo 3.htm", UriKind.Relative));
            }*/
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (indexCanvas.Visibility == System.Windows.Visibility.Collapsed)
            {
                indexCanvas.Visibility = System.Windows.Visibility.Visible;
            }
            else indexCanvas.Visibility = System.Windows.Visibility.Collapsed;
         
        }

        private void linkPag0_Click(object sender, RoutedEventArgs e)
        {
            
            webBrowserTesto.Navigate(new Uri("Pirandello.htm", UriKind.Relative));
            indexCanvas.Visibility = System.Windows.Visibility.Collapsed;
            BackgroundAudioPlayer.Instance.Stop();
            slider1.Value = 0;
            BackgroundAudioPlayer.Instance.Track = MyAudioPlaybackAgent.AudioPlayer._playList[0];
            
        }

        private void linkPag1_Click(object sender, RoutedEventArgs e)
        {
            
            webBrowserTesto.Navigate(new Uri("Candelora Capitolo 1.htm", UriKind.Relative));
            indexCanvas.Visibility = System.Windows.Visibility.Collapsed;
            BackgroundAudioPlayer.Instance.Stop();
            slider1.Value = 0;
            BackgroundAudioPlayer.Instance.Track = MyAudioPlaybackAgent.AudioPlayer._playList[0];
            
        }

        private void linkPag2_Click(object sender, RoutedEventArgs e)
        {
           
            webBrowserTesto.Navigate(new Uri("Candelora Capitolo 2.htm", UriKind.Relative));
            indexCanvas.Visibility = System.Windows.Visibility.Collapsed;
            BackgroundAudioPlayer.Instance.Stop();
            slider1.Value = 0;
            BackgroundAudioPlayer.Instance.Track = MyAudioPlaybackAgent.AudioPlayer._playList[1];
            
        }

        private void linkPag3_Click(object sender, RoutedEventArgs e)
        {
            webBrowserTesto.Navigate(new Uri("Candelora Capitolo 3.htm", UriKind.Relative));
            indexCanvas.Visibility = System.Windows.Visibility.Collapsed;
            BackgroundAudioPlayer.Instance.Stop();
            slider1.Value = 0;
            BackgroundAudioPlayer.Instance.Track = MyAudioPlaybackAgent.AudioPlayer._playList[2];
            
        }

       
        private void enter_click_prevMouse(object sender, System.Windows.Input.MouseEventArgs e)
        {
            PrevBtn.Source = new BitmapImage(new Uri("/AudioBookCandeloraCS;component/Images/indietrodisable.png", UriKind.Relative));
        
        }

        private void leave_click_prevMouse(object sender, System.Windows.Input.MouseEventArgs e)
        {
            PrevBtn.Source = new BitmapImage(new Uri("/AudioBookCandeloraCS;component/Images/dietro.png", UriKind.Relative));
        
        }

        private void enter_click_nextMouse(object sender, System.Windows.Input.MouseEventArgs e)
        {
            NextBtn.Source = new BitmapImage(new Uri("/AudioBookCandeloraCS;component/Images/avantidisable.png", UriKind.Relative));
                
        }

        private void leave_click_nextMouse(object sender, System.Windows.Input.MouseEventArgs e)
        {
            NextBtn.Source = new BitmapImage(new Uri("/AudioBookCandeloraCS;component/Images/avanti.png", UriKind.Relative));
             
        }

        private void slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
           
            
        }

        public void StartTimer() {
            
            timer.Interval = new TimeSpan(0, 0, 0, 0, 500);
            timer.Tick += new EventHandler(timer_tick);
            timer.Start();
        }
        
        
        private void timer_tick(object sender, EventArgs e) {
            if (PlayState.Playing == BackgroundAudioPlayer.Instance.PlayerState) {
                slider1.Minimum = 0;
                slider1.Value = BackgroundAudioPlayer.Instance.Position.TotalMilliseconds;
                slider1.Maximum = BackgroundAudioPlayer.Instance.Track.Duration.TotalMilliseconds;

                string text = BackgroundAudioPlayer.Instance.Position.ToString();
                StartTextBlock.Text = text.Substring(0, 8);
                text = BackgroundAudioPlayer.Instance.Track.Duration.ToString();
                EndTextBlock.Text = text.Substring(0, 8);
            }
        }

        private void soundSlider_manipulationCompleted(object sender, System.Windows.Input.ManipulationCompletedEventArgs e)
        {
            // get slider value
            int sliderValue = (int)slider1.Value;
            // create timespan object with milliseconds (from slider value)
            TimeSpan timeSpan = new TimeSpan(0, 0, 0, 0, sliderValue);
            // set a new position of the song
            BackgroundAudioPlayer.Instance.Position = timeSpan;

        }

        private void hyperlinkButton1_Click(object sender, RoutedEventArgs e)
        {
            webBrowserTesto.Navigate(new Uri("http://it.wikipedia.org/wiki/Luigi_Pirandello",UriKind.RelativeOrAbsolute));
        }

       


        

 
    }
}

Commits for Nextrek/WindowsPhone/AudioStory/Candelora/sdkBackgroundAudioPlayerCS/MainPage.xaml.cs

Diff revisions: vs.
Revision Author Commited Message
6 FMMortaroli picture FMMortaroli Sat 20 Apr, 2013 15:30:47 +0000