This repository has been archived by the owner on Oct 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBlankPage1-MainSup1.xaml.cs
232 lines (216 loc) · 8.69 KB
/
BlankPage1-MainSup1.xaml.cs
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
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using Windows.Storage;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.Storage.Streams;
using Windows.UI.Xaml.Controls;
using Windows.Storage.FileProperties;
using Windows.UI;
using Windows.Media.Playlists;
using Windows.Storage.Search;
using Windows.UI.Xaml.Media.Imaging;
using System.Threading.Tasks;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
namespace MediaCenter
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class BlankPage1_MainSup1 : Page
{
ObservableCollection<Music> o = new ObservableCollection<Music>();
List<String> fileTypeFilter = new List<String>();
QueryOptions query;
public BlankPage1_MainSup1()
{
this.InitializeComponent();
fileTypeFilter.Add("*");
query = new QueryOptions(CommonFileQuery.DefaultQuery, fileTypeFilter);
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
StorageFolder sfolder=null;
try
{
sfolder = await ApplicationData.Current.LocalFolder.GetFolderAsync("Settings-Music_Player");
}
catch (Exception)
{
}
if(sfolder==null)
sfolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Settings-Music_Player");
StorageFile settings=null;
try
{
settings = await sfolder.GetFileAsync("MusicPlayerSettings.usersettings");
}
catch (Exception)
{
}
IReadOnlyList<StorageFile> ir;
if (settings == null)
settings = await sfolder.CreateFileAsync("MusicPlayerSettings.usersettings");
string text=string.Empty;
try
{
text=await FileIO.ReadTextAsync(settings);
}
catch (Exception)
{
}
if (text == string.Empty)
{
await FileIO.WriteTextAsync(settings, @"E:\songs\Music\Hindi songs\Nf");
text = await FileIO.ReadTextAsync(settings);
}
else
{
ir = await ((await StorageFolder.GetFolderFromPathAsync(text)).CreateFileQueryWithOptions(query).GetFilesAsync());
AddToMasterPlaylist(sfolder, ir);
int i = 0;
StorageItemThumbnail[] st = new StorageItemThumbnail[ir.Count];
st = await getThumbnails(ir);
MusicProperties mp = null;
foreach (StorageFile sf in ir)
{
bi = new BitmapImage();
bi.SetSource(st[i]);
mp = await sf.Properties.GetMusicPropertiesAsync();
o.Add(new Music{Thumbnail=bi,Duration=((mp.Duration.Hours < 10) ? ("0" + mp.Duration.Hours.ToString()) : mp.Duration.Hours.ToString()) + ":" + ((mp.Duration.Minutes < 10) ? ("0" + mp.Duration.Minutes.ToString()) : (mp.Duration.Minutes.ToString())) + ":" + ((mp.Duration.Seconds < 10) ? ("0" + mp.Duration.Seconds.ToString()) : (mp.Duration.Seconds.ToString())),Title=mp.Title,Album=mp.Album,CurrentFile=sf});
i++;
}
ObservableCollection<Music> og = new ObservableCollection<Music>();
Music[] mus = await getByAlbum(ir.ToArray());
foreach (Music m in mus)
{
og.Add(m);
}
MainGrid.ItemsSource = og;
MainGrid.UpdateLayout();
p_ring.Visibility = Visibility.Collapsed;
}
}
private async Task<Music[]> getByAlbum(StorageFile[] ir)
{
List <Music> list = new List<Music>();
List<StorageFile>[] l=await Sort(ir);
MusicProperties mp = null;
StorageItemThumbnail st=null;
for (int i = 0; i < ir.Length; i++)
{
st =await (l[i])[0].GetThumbnailAsync(ThumbnailMode.MusicView, 200, ThumbnailOptions.UseCurrentScale);
mp =await (l[i])[0].Properties.GetMusicPropertiesAsync();
bi = new BitmapImage();
bi.SetSource(st);
list.Add(new Music { Thumbnail = bi, Album = mp.Album });
}
return list.ToArray<Music>();
}
private async Task<List<StorageFile>[]> Sort(StorageFile[] ir)
{
bool val = false;
MusicProperties mp1 = null, mp2 = null;
List<StorageFile>[] sf=new List<StorageFile>[ir.Length];
for (int i = 0; i < sf.Length; i++)
{
sf[i] = new List<StorageFile>();
sf[i].Add(null);
}
for (int i = 0; i < ir.Length; i++)
{
mp1 = await ir[i].Properties.GetMusicPropertiesAsync();
for (int j = 0; j < ir.Length; j++)
{
mp2 = await ir[j].Properties.GetMusicPropertiesAsync();
if (mp1.Album==mp2.Album)
{
val = false;
for (int k = 0; k < sf.Length; k++)
{
if (sf[k][0] == ir[j])
{
val = true;
break;
}
}
if (!val)
{
sf[i].RemoveAt(0);
sf[i].Add(ir[j]);
}
else
continue;
}
}
}
return sf;
}
private async Task<StorageItemThumbnail[]> getThumbnails(IReadOnlyList<StorageFile> ir)
{
StorageItemThumbnail[] st = new StorageItemThumbnail[ir.Count];
for(int i=0;i<ir.Count;i++)
{
st[i] = await ir[i].GetThumbnailAsync(ThumbnailMode.MusicView, 200, ThumbnailOptions.UseCurrentScale);
}
return st;
}
Playlist masterPlaylist = new Playlist();
private async void AddToMasterPlaylist(StorageFolder sfolder, IReadOnlyList<StorageFile> ir)
{
StorageFolder storageFolder = null;
try
{
storageFolder =await sfolder.GetFolderAsync("MasterPlaylistSection");
}
catch (Exception)
{
}
if (storageFolder == null)
{
storageFolder = await sfolder.CreateFolderAsync("MasterPlaylistSection");
}
foreach (StorageFile sf in ir)
{
masterPlaylist.Files.Add(sf);
}
await masterPlaylist.SaveAsAsync(storageFolder, "MasterPlaylist", NameCollisionOption.ReplaceExisting, PlaylistFormat.Zune);
}
BitmapImage bi=new BitmapImage();
private void MainGrid_ItemClick_1(object sender, ItemClickEventArgs e)
{
ObservableCollection<Music> obv=new ObservableCollection<Music>();
Music mus = e.ClickedItem as Music;
foreach (Music m in o)
{
if (m.Album.Equals(mus.Album))
obv.Add(m);
}
ByFiles.ItemsSource = obv;
MainGrid.Visibility = Visibility.Collapsed;
ByFiles.Visibility = Visibility.Visible;
}
}
public class Music
{
public ImageSource Thumbnail{get;set;}
public string Duration { get; set; }
public string Title { get; set; }
public string Album { get; set; }
public StorageFile CurrentFile { get; set; }
}
}