Added base for playlists, puts files in dir and reads files from dir
This commit is contained in:
@@ -55,7 +55,7 @@ namespace MusicPlayer
|
||||
dynamic songs = o["songs"];
|
||||
for (int i = 0; i < songs.Count; i++)
|
||||
{
|
||||
allsongslist.Add(new Song(songs[i][0].ToString(), songs[i][3].ToString(), songs[i][5].ToString(), songs[i][4].ToString(), this));
|
||||
allsongslist.Add(new Song(songs[i][0].ToString(), songs[i][3].ToString(), songs[i][5].ToString(), songs[i][4].ToString(), songs[i][1].ToString(), (int)songs[i][9], this));
|
||||
}
|
||||
}
|
||||
return allsongslist;
|
||||
|
||||
@@ -11,16 +11,18 @@ namespace MusicPlayer
|
||||
public APIHandler api;
|
||||
public MainForm form;
|
||||
public NetworkHandler nw;
|
||||
public PlaylistHandler pl;
|
||||
public AudioHandler audio;
|
||||
|
||||
private SongsTable table;
|
||||
|
||||
public Main(NetworkHandler nw, APIHandler api, MainForm form)
|
||||
public Main(NetworkHandler nw, APIHandler api, MainForm form, PlaylistHandler pl)
|
||||
{
|
||||
this.nw = nw;
|
||||
this.api = api;
|
||||
this.form = form;
|
||||
form.main = this;
|
||||
this.pl = pl;
|
||||
|
||||
audio = new AudioHandler();
|
||||
table = new SongsTable();
|
||||
@@ -34,6 +36,7 @@ namespace MusicPlayer
|
||||
this.api.GetAlbums().ForEach(a => form.AlbumListView.Items.Add(a.albumnaam));
|
||||
this.api.GetArtists().ForEach(a => form.ArtistListBox.Items.Add(a.naam));
|
||||
this.api.GetGenres().ForEach(g => form.GenreListBox.Items.Add(g.name));
|
||||
this.pl.GetPlaylists().ForEach(p => form.PlaylistBox.Items.Add(p.name));
|
||||
}
|
||||
|
||||
public void ArtistFilter(string artist)
|
||||
|
||||
+1
-1
@@ -431,7 +431,7 @@
|
||||
private System.Windows.Forms.Label GenreListLabel;
|
||||
private System.Windows.Forms.ToolStripMenuItem playlistsToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem overviewToolStripMenuItem;
|
||||
private System.Windows.Forms.ListBox PlaylistBox;
|
||||
public System.Windows.Forms.ListBox PlaylistBox;
|
||||
private System.Windows.Forms.Label PlaylistListLabel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +73,8 @@
|
||||
<Compile Include="NotificationPopup.Designer.cs">
|
||||
<DependentUpon>NotificationPopup.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Playlist.cs" />
|
||||
<Compile Include="PlaylistHandler.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Song.cs" />
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace MusicPlayer
|
||||
{
|
||||
public class Playlist
|
||||
{
|
||||
public string name { get; }
|
||||
private string basedir;
|
||||
public List<Song> songs;
|
||||
public Playlist(string name, string basedir)
|
||||
{
|
||||
this.songs = new List<Song>();
|
||||
this.name = name;
|
||||
this.basedir = basedir;
|
||||
}
|
||||
|
||||
public void AddSong(Song s)
|
||||
{
|
||||
this.songs.Add(s);
|
||||
}
|
||||
|
||||
public void WriteToFile()
|
||||
{
|
||||
using (StreamWriter stw = new StreamWriter(basedir + name + ".txt"))
|
||||
{
|
||||
this.songs.ForEach(s =>
|
||||
{
|
||||
stw.WriteLine(s.ToString());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace MusicPlayer
|
||||
{
|
||||
public class PlaylistHandler
|
||||
{
|
||||
private List<Playlist> playlists;
|
||||
private readonly string basedir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\.mpplaylists\\";
|
||||
public PlaylistHandler()
|
||||
{
|
||||
this.playlists = new List<Playlist>();
|
||||
Populate();
|
||||
}
|
||||
|
||||
private void Populate()
|
||||
{
|
||||
try {
|
||||
Directory.GetFiles(basedir).ToList().ForEach(f =>
|
||||
{
|
||||
if (f.EndsWith(".txt"))
|
||||
{
|
||||
playlists.Add(new Playlist(Path.GetFileName(f.Replace(".txt","")) ,basedir));
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
Directory.CreateDirectory(basedir);
|
||||
Populate();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public List<Playlist> GetPlaylists()
|
||||
{
|
||||
return playlists;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,28 +19,9 @@ namespace MusicPlayer
|
||||
|
||||
NetworkHandler nw = new NetworkHandler("http://www.imegumii.nl");
|
||||
APIHandler api = new APIHandler(nw);
|
||||
// api.GetSongsByArtist("Amon Amarth").ForEach(s =>
|
||||
// {
|
||||
// Console.WriteLine(s.SongID);
|
||||
// });
|
||||
// api.GetSongsByYear("2009").ForEach(s =>
|
||||
// {
|
||||
// Console.WriteLine(s.Name);
|
||||
// });
|
||||
// api.GetSongsByGenre("Melodic Death Metal").ForEach(s =>
|
||||
// {
|
||||
// Console.WriteLine(s.Name);
|
||||
// });
|
||||
// api.GetSongsByAlbum("Stronger").ForEach(s =>
|
||||
// {
|
||||
// Console.WriteLine(s.Name);
|
||||
// });
|
||||
api.GetAllSongs().ForEach(s =>
|
||||
{
|
||||
Console.WriteLine(s.Name);
|
||||
});
|
||||
MainForm form = new MainForm();
|
||||
new Main(nw, api, form);
|
||||
PlaylistHandler pl = new PlaylistHandler();
|
||||
new Main(nw, api, form,pl);
|
||||
|
||||
Application.Run(form);
|
||||
}
|
||||
|
||||
@@ -48,5 +48,10 @@ namespace MusicPlayer
|
||||
{
|
||||
url = str;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{this.SongID}|{this.Name}|{this.Album}|{this.Artist}|{this.Seconds}|{this.Genre}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user