From ef61830a00595c47797a596fc02d98a58f721cd8 Mon Sep 17 00:00:00 2001 From: Royce551 Date: Mon, 6 Jul 2020 23:12:02 -0500 Subject: [PATCH] initial commit --- .../FRESHMusicPlayer.Player.sln | 31 ++ .../FRESHMusicPlayer.Core.csproj | 73 ++++ .../Handlers/DatabaseHandler.cs | 128 +++++++ .../Handlers/ErrorHandler.cs | 13 + .../Handlers/Integrations/Integration.cs | 40 +++ .../Handlers/InternetHandler.cs | 19 + .../FRESHMusicPlayer.Player/Player.cs | 328 ++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++ .../Utilities/PlayerUtils.cs | 38 ++ .../Utilities/database.json | 1 + .../Utilities/databaseformat.cs | 10 + .../FRESHMusicPlayer.Player/packages.config | 7 + .../WinformsTest/App.config | 6 + .../WinformsTest/Form1.Designer.cs | 112 ++++++ FRESHMusicPlayer.Player/WinformsTest/Form1.cs | 61 ++++ .../WinformsTest/Form1.resx | 120 +++++++ .../WinformsTest/Program.cs | 22 ++ .../WinformsTest/Properties/AssemblyInfo.cs | 36 ++ .../Properties/Resources.Designer.cs | 71 ++++ .../WinformsTest/Properties/Resources.resx | 117 +++++++ .../Properties/Settings.Designer.cs | 30 ++ .../WinformsTest/Properties/Settings.settings | 7 + .../WinformsTest/WinformsTest.csproj | 89 +++++ 23 files changed, 1395 insertions(+) create mode 100644 FRESHMusicPlayer.Player/FRESHMusicPlayer.Player.sln create mode 100644 FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/FRESHMusicPlayer.Core.csproj create mode 100644 FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Handlers/DatabaseHandler.cs create mode 100644 FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Handlers/ErrorHandler.cs create mode 100644 FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Handlers/Integrations/Integration.cs create mode 100644 FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Handlers/InternetHandler.cs create mode 100644 FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Player.cs create mode 100644 FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Properties/AssemblyInfo.cs create mode 100644 FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Utilities/PlayerUtils.cs create mode 100644 FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Utilities/database.json create mode 100644 FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Utilities/databaseformat.cs create mode 100644 FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/packages.config create mode 100644 FRESHMusicPlayer.Player/WinformsTest/App.config create mode 100644 FRESHMusicPlayer.Player/WinformsTest/Form1.Designer.cs create mode 100644 FRESHMusicPlayer.Player/WinformsTest/Form1.cs create mode 100644 FRESHMusicPlayer.Player/WinformsTest/Form1.resx create mode 100644 FRESHMusicPlayer.Player/WinformsTest/Program.cs create mode 100644 FRESHMusicPlayer.Player/WinformsTest/Properties/AssemblyInfo.cs create mode 100644 FRESHMusicPlayer.Player/WinformsTest/Properties/Resources.Designer.cs create mode 100644 FRESHMusicPlayer.Player/WinformsTest/Properties/Resources.resx create mode 100644 FRESHMusicPlayer.Player/WinformsTest/Properties/Settings.Designer.cs create mode 100644 FRESHMusicPlayer.Player/WinformsTest/Properties/Settings.settings create mode 100644 FRESHMusicPlayer.Player/WinformsTest/WinformsTest.csproj diff --git a/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player.sln b/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player.sln new file mode 100644 index 0000000..c160673 --- /dev/null +++ b/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30114.105 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FRESHMusicPlayer.Core", "FRESHMusicPlayer.Player\FRESHMusicPlayer.Core.csproj", "{FFE8EAFD-7FAA-4503-9364-2643821A2BC8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinformsTest", "WinformsTest\WinformsTest.csproj", "{AA375910-6E80-4570-9663-8EA13238192A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FFE8EAFD-7FAA-4503-9364-2643821A2BC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FFE8EAFD-7FAA-4503-9364-2643821A2BC8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FFE8EAFD-7FAA-4503-9364-2643821A2BC8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FFE8EAFD-7FAA-4503-9364-2643821A2BC8}.Release|Any CPU.Build.0 = Release|Any CPU + {AA375910-6E80-4570-9663-8EA13238192A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AA375910-6E80-4570-9663-8EA13238192A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AA375910-6E80-4570-9663-8EA13238192A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AA375910-6E80-4570-9663-8EA13238192A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {4AD6E028-0932-471C-828A-F2CBCA4A7CED} + EndGlobalSection +EndGlobal diff --git a/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/FRESHMusicPlayer.Core.csproj b/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/FRESHMusicPlayer.Core.csproj new file mode 100644 index 0000000..1fd0a27 --- /dev/null +++ b/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/FRESHMusicPlayer.Core.csproj @@ -0,0 +1,73 @@ + + + + + Debug + AnyCPU + {FFE8EAFD-7FAA-4503-9364-2643821A2BC8} + Library + Properties + FRESHMusicPlayer.Player + FRESHMusicPlayer.Core + v4.7.2 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\z440.atl.core.2.16.0\lib\net30\ATL.dll + + + ..\packages\DiscordRichPresence.1.0.150\lib\net35\DiscordRPC.dll + + + ..\packages\NAudio.1.10.0\lib\net35\NAudio.dll + + + ..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + + + Form + + + + + + + + + + + \ No newline at end of file diff --git a/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Handlers/DatabaseHandler.cs b/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Handlers/DatabaseHandler.cs new file mode 100644 index 0000000..031e204 --- /dev/null +++ b/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Handlers/DatabaseHandler.cs @@ -0,0 +1,128 @@ +using FRESHMusicPlayer.Utilities; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO; +namespace FRESHMusicPlayer.Handlers +{ + static class DatabaseHandler + { + public static readonly int DatabaseVersion = 1; + public static readonly string DatabasePath; + static DatabaseHandler() + { + DatabasePath = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\FRESHMusicPlayer"; + } + /// + /// Returns all of the tracks in the database. + /// + /// A list of file paths in the database. + public static List ReadSongs() + { + if (!File.Exists(DatabasePath + "\\database.json")) + { + Directory.CreateDirectory(DatabasePath); + File.WriteAllText(DatabasePath + "\\database.json", $"{{\"Version\":{DatabaseVersion},\"Songs\":[]}}"); + } + using (StreamReader file = File.OpenText(DatabasePath + "\\database.json")) // Read json file + { + JsonSerializer serializer = new JsonSerializer(); + DatabaseFormat database = (DatabaseFormat)serializer.Deserialize(file, typeof(DatabaseFormat)); + return database.Songs; + } + } + + public static void ImportSong(string filepath) + { + List database = ReadSongs(); + + database.Add(filepath); // Add the new song in + DatabaseFormat format = new DatabaseFormat(); + format.Version = 1; + format.Songs = new List(); + format.Songs = database; + + using (StreamWriter file = File.CreateText(DatabasePath + "\\database.json")) + { + JsonSerializer serializer = new JsonSerializer(); + serializer.Serialize(file, format); + } + + } + public static void ImportSong(string[] filepath) + { + List database = ReadSongs(); + + database.AddRange(filepath); + DatabaseFormat format = new DatabaseFormat(); + format.Version = 1; + format.Songs = new List(); + format.Songs = database; + + using (StreamWriter file = File.CreateText(DatabasePath + "\\database.json")) + { + JsonSerializer serializer = new JsonSerializer(); + serializer.Serialize(file, format); + } + + } + public static void ImportSong(List filepath) + { + List database = ReadSongs(); + + database.AddRange(filepath); + DatabaseFormat format = new DatabaseFormat(); + format.Version = 1; + format.Songs = new List(); + format.Songs = database; + + using (StreamWriter file = File.CreateText(DatabasePath + "\\database.json")) + { + JsonSerializer serializer = new JsonSerializer(); + serializer.Serialize(file, format); + } + + } + public static void ImportSong(IList filepath) + { + List database = ReadSongs(); + + database.AddRange(filepath); + DatabaseFormat format = new DatabaseFormat(); + format.Version = 1; + format.Songs = new List(); + format.Songs = database; + + using (StreamWriter file = File.CreateText(DatabasePath + "\\database.json")) + { + JsonSerializer serializer = new JsonSerializer(); + serializer.Serialize(file, format); + } + + } + public static void DeleteSong(string filepath) + { + List database = ReadSongs(); + database.Remove(filepath); + DatabaseFormat format = new DatabaseFormat(); + format.Version = 1; + format.Songs = database; + + + using (StreamWriter file = File.CreateText(DatabasePath + "\\database.json")) + { + JsonSerializer serializer = new JsonSerializer(); + serializer.Serialize(file, format); + } + } + public static void ClearLibrary() + { + if (File.Exists(DatabasePath + "\\database.json")) + { + File.Delete(DatabasePath + "\\database.json"); + File.WriteAllText(DatabasePath + "\\database.json", @"{""Version"":1,""Songs"":[]}"); + } + } + } + +} diff --git a/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Handlers/ErrorHandler.cs b/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Handlers/ErrorHandler.cs new file mode 100644 index 0000000..58f51c7 --- /dev/null +++ b/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Handlers/ErrorHandler.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FRESHMusicPlayer.Handlers +{ + public class PlaybackExceptionEventArgs : EventArgs + { + public string Details { get; set; } + } +} diff --git a/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Handlers/Integrations/Integration.cs b/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Handlers/Integrations/Integration.cs new file mode 100644 index 0000000..1d289cf --- /dev/null +++ b/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Handlers/Integrations/Integration.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Drawing; +namespace FRESHMusicPlayer.Handlers.Integrations +{ + + class IntegrationData + { + public string Title { get; set; } + public string Artist { get; set; } + public string Album { get; set; } + public string Genre { get; set; } + public int Year { get; set; } + public int TrackNumber { get; set; } + public int DiscNumber { get; set; } + public int Bitrate { get; set; } + //public Image AlbumArt { get; set; } + + } + class IntegrationQuery + { + public string Title { get; set; } + public string AltTitle { get; set; } + public string Album { get; set; } + public int TrackNumber { get; set; } + } + abstract class Integration + { + /*abstract public (string type, string label)[] Options { get; } + /// + /// Fetches metadata from the integration. + /// + /// The query for the integration to use (usually the song title) + /// + abstract public List FetchMetadata(IntegrationQuery query);*/ + } +} diff --git a/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Handlers/InternetHandler.cs b/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Handlers/InternetHandler.cs new file mode 100644 index 0000000..0ba3d6a --- /dev/null +++ b/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Handlers/InternetHandler.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; + +namespace FRESHMusicPlayer.Handlers +{ + public static class InternetHandler + { + public static HttpClient HttpClient; + static InternetHandler() + { + HttpClient = new HttpClient(); + HttpClient.DefaultRequestHeaders.UserAgent.ParseAdd($"FRESHMusicPlayer/8.0.0 (https://github.com/Royce551/FRESHMusicPlayer)"); // hi i'm FMP + } + } +} diff --git a/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Player.cs b/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Player.cs new file mode 100644 index 0000000..3631c02 --- /dev/null +++ b/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Player.cs @@ -0,0 +1,328 @@ +using DiscordRPC; +using NAudio.Wave; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using System.Windows.Forms; +using FRESHMusicPlayer.Handlers; +using FRESHMusicPlayer.Utilities; +using System.Net.Http; +namespace FRESHMusicPlayer +{ + public partial class Player : Form + { + private static WaveOutEvent outputDevice; + public static AudioFileReader audioFile; + public static bool avoidnextqueue = false; + public static DiscordRpcClient client; + + //public static int position; + public static float currentvolume = 1; + public static string filePath = ""; + public static bool playing = false; + public static bool paused = false; + + public static bool RepeatOnce = false; + public static bool Shuffle = false; + + private static List Queue = new List(); + public static int QueuePosition = 0; + + public static DateTime lastUpdateCheck; + /// + /// Raised whenever a new track is being played. + /// + public static event EventHandler songChanged; + public static event EventHandler songStopped; + public static event EventHandler songException; + public Player() + { + } + #region CoreFMP + // Queue System + /// + /// Adds a track to the . + /// + /// The file path to the track to add. + public static void AddQueue(string filePath) + { + Queue.Add(filePath); + } + public static void AddQueue(string[] filePaths) + { + Queue.AddRange(filePaths); + } + public static void ClearQueue() => Queue.Clear(); + public static List GetQueue() + { + + return Queue; + } + /// + /// Skips to the previous track in the queue. If there are no tracks for the player to go back to, nothing will happen. + /// + public static void PreviousSong() + { + if (QueuePosition <= 1) return; + if (Shuffle) Queue = PlayerUtils.ShuffleQueue(Queue); + QueuePosition -= 2; + PlayMusic(); + } + /// + /// Skips to the next track in the queue. If there are no more tracks, the player will stop. + /// + /// Intended to be used only by the player + public static void NextSong(bool avoidnext = false) + { + avoidnextqueue = avoidnext; + if (QueuePosition >= Queue.Count) + { + Queue.Clear(); + QueuePosition = 0; + StopMusic(); + return; + } + if (RepeatOnce) QueuePosition--; // Don't advance queue, play the same thing again + if (Shuffle) Queue = PlayerUtils.ShuffleQueue(Queue); + PlayMusic(); + } + // Music Playing Controls + private static void OnPlaybackStopped(object sender, StoppedEventArgs args) + { + if (!avoidnextqueue) NextSong(false); + else + { + avoidnextqueue = false; + } + } + /// + /// Repositions the playback position of the player. + /// + /// The position in to the track to skip in, in seconds. + public static void RepositionMusic(int seconds) + { + audioFile.CurrentTime = TimeSpan.FromSeconds(seconds); + } + + /// + /// Starts playing the queue. In order to play a track, you must first add it to the queue using . + /// + /// If true, avoids dequeuing the next track. Not to be used for anything other than the player. + public static void PlayMusic(bool repeat = false) + { + if (!repeat && Queue.Count != 0) filePath = Queue[QueuePosition]; // Some functions want to play the same song again + QueuePosition++; + void PMusic() + { + if (outputDevice == null) + { + outputDevice = new WaveOutEvent(); + outputDevice.PlaybackStopped += OnPlaybackStopped; + } + if (audioFile == null) + { + audioFile = new AudioFileReader(filePath); + outputDevice.Init(audioFile); + } + outputDevice.Play(); + outputDevice.Volume = currentvolume; + playing = true; + } + try + { + if (playing != true) + { + PMusic(); + } + else + { + avoidnextqueue = true; + StopMusic(); + PMusic(); + } + songChanged?.Invoke(null, EventArgs.Empty); // Now that playback has started without any issues, fire the song changed event. + } + catch (System.IO.FileNotFoundException) + { + PlaybackExceptionEventArgs args = new PlaybackExceptionEventArgs(); + args.Details = "That's not a valid file path!"; + songException.Invoke(null, args); + } + catch (System.ArgumentException) + { + PlaybackExceptionEventArgs args = new PlaybackExceptionEventArgs(); + args.Details = "That's not a valid file path!"; + songException.Invoke(null, args); + } + catch (System.Runtime.InteropServices.COMException) + { + PlaybackExceptionEventArgs args = new PlaybackExceptionEventArgs(); + args.Details = "This isn't a valid audio file!"; + songException.Invoke(null, args); + } + catch (System.FormatException) + { + PlaybackExceptionEventArgs args = new PlaybackExceptionEventArgs(); + args.Details = "This audio file might be corrupt!"; + songException.Invoke(null, args); + } + catch (System.InvalidOperationException) + { + PlaybackExceptionEventArgs args = new PlaybackExceptionEventArgs(); + args.Details = "This audio file uses VBR \nor might be corrupt!"; + songException.Invoke(null, args); + } + + + } + /// + /// Completely stops and disposes the player and resets all playback related variables to their defaults. + /// + public static void StopMusic() + { + if (playing) + try + { + outputDevice.Dispose(); + outputDevice = null; + audioFile?.Dispose(); + audioFile = null; + playing = false; + paused = false; + //position = 0; + songStopped?.Invoke(null, EventArgs.Empty); + } + catch (NAudio.MmException) // This is an old workaround from the original FMP days. Shouldn't be needed anymore, but is kept anyway for the sake of + { // stability. + Console.WriteLine("Things are breaking!"); + Console.WriteLine(filePath); + outputDevice?.Dispose(); + outputDevice = new WaveOutEvent(); + outputDevice.PlaybackStopped += OnPlaybackStopped; // Does the same initiallization PlayMusic() does. + audioFile = new AudioFileReader(filePath); + outputDevice.Init(audioFile); + PlayMusic(true); + } + + } + /// + /// Pauses playback without disposing. Can later be resumed with . + /// + public static void PauseMusic() + { + if (!paused) outputDevice?.Pause(); + paused = true; + }// Pauses the music without completely disposing it + /// + /// Resumes playback. + /// + public static void ResumeMusic() + { + if (paused) outputDevice?.Play(); + //playing = true; + paused = false; + }// Resumes music that has been paused + /// + /// Updates the volume of the player during playback to the value of . + /// Even if you don't call this, the volume of the player will update whenever the next track plays. + /// + public static void UpdateSettings() + { + outputDevice.Volume = currentvolume; + } + // Other Logic Stuff + /// + /// Returns a formatted string of the current playback position. + /// + /// + public static string getSongPosition() + { + //if (playing) // Only work if music is currently playing + //if (!positiononly) position += 1; // Only tick up the position if it's being called from UserInterface + + string Format(int secs) + { + int hours = 0; + int mins = 0; + + while (secs >= 60) + { + mins++; + secs -= 60; + } + + while (mins >= 60) + { + hours++; + mins -= 60; + } + + string hourStr = hours.ToString(); if (hourStr.Length < 2) hourStr = "0" + hourStr; + string minStr = mins.ToString(); if (minStr.Length < 2) minStr = "0" + minStr; + string secStr = secs.ToString(); if (secStr.Length < 2) secStr = "0" + secStr; + + string durStr = ""; + if (hourStr != "00") durStr += hourStr + ":"; + durStr = minStr + ":" + secStr; + + return durStr; + } + + //ATL.Track theTrack = new ATL.Track(filePath); + var length = audioFile.TotalTime; + + return $"{Format((int)audioFile.CurrentTime.TotalSeconds)} / {Format((int)length.TotalSeconds)}"; + } + #endregion + // Integration + #region DiscordRPC + public static void InitDiscordRPC() + { + /* + Create a discord client + NOTE: If you are using Unity3D, you must use the full constructor and define + the pipe connection. + */ + client = new DiscordRpcClient("656678380283887626"); + + //Set the logger + //client.Logger = new ConsoleLogger() { Level = Discord.LogLevel.Warning }; + + //Subscribe to events + client.OnReady += (sender, e) => + { + Console.WriteLine("Received Ready from user {0}", e.User.Username); + }; + + client.OnPresenceUpdate += (sender, e) => + { + Console.WriteLine("Received Update! {0}", e.Presence); + }; + + //Connect to the RPC + client.Initialize(); + + //Set the rich presence + //Call this as many times as you want and anywhere in your code. + } + public static void UpdateRPC(string Activity, string Artist = null, string Title = null) + { + client?.SetPresence(new RichPresence() + { + Details = Title, + State = $"by {Artist}", + Assets = new Assets() + { + LargeImageKey = "icon", + SmallImageKey = Activity + }, + Timestamps = Timestamps.Now + } + ); + + } + public static void DisposeRPC() => client?.Dispose(); + #endregion + + } +} diff --git a/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Properties/AssemblyInfo.cs b/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..6acb79a --- /dev/null +++ b/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("FRESHMusicPlayer.Player")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("FRESHMusicPlayer.Player")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("ffe8eafd-7faa-4503-9364-2643821a2bc8")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Utilities/PlayerUtils.cs b/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Utilities/PlayerUtils.cs new file mode 100644 index 0000000..77d4f39 --- /dev/null +++ b/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Utilities/PlayerUtils.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using FRESHMusicPlayer; +namespace FRESHMusicPlayer.Utilities +{ + static class PlayerUtils + { + private static Random rng = new Random(); + + public static List ShuffleQueue(List list) + { + List listtosort = new List(); + List listtoreinsert = new List(); + int number = 0; + foreach (string x in list) + { + if (Player.QueuePosition < number) listtosort.Add(x); + else listtoreinsert.Add(x); + number++; + } + + int n = listtosort.Count; + while (n > 1) + { + n--; + int k = rng.Next(n + 1); + string value = listtosort[k]; + listtosort[k] = listtosort[n]; + listtosort[n] = value; + } + foreach (string x in listtosort) listtoreinsert.Add(x); + return listtoreinsert; + } + } +} diff --git a/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Utilities/database.json b/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Utilities/database.json new file mode 100644 index 0000000..0daed10 --- /dev/null +++ b/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Utilities/database.json @@ -0,0 +1 @@ +{"Version":1,"Songs":["C:\\Users\\poohw\\OneDrive\\Music\\Nanahira\\08 - Zennihon Ofuroka Keikaku.mp3","C:\\Users\\poohw\\OneDrive\\Music\\Nanahira\\shutter.mp3","C:\\Users\\poohw\\OneDrive\\Music\\Nanahira\\audio.mp3"]} \ No newline at end of file diff --git a/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Utilities/databaseformat.cs b/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Utilities/databaseformat.cs new file mode 100644 index 0000000..f475aff --- /dev/null +++ b/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/Utilities/databaseformat.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; + +namespace FRESHMusicPlayer.Utilities +{ + public class DatabaseFormat + { + public int Version { get; set; } + public List Songs { get; set; } + } +} \ No newline at end of file diff --git a/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/packages.config b/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/packages.config new file mode 100644 index 0000000..6aa70ec --- /dev/null +++ b/FRESHMusicPlayer.Player/FRESHMusicPlayer.Player/packages.config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/FRESHMusicPlayer.Player/WinformsTest/App.config b/FRESHMusicPlayer.Player/WinformsTest/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/FRESHMusicPlayer.Player/WinformsTest/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/FRESHMusicPlayer.Player/WinformsTest/Form1.Designer.cs b/FRESHMusicPlayer.Player/WinformsTest/Form1.Designer.cs new file mode 100644 index 0000000..81ee587 --- /dev/null +++ b/FRESHMusicPlayer.Player/WinformsTest/Form1.Designer.cs @@ -0,0 +1,112 @@ +namespace WinformsTest +{ + partial class FreshMusicPlayer + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.button1 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); + this.label2 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 26); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(35, 13); + this.label1.TabIndex = 0; + this.label1.Text = "label1"; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(294, 12); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(143, 41); + this.button1.TabIndex = 1; + this.button1.Text = "Pause/Resume"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(294, 59); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(143, 41); + this.button2.TabIndex = 2; + this.button2.Text = "Stop"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // button3 + // + this.button3.Location = new System.Drawing.Point(294, 106); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(143, 41); + this.button3.TabIndex = 3; + this.button3.Text = "Play Song!"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 59); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(35, 13); + this.label2.TabIndex = 4; + this.label2.Text = "label2"; + // + // FreshMusicPlayer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(449, 200); + this.Controls.Add(this.label2); + this.Controls.Add(this.button3); + this.Controls.Add(this.button2); + this.Controls.Add(this.button1); + this.Controls.Add(this.label1); + this.Name = "FreshMusicPlayer"; + this.Text = "FRESHMusicPlayer Core Tester Thingamajiga"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.Label label2; + } +} + diff --git a/FRESHMusicPlayer.Player/WinformsTest/Form1.cs b/FRESHMusicPlayer.Player/WinformsTest/Form1.cs new file mode 100644 index 0000000..5473b85 --- /dev/null +++ b/FRESHMusicPlayer.Player/WinformsTest/Form1.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using FRESHMusicPlayer; +namespace WinformsTest +{ + public partial class FreshMusicPlayer : Form + { + public FreshMusicPlayer() + { + InitializeComponent(); + Player.songChanged += Player_songChanged; + Player.songStopped += Player_songStopped; + Player.songException += Player_songException; + } + + private void Player_songException(object sender, FRESHMusicPlayer.Handlers.PlaybackExceptionEventArgs e) + { + MessageBox.Show("something did a fucky wucky"); + } + + private void Player_songStopped(object sender, EventArgs e) + { + label1.Text = "stopped"; + } + + private void Player_songChanged(object sender, EventArgs e) + { + label1.Text = "playing something!"; + } + + private void button1_Click(object sender, EventArgs e) + { + if (Player.paused) Player.ResumeMusic(); + else Player.PauseMusic(); + } + + private void button2_Click(object sender, EventArgs e) + { + Player.StopMusic(); + } + + private void button3_Click(object sender, EventArgs e) + { + OpenFileDialog openFileDialog1 = new OpenFileDialog(); + if (openFileDialog1.ShowDialog() == DialogResult.OK) + { + Player.AddQueue(openFileDialog1.FileName); + Player.PlayMusic(); + Player.currentvolume = 0.2f; + Player.UpdateSettings(); + } + } + } +} diff --git a/FRESHMusicPlayer.Player/WinformsTest/Form1.resx b/FRESHMusicPlayer.Player/WinformsTest/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/FRESHMusicPlayer.Player/WinformsTest/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FRESHMusicPlayer.Player/WinformsTest/Program.cs b/FRESHMusicPlayer.Player/WinformsTest/Program.cs new file mode 100644 index 0000000..7b99d9b --- /dev/null +++ b/FRESHMusicPlayer.Player/WinformsTest/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WinformsTest +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new FreshMusicPlayer()); + } + } +} diff --git a/FRESHMusicPlayer.Player/WinformsTest/Properties/AssemblyInfo.cs b/FRESHMusicPlayer.Player/WinformsTest/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..2aa0c0e --- /dev/null +++ b/FRESHMusicPlayer.Player/WinformsTest/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("WinformsTest")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("WinformsTest")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("aa375910-6e80-4570-9663-8ea13238192a")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/FRESHMusicPlayer.Player/WinformsTest/Properties/Resources.Designer.cs b/FRESHMusicPlayer.Player/WinformsTest/Properties/Resources.Designer.cs new file mode 100644 index 0000000..f597a88 --- /dev/null +++ b/FRESHMusicPlayer.Player/WinformsTest/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace WinformsTest.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WinformsTest.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/FRESHMusicPlayer.Player/WinformsTest/Properties/Resources.resx b/FRESHMusicPlayer.Player/WinformsTest/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/FRESHMusicPlayer.Player/WinformsTest/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FRESHMusicPlayer.Player/WinformsTest/Properties/Settings.Designer.cs b/FRESHMusicPlayer.Player/WinformsTest/Properties/Settings.Designer.cs new file mode 100644 index 0000000..afc4aa1 --- /dev/null +++ b/FRESHMusicPlayer.Player/WinformsTest/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace WinformsTest.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/FRESHMusicPlayer.Player/WinformsTest/Properties/Settings.settings b/FRESHMusicPlayer.Player/WinformsTest/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/FRESHMusicPlayer.Player/WinformsTest/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/FRESHMusicPlayer.Player/WinformsTest/WinformsTest.csproj b/FRESHMusicPlayer.Player/WinformsTest/WinformsTest.csproj new file mode 100644 index 0000000..a68a8aa --- /dev/null +++ b/FRESHMusicPlayer.Player/WinformsTest/WinformsTest.csproj @@ -0,0 +1,89 @@ + + + + + Debug + AnyCPU + {AA375910-6E80-4570-9663-8EA13238192A} + WinExe + WinformsTest + WinformsTest + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + {ffe8eafd-7faa-4503-9364-2643821a2bc8} + FRESHMusicPlayer.Core + + + + \ No newline at end of file