Hi i am make a small media player to play some mp3 file i have try many different way in which to make this program i finally resolved myself to using a dialog box because i could not get it done any other way with out having to worry about where the other person would install this program (because of directories).

you see i want to be able to bring this program to any one's computer and play the songs that i have in the resource folder.

I have use the following way:

dialog box:

private void LLRap_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            // Diectory of the music i want to play  

            dlg.InitialDirectory = @"c:\woods all projects\musicChoice\Rap";

            dlg.CheckFileExists = true;

            dlg.Multiselect = false;

            dlg.Filter = "Media Files(*.avi;*.mp3;*.mpg;*.mpa)" +

                   "|*.avi;*.mp3;*.mpg;*.mpa|" +

                 "All files (*.*)|*.*";

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                axWindowsMediaPlayer1.URL = dlg.FileName;

                BackColor = Color.Black; // colour to Black
                pbPac.Show();
                pbBeatles.Visible = false;
                pbIndie.Visible = false;
                pbMet.Visible = false;

            }
        }

Hard codeing in the address

private void LLRap_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {

                axWindowsMediaPlayer1.URL = @"C:\Users\michael\Desktop\Wood All Projects\musicChoice\Rap\2pac.mp3";

                BackColor = Color.Black; // colour to Black
                pbPac.Show();
                pbBeatles.Visible = false;
                pbIndie.Visible = false;
                pbMet.Visible = false;
        }

finally not using the drive directory just the folders ( This is the part i will ask about after the code):

private void LLRap_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {

                axWindowsMediaPlayer1.URL = "\\Users\\michael\\Desktop\\Wood All Projects\\musicChoice\\musicChoice\\Resources\\2pac.mp3";

                BackColor = Color.Black; // colour to Black
                pbPac.Show();
                pbBeatles.Visible = false;
                pbIndie.Visible = false;
                pbMet.Visible = false;
        }

You see what i want to be able to do it cut this last code to just use

axWindowsMediaPlayer1.URL = "\\Resources\\2pac.mp3";

but it wont find the file the reason i want to cut it to this is that if i don't

axWindowsMediaPlayer1.URL = "\\Users\\michael\\Desktop\\Wood All Projects\\musicChoice\\musicChoice\\Resources\\2pac.mp3";

no one else's computer will have this directory only mine but any one should be able to read
axWindowsMediaPlayer1.URL = "\\Resources\\2pac.mp3";
if you understand what i mean.

so is there any way to put in an address with out worrying about directories or do i just haver to use a dialog box

When the program opens you need to save its current directory to a string, then append the resource folder name and song file name.

this method will return the directory that your application was open from.

private string GetAssemblyPath()
        {
            System.Reflection.Assembly exe = System.Reflection.Assembly.GetEntryAssembly();

            return System.IO.Path.GetDirectoryName(exe.Location);
        }

then you can do something like

axWindowsMediaPlayer1.URL = "GetAssemblyPath() + \\Resources\\2pac.mp3";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.