src/FingersDance.Control.Player/UserControlPlayer.xaml.cs
changeset 34 9e222810f5b5
parent 10 e8bfe1102e03
child 41 ce8b404aaae4
equal deleted inserted replaced
33:644464191714 34:9e222810f5b5
    12 
    12 
    13 namespace FingersDance.Control.Player
    13 namespace FingersDance.Control.Player
    14 {
    14 {
    15 	public partial class UserControlPlayer
    15 	public partial class UserControlPlayer
    16 	{
    16 	{
       
    17         #region Variables
       
    18         private bool isPlaying = false;
       
    19         #endregion
    17 
    20 
    18         private bool play;
    21         public event EventHandler PlayerOpened;
    19 
    22 
    20 		public UserControlPlayer()
    23 		public UserControlPlayer()
    21 		{
    24 		{
    22 			this.InitializeComponent();
    25 			this.InitializeComponent();
    23              
       
    24             initPlayer();
    26             initPlayer();
    25 		}
    27         }
    26 
    28 
       
    29         #region Properties
       
    30         public double TotalMilliseconds
       
    31         {
       
    32             get
       
    33             {
       
    34                 return MediaElementVideo.NaturalDuration.TimeSpan.TotalMilliseconds;
       
    35             }
       
    36         }
       
    37         public MediaElement Player
       
    38         {
       
    39             get
       
    40             {
       
    41                 return MediaElementVideo;
       
    42             }
       
    43             set
       
    44             {
       
    45                 MediaElementVideo= value;
       
    46             }
       
    47         }
       
    48 
       
    49         #endregion
       
    50 
       
    51 
       
    52         #region Methodes
    27         void initPlayer()
    53         void initPlayer()
    28         { 
    54         {
    29             //init player
    55             //init player
    30             play = false;
    56             isPlaying = false;
    31             MediaElementVideo.Source = new Uri("Resources\\Lake.wmv", UriKind.Relative);
    57             MediaElementVideo.Source = new Uri("Resources\\Lake.wmv", UriKind.Relative);
    32             MediaElementVideo.LoadedBehavior = MediaState.Manual;
    58             MediaElementVideo.LoadedBehavior = MediaState.Manual;
       
    59             MediaElementVideo.UnloadedBehavior = MediaState.Manual;
       
    60             MediaElementVideo.ScrubbingEnabled= true;
    33         }
    61         }
       
    62 
       
    63         public void playerPause()
       
    64         {
       
    65             MediaElementVideo.Pause();
       
    66         }
       
    67         public void playerPlay()
       
    68         {
       
    69             MediaElementVideo.Play();
       
    70         }
       
    71         public void playerStop()
       
    72         {
       
    73             MediaElementVideo.Stop();
       
    74         }
       
    75         
       
    76         #endregion
    34 
    77 
    35         private void ButtonPlayPause_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
    78         private void ButtonPlayPause_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
    36         {
    79         {
    37             if (!play)//Play
    80             if (!isPlaying)//Play
    38             {
    81             {
    39                 play = true;
    82                 isPlaying = true;
    40                 try
    83                 try
    41                 {
    84                 {
    42                     MediaElementVideo.Play();
    85                     MediaElementVideo.Play();
    43                 }
    86                 }
    44                 catch (Exception ex) { }
    87                 catch (Exception ex) { }
    45             }
    88             }
    46             else//Pause
    89             else//Pause
    47             {
    90             {
    48                 play = false;
    91                 isPlaying = false;
    49                 try
    92                 try
    50                 {
    93                 {
    51                     MediaElementVideo.Pause();
    94                     MediaElementVideo.Pause();
    52                 }
    95                 }
    53                 catch (Exception exx ) { }
    96                 catch (Exception exx) { }
    54             }
    97             }
    55 
    98 
    56         }
    99         }
    57 
   100 
    58         private void ButtonPlayPause_Click(object sender, RoutedEventArgs e)
   101         private void ButtonPlayPause_Click(object sender, RoutedEventArgs e)
    59         {
   102         {
    60             if (!play)//Play
   103             if (!isPlaying)//Play
    61             {
   104             {
    62                 play = true;
   105                 isPlaying = true;
    63                 try
   106                 try
    64                 {
   107                 {
    65                     MediaElementVideo.Play();
   108                     MediaElementVideo.Play();
    66                 }
   109                 }
    67                 catch (Exception ex ) { }
   110                 catch (Exception ex) { }
    68                 ButtonPlayPause.Background = FindResource("[Skin_1]_Pause_button_xaml") as Brush;
   111 
    69             }
   112             }
    70             else//Pause
   113             else//Pause
    71             {
   114             {
    72                 play = false;
   115                 isPlaying = false;
    73                 try
   116                 try
    74                 {
   117                 {
    75                     MediaElementVideo.Pause();
   118                     MediaElementVideo.Pause();
    76                 }
   119                 }
    77                 catch (Exception exx ) { }
   120                 catch (Exception exx) { }
    78                 ButtonPlayPause.Background = FindResource("[Skin_1]_Play_button_xaml") as Brush;
   121                 //ButtonPlayPause.Background = FindResource("[Skin_1]_Play_button_xaml") as Brush;
    79             }
   122             }
       
   123         }
       
   124 
       
   125         private void ButtonFastForward_Click(object sender, RoutedEventArgs e)
       
   126         {
       
   127             if (MediaElementVideo.SpeedRatio <= 3)
       
   128                 MediaElementVideo.SpeedRatio += 1;
       
   129         }
       
   130 
       
   131         private void ButtonFastForward_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
       
   132         {
       
   133             if (MediaElementVideo.SpeedRatio <= 3)
       
   134                 MediaElementVideo.SpeedRatio += 1;
       
   135         }
       
   136 
       
   137         private void ButtonRewind_Click(object sender, RoutedEventArgs e)
       
   138         {
       
   139             //TimeSpan ts = new TimeSpan(0, 0, 0, 0);
       
   140             if (MediaElementVideo.SpeedRatio > 1)
       
   141             {
       
   142                 MediaElementVideo.SpeedRatio -= 1;
       
   143             }
       
   144             else
       
   145             {
       
   146                 MediaElementVideo.Position = MediaElementVideo.Position.Add(new TimeSpan(0, 0, 0, -5));
       
   147             }
       
   148         }
       
   149 
       
   150         private void ButtonRewind_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
       
   151         {
       
   152 
       
   153             //TimeSpan ts = new TimeSpan(0, 0, 0,0);
       
   154             if (MediaElementVideo.SpeedRatio > 1)
       
   155             {
       
   156                 MediaElementVideo.SpeedRatio -= 1;
       
   157             }
       
   158             else
       
   159             {
       
   160                 MediaElementVideo.Position = MediaElementVideo.Position.Add(new TimeSpan(0, 0, 0, -5));
       
   161             }
       
   162         }
       
   163 
       
   164         private void MediaElementVideo_MediaOpened(object sender, RoutedEventArgs e)
       
   165         {
       
   166             OnPlayerOpened();
       
   167         }
       
   168         protected virtual void OnPlayerOpened()
       
   169         {
       
   170             if(PlayerOpened!=null)
       
   171                 PlayerOpened(this, new EventArgs());
    80         }
   172         }
    81 	}
   173 	}
    82 }
   174 }