tags:

views:

87

answers:

5

I have always wanted to make a music player. But i have no idea how to. I dont need it to be cross playform, just as long as it works.

Each part is its own question but let me know if i am missing any. I broke it up into simple, unknown and long

Simple

  • Selecting Files/Directories using a Dialog
  • Saving playlist and other settings (json i choose you!)
  • Sorting the data in the GUI

Somewhat difficult

  • Global Keys so i dont need to switch to the player window (i know this isnt supported in .NET :()
  • Searching for songs (Allowing artist and album to be mixed with title and getting what is thought to be best results)

Unknown

  • Playing actual music with pause and stop with MP3, AAC and OGG support
  • Song information (artist, album, title, year)

I have a feeling when i start this will take a long time to finish. I plan to do this in C#. Do i have to use an external lib to get song information? Is one of these harder then what some people may think? any warnings about any of the above?

+2  A: 

I would suggest, rather than trying to take on such a project yourself, find an open source music player on SourceForge, GitHub, or one of the other OS project sites and join in with that project. There are many many open source media players, so I am sure that one of them would fit parallel with your goals.

Good luck,

cjstehno
+2  A: 

First of all, while you might contribute more to the world by joining an existing project, I say: where is the fun i that? So if you doing this to learn and have fun, then you should by all means get going with it.

Global keys:

Yes it is possible by hooking into the Windows message loop. It takes a dll import of user32.dll and kernel32.dll. I have previously done something like this:

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace DevBoard.App
{
    internal class InterceptKeys
    {
        #region Delegates

        public delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);

        #endregion

        private const int WH_KEYBOARD_LL = 13;
        private const int WM_KEYDOWN = 0x0100;

        public static IntPtr SetHook(LowLevelKeyboardProc proc)
        {
            using (Process curProcess = Process.GetCurrentProcess())
            using (ProcessModule curModule = curProcess.MainModule)
            {
                return SetWindowsHookEx(WH_KEYBOARD_LL, proc,GetModuleHandle(curModule.ModuleName), 0);
            }
        }

        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern IntPtr SetWindowsHookEx(int idHook,
                                                      LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);

        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool UnhookWindowsHookEx(IntPtr hhk);

        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode,
                                                   IntPtr wParam, IntPtr lParam);

        [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern IntPtr GetModuleHandle(string lpModuleName);
    }
}

Searching

If you want to do some advanced indexed search you could have a look at Lucene.Net

Happy coding! :)

Luhmann
-1: You absolutely don't want to set a low level keyboard hook. Virus scanners will go nuts for good reason.
280Z28
As far as i know, there is no other way to achieve a global hook, and he asked for a way to do this. And I have never experienced any trouble with virus scanners.
Luhmann
There is another way to add a global hook - and it's much safer. The documentation for SetWindowsHookEx makes it painfully obvious that a low-level hook is an *absolutely unacceptable* option for a product release.
280Z28
Can you shed some light on this alternative way?
Luhmann
+1  A: 

I used Global Hotkeys in .NET in a open source project

http://skd.codeplex.com/SourceControl/changeset/view/1306#28124

I think I got the code in a Codeplex article

Jader Dias
+2  A: 

I think the best way to get an idea about how to build a music player would be to check source of an existing one :) In which case I recommend taking a look at Banshee, it's written with C# and is one of the leading music players for Linux - soon to be released on windows.

mythz
+1  A: 

I know this only addresses one small part of your question, but I saw several overly complicated (or in one case completely wrong) examples and figured I should add this.

The easiest way to add a system hotkey is with the ManagedWinapi project. After adding a reference to the project, you can place something like the following in your application startup code:

hotkey = new ManagedWinapi.Hotkey();
hotkey.WindowsKey = true;
hotkey.KeyCode = System.Windows.Forms.Keys.Space;
hotkey.HotkeyPressed += new EventHandler(hotkey_HotkeyPressed);
try
{
    hotkey.Enabled = true;
}
catch (ManagedWinapi.HotkeyAlreadyInUseException)
{
    System.Windows.MessageBox.Show("Could not register hotkey (already in use).", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
280Z28
Great solution!
acidzombie24