file360

Log | Files | Refs

VideoPage.xaml.cs (5839B)


      1 using System;
      2 using System.Collections.Generic;
      3 using System.IO;
      4 using System.Linq;
      5 using System.Runtime.InteropServices.WindowsRuntime;
      6 using Windows.Foundation;
      7 using Windows.Foundation.Collections;
      8 using Windows.Storage;
      9 using Windows.UI.Xaml;
     10 using Windows.UI.Xaml.Controls;
     11 using Windows.UI.Xaml.Controls.Primitives;
     12 using Windows.UI.Xaml.Data;
     13 using Windows.UI.Xaml.Input;
     14 using Windows.UI.Xaml.Media;
     15 using Windows.UI.Xaml.Navigation;
     16 
     17 // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkID=390556
     18 
     19 namespace File360
     20 {
     21     /// <summary>
     22     /// An empty page that can be used on its own or navigated to within a Frame.
     23     /// </summary>
     24     public sealed partial class VideoPage : Page
     25     {
     26 
     27         private bool MENU_HIDDEN = true;
     28         private DispatcherTimer musicDispatcher;
     29         public VideoPage()
     30         {
     31             this.InitializeComponent();
     32             Loaded += VideoPage_Loaded;
     33             Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
     34             SizeChanged += VideoPage_SizeChanged;
     35         }
     36 
     37         private void VideoPage_SizeChanged(object sender, SizeChangedEventArgs e)
     38         {
     39             VisualStateManager.GoToState(this, "Landscape", false);
     40         }
     41 
     42         private void VideoPage_Loaded(object sender, RoutedEventArgs e)
     43         {
     44             MenuHide.Begin();
     45         }
     46 
     47         private void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
     48         {
     49             if (this.Frame.CanGoBack)
     50                 this.Frame.GoBack();
     51             else Application.Current.Exit();
     52         }
     53 
     54         /// <summary>
     55         /// Invoked when this page is about to be displayed in a Frame.
     56         /// </summary>
     57         /// <param name="e">Event data that describes how this page was reached.
     58         /// This parameter is typically used to configure the page.</param>
     59         protected override void OnNavigatedTo(NavigationEventArgs e)
     60         {
     61             IStorageFile isf = (IStorageFile)e.Parameter;
     62             mediaPlayer.Source = new Uri(isf.Path);
     63             mediaPlayer.MediaOpened += (es,st) =>
     64             {
     65                 UpdateVideoInfo(isf.Name, mediaPlayer.NaturalDuration.TimeSpan.Minutes + ":" + mediaPlayer.NaturalDuration.TimeSpan.Seconds.ToString(),"8");
     66                 musicSlider.Maximum = mediaPlayer.NaturalDuration.TimeSpan.TotalSeconds;
     67                 musicDispatcher.Start();
     68             };
     69 
     70             musicDispatcher = new DispatcherTimer();
     71             musicDispatcher.Interval = TimeSpan.FromMilliseconds(1000);
     72 
     73 
     74             mediaPlayer.MediaEnded += async (es,st) =>
     75             {
     76                 await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, delegate
     77                 {
     78                     //UpdateVideoInfo("no media", "--:--", "5");
     79                     //musicDispatcher.Stop();
     80                     ExitOrGoBack();
     81                 });
     82             };
     83 
     84             mediaPlayer.MediaFailed += async (s, t) =>
     85             {
     86                 await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, delegate
     87                 {
     88                     //UpdateVideoInfo("no media", "--:--", "5");
     89                     if (musicDispatcher.IsEnabled)
     90                         musicDispatcher.Stop();
     91                     MessageBox mb = new MessageBox();
     92                     mb.HeadingText = "Cannot Play Media";
     93                     mb.ContentText = "Cannot play this file, do you want to open with other video player?";
     94                     mb.LeftButtonHandler += (es, st) => 
     95                     {
     96                         ExitOrGoBack();
     97                     };
     98                     mb.RightButtonHandler += async (es, st) =>
     99                     {
    100                         await Windows.System.Launcher.LaunchFileAsync(isf);
    101                     };
    102                     MediaFragment.Children.Add(mb);
    103                 });
    104             };
    105 
    106 
    107             musicDispatcher.Tick += (s, t) =>
    108             {
    109                 musicSlider.Value = mediaPlayer.Position.TotalSeconds;
    110                 currentDuration.Text = mediaPlayer.Position.Minutes + ":" + mediaPlayer.Position.Seconds;
    111 
    112             };
    113             videoName.Text = isf.Name;
    114 
    115         }
    116 
    117         private void ExitOrGoBack()
    118         {
    119             if (this.Frame.CanGoBack)
    120                 this.Frame.GoBack();
    121             else Application.Current.Exit();
    122         }
    123 
    124         private void UpdateVideoInfo(string name, string dur, string playMode)
    125         {
    126             videoName.Text = name;
    127             mediaDuration.Text = dur;
    128             musicSlider.Value = 0;
    129             playPause.Content = playMode;
    130         }
    131 
    132         private void mediaPlayer_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
    133         {
    134 
    135         }
    136 
    137         private void mediaPlayer_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
    138         {
    139 
    140         }
    141 
    142         private void mediaPlayer_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
    143         {
    144 
    145         }
    146 
    147         private void PlayCurrent(object sender, RoutedEventArgs e)
    148         {
    149             if (mediaPlayer.CurrentState == MediaElementState.Playing)
    150             {
    151                 mediaPlayer.Pause();
    152                 playPause.Content = "5";
    153                 //DurationBlink.Begin();
    154             }
    155             else if (mediaPlayer.CurrentState == MediaElementState.Paused)
    156             {
    157                 mediaPlayer.Play();
    158                 playPause.Content = "8";
    159                 //DurationBlink.Stop();
    160             }
    161 
    162         }
    163 
    164         private void Grid_Tapped(object sender, TappedRoutedEventArgs e)
    165         {
    166             if (MENU_HIDDEN)
    167                 MenuHideRev.Begin();
    168             else MenuHide.Begin();
    169             MENU_HIDDEN = !MENU_HIDDEN;
    170         }
    171     }
    172 }