PageRenderTime 45ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/IPlayer/App.xaml.cs

https://gitlab.com/prabaprakash/Real_Metro_Player
C# | 319 lines | 131 code | 56 blank | 132 comment | 16 complexity | 3aea5204913959bb50b75b1c1f7438fb MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using IPlayer.Views;
  5. using Windows.ApplicationModel;
  6. using Windows.ApplicationModel.Activation;
  7. using Windows.Storage;
  8. using Windows.Storage.Search;
  9. using Windows.UI.Popups;
  10. using Windows.UI.Xaml;
  11. using Windows.UI.Xaml.Controls;
  12. // The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234227
  13. namespace IPlayer
  14. {
  15. /// <summary>
  16. /// Provides application-specific behavior to supplement the default Application class.
  17. /// </summary>
  18. sealed partial class App : Application
  19. {
  20. /// <summary>
  21. /// Initializes the singleton application object. This is the first line of authored code
  22. /// executed, and as such is the logical equivalent of main() or WinMain().
  23. /// </summary>
  24. public App()
  25. {
  26. this.InitializeComponent();
  27. this.Suspending += OnSuspending;
  28. }
  29. /// <summary>
  30. /// Invoked when the application is launched normally by the end user. Other entry points
  31. /// will be used when the application is launched to open a specific file, to display
  32. /// search results, and so forth.
  33. /// </summary>
  34. /// <param name="args">Details about the launch request and process.</param>
  35. protected override void OnLaunched(LaunchActivatedEventArgs args)
  36. {
  37. Frame rootFrame = Window.Current.Content as Frame;
  38. // Do not repeat app initialization when the Window already has content,
  39. // just ensure that the window is active
  40. if (rootFrame == null)
  41. {
  42. // Create a Frame to act as the navigation context and navigate to the first page
  43. rootFrame = new Frame();
  44. if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
  45. {
  46. // await SuspensionManager.RestoreAsync();
  47. //var dispRequest = new DisplayRequest();
  48. //dispRequest.RequestActive();
  49. }
  50. // Place the frame in the current Window
  51. Window.Current.Content = rootFrame;
  52. }
  53. if (rootFrame.Content == null)
  54. {
  55. // When the navigation stack isn't restored navigate to the first page,
  56. // configuring the new page by passing required information as a navigation
  57. // parameter
  58. if (!rootFrame.Navigate(typeof(Views.MainPage), args.Arguments))
  59. {
  60. throw new Exception("Failed to create initial page");
  61. }
  62. }
  63. // Ensure the current window is active
  64. Window.Current.Activate();
  65. }
  66. /// <summary>
  67. /// Invoked when application execution is being suspended. Application state is saved
  68. /// without knowing whether the application will be terminated or resumed with the contents
  69. /// of memory still intact.
  70. /// </summary>
  71. /// <param name="sender">The source of the suspend request.</param>
  72. /// <param name="e">Details about the suspend request.</param>
  73. private void OnSuspending(object sender, SuspendingEventArgs e)
  74. {
  75. var deferral = e.SuspendingOperation.GetDeferral();
  76. //TODO: Save application state and stop any background activity
  77. // await SuspensionManager.SaveAsync();
  78. deferral.Complete();
  79. }
  80. protected override void OnSearchActivated(Windows.ApplicationModel.Activation.SearchActivatedEventArgs args)
  81. {
  82. //// TODO: Register the Windows.ApplicationModel.Search.SearchPane.GetForCurrentView().QuerySubmitted
  83. //// event in OnWindowCreated to speed up searches once the application is already running
  84. //// If the Window isn't already using Frame navigation, insert our own Frame
  85. //var previousContent = Window.Current.Content;
  86. //var frame = previousContent as Frame;
  87. //// If the app does not contain a top-level frame, it is possible that this
  88. //// is the initial launch of the app. Typically this method and OnLaunched
  89. //// in App.xaml.cs can call a common method.
  90. //if (frame == null)
  91. //{
  92. // // Create a Frame to act as the navigation context and associate it with
  93. // // a SuspensionManager key
  94. // frame = new Frame();
  95. // IPlayer.Common.SuspensionManager.RegisterFrame(frame, "AppFrame");
  96. // if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
  97. // {
  98. // // Restore the saved session state only when appropriate
  99. // try
  100. // {
  101. // await IPlayer.Common.SuspensionManager.RestoreAsync();
  102. // }
  103. // catch (IPlayer.Common.SuspensionManagerException)
  104. // {
  105. // //Something went wrong restoring state.
  106. // //Assume there is no state and continue
  107. // }
  108. // }
  109. //}
  110. //frame.Navigate(typeof(MainPage), args);
  111. //Window.Current.Content = frame;
  112. //// Ensure the current window is active
  113. //Window.Current.Activate();
  114. Frame f = (Frame) Window.Current.Content;
  115. if (f == null)
  116. {
  117. Frame frame = new Frame();
  118. frame.Navigate(typeof (Views.MainPage), args);
  119. Window.Current.Content = frame;
  120. // Ensure the current window is active
  121. Window.Current.Activate();
  122. }
  123. }
  124. public int count = 0;
  125. protected override async void OnFileActivated(FileActivatedEventArgs args)
  126. {
  127. //if (count == 0)
  128. //{
  129. // var rootFrame = new Frame();
  130. // rootFrame.Navigate(typeof (MainPage));
  131. // Window.Current.Content = rootFrame;
  132. // MainPage p = rootFrame.Content as MainPage;
  133. // Window.Current.Activate();
  134. // StorageFile file = args.Files[0] as StorageFile;
  135. // p.fileactivatedfile = file;
  136. // count = count + 1;
  137. //}
  138. //else
  139. //{
  140. // //MainPage a=new MainPage();
  141. // //StorageFile file = args.Files[0] as StorageFile;
  142. // //a.SetSource(file);
  143. // //Window.Current.Content = a;
  144. // // await new MessageDialog("Open Media via App").ShowAsync();
  145. //}
  146. //Method 2
  147. //////var rootFrame = new Frame();
  148. //////rootFrame.Navigate(typeof(MainPage));
  149. //////Window.Current.Content = rootFrame;
  150. //////MainPage p = rootFrame.Content as MainPage;
  151. //////Window.Current.Activate();
  152. //////await Windows.UI.Xaml.Window.Current.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High, new DispatchedHandler(() =>
  153. //////{
  154. ////// StorageFile file = args.Files[0] as StorageFile;
  155. ////// p.SetSource(file);
  156. //////}));
  157. //method 3
  158. var previousContent = Window.Current.Content;
  159. var frame = previousContent as Frame;
  160. // If the app does not contain a top-level frame, it is possible that this
  161. // is the initial launch of the app. Typically this method and OnLaunched
  162. // in App.xaml.cs can call a common method.
  163. if (frame == null)
  164. {
  165. // Create a Frame to act as the navigation context and associate it with
  166. // a SuspensionManager key
  167. frame = new Frame();
  168. IPlayer.Common.SuspensionManager.RegisterFrame(frame, "AppFrame");
  169. if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
  170. {
  171. // Restore the saved session state only when appropriate
  172. try
  173. {
  174. await IPlayer.Common.SuspensionManager.RestoreAsync();
  175. }
  176. catch (IPlayer.Common.SuspensionManagerException)
  177. {
  178. //Something went wrong restoring state.
  179. //Assume there is no state and continue
  180. }
  181. }
  182. }
  183. frame.Navigate(typeof(Views.MainPage), args);
  184. Views.MainPage p = frame.Content as Views.MainPage;
  185. //var QueryOptions = new QueryOptions
  186. // (
  187. // CommonFileQuery.OrderByName, new List<string> { ".3g2", ".3gp2", ".3gp", ".3gpp", ".m4a", ".m4v", ".mp4v", ".mp4", ".mov", ".m2ts", ".asf", ".wm", ".vob", ".wmv", ".wma", ".aac", ".adt", ".mp3", ".wav", ".avi", ".ac3", ".ec3" }
  188. // );
  189. //var FileQuery = folder.CreateFileQueryWithOptions(QueryOptions);
  190. //var ass = await FileQuery.GetFilesAsync();
  191. var list = new List<string>
  192. {
  193. ".3g2",
  194. ".3gp2",
  195. ".3gp",
  196. ".3gpp",
  197. ".m4a",
  198. ".m4v",
  199. ".mp4v",
  200. ".mp4",
  201. ".mov",
  202. ".m2ts",
  203. ".asf",
  204. ".wm",
  205. ".vob",
  206. ".wmv",
  207. ".wma",
  208. ".aac",
  209. ".adt",
  210. ".mp3",
  211. ".wav",
  212. ".avi",
  213. ".ac3",
  214. ".ec3"
  215. };
  216. List<StorageFile> strlis=new List<StorageFile>();
  217. //foreach (StorageFile fi in args.Files)
  218. //{
  219. // if (list.Any(x=>x.Contains(fi.FileType.ToLower()))==true)
  220. // {
  221. // strlis.Add(fi);
  222. // }
  223. //}
  224. // StorageFile file = args.Files[0] as StorageFile;
  225. if (args.Verb.Equals("play"))
  226. {
  227. ////var QueryOptions = new QueryOptions
  228. //// (
  229. //// CommonFileQuery.OrderByName, new List<string> { ".3g2", ".3gp2", ".3gp", ".3gpp", ".m4a", ".m4v", ".mp4v", ".mp4", ".mov", ".m2ts", ".asf", ".wm", ".vob", ".wmv", ".wma", ".aac", ".adt", ".mp3", ".wav", ".avi", ".ac3", ".ec3" }
  230. //// );
  231. ////var FileQuery = ((StorageFolder)args.Files[0]).CreateFileQueryWithOptions(QueryOptions);
  232. ////var ass = await FileQuery.GetFilesAsync();
  233. ////foreach (var storage in ass)
  234. ////{
  235. //// strlis.Add(storage);
  236. ////}
  237. // await new MessageDialog("hi").ShowAsync();
  238. IReadOnlyList<IStorageItem> files = args.Files as IReadOnlyList<IStorageItem>;
  239. foreach (var storageItem in files)
  240. {
  241. strlis.Add(storageItem as StorageFile);
  242. }
  243. }
  244. else
  245. {
  246. foreach (var fi in args.Files)
  247. {
  248. if (fi is StorageFile)
  249. {
  250. if (list.Any(x => x.Contains((fi as StorageFile).FileType.ToLower())))
  251. {
  252. strlis.Add(fi as StorageFile);
  253. }
  254. }
  255. }
  256. p.file1 = strlis;
  257. }
  258. Window.Current.Content = frame;
  259. // Ensure the current window is active
  260. Window.Current.Activate();
  261. }
  262. }
  263. }