This repository has been archived by the owner on Jan 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.xaml.cs
74 lines (58 loc) · 2.34 KB
/
App.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
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using RecodedMusicPlayer.Models;
using RecodedMusicPlayer.ViewModels;
using RecodedMusicPlayer.Stores;
namespace RecodedMusicPlayer
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
public static MusicPlayer _musicplayer;
public static NavigationStore _navigationStore;
public static MainPageViewModel _mainPageViewModel;
public static PlayerControlsViewModel _playerControlsViewModel;
public App()
{
_musicplayer = new MusicPlayer();
_navigationStore = new NavigationStore();
}
protected override void OnStartup(StartupEventArgs e)
{
//Source https://stackoverflow.com/questions/13301053/directory-getfiles-of-certain-extension
//Console.WriteLine(String.Join(", ", Directory.GetFiles(String.Format(@"C:\Users\{0}\Music", Environment.UserName))));
List<string> musicFiles = Directory.GetFiles(String.Format(@"C:\Users\{0}\Music", Environment.UserName), "*.*", SearchOption.AllDirectories)
.Where(file => new string[] { ".aiff", ".asf", ".au", ".cda", ".mid", ".mp3", ".mp4", ".wav", ".wma" }
.Contains(Path.GetExtension(file)))
.ToList();
int index = 0;
foreach (var file in musicFiles)
{
MusicFile song = new MusicFile(file, index++);
if (song.duration.TotalSeconds != 0)
{
_musicplayer.AddMusicToLibrary(song);
}
}
PlayerControlsViewModel vm = new PlayerControlsViewModel(_musicplayer);
vm.SetSongCommand.Execute(_musicplayer.GetMusicList().FirstOrDefault());
_playerControlsViewModel = vm;
vm.StopCommand.Execute(null);
_navigationStore.CurrentViewModel = new MainPageViewModel();
MainWindow = new MainWindow()
{
DataContext = new MainViewModel(_musicplayer, _navigationStore)
};
MainWindow.Show();
base.OnStartup(e);
}
}
}