getfilename
-
Hi i have a simple window form with a listbox that plays a highlighted mp3, works great if i add the mp3 to the project bin, however when i try and put a path in for mp3 for example f:\mp3\song.mp3 it says it "cant play file " if i put a copy of the mp3 (song.mp3) in the project bin but leave the path as f:\mp3\song.mp3 then it plays fine so i'm guessing it is defaulting to the project bin to get filename, what am i missing? code: private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { dsAudioPlayer1.FileName = Path.GetFileName(listBox1.SelectedItem.ToString ()); kenny
-
Hi i have a simple window form with a listbox that plays a highlighted mp3, works great if i add the mp3 to the project bin, however when i try and put a path in for mp3 for example f:\mp3\song.mp3 it says it "cant play file " if i put a copy of the mp3 (song.mp3) in the project bin but leave the path as f:\mp3\song.mp3 then it plays fine so i'm guessing it is defaulting to the project bin to get filename, what am i missing? code: private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { dsAudioPlayer1.FileName = Path.GetFileName(listBox1.SelectedItem.ToString ()); kenny
kennyhibs wrote:
Path.GetFileName
First guess is that you are only getting the filename and not the full path to the file. Try Path.GetFullPath instead.
Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Individuality is fine, as long as we do it together - F. Burns Help humanity, join the CodeProject grid computing team here
-
Hi i have a simple window form with a listbox that plays a highlighted mp3, works great if i add the mp3 to the project bin, however when i try and put a path in for mp3 for example f:\mp3\song.mp3 it says it "cant play file " if i put a copy of the mp3 (song.mp3) in the project bin but leave the path as f:\mp3\song.mp3 then it plays fine so i'm guessing it is defaulting to the project bin to get filename, what am i missing? code: private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { dsAudioPlayer1.FileName = Path.GetFileName(listBox1.SelectedItem.ToString ()); kenny
GetFileName returns the name of the file: "song.mp3" - i.e. without the path. If you have this in the current directory (as in the case of the project directory) then it can find it. Give it the whole pathed file name and you should be fine. Try
if (File.Exists(listBox1.SelectedItem.ToString())
{
dsAudioPlayer1....
}
else
{
MessageBox.Show("Cannot find \"" + listBox1.SelectedItem.ToString() + "\"");
}No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones
-
kennyhibs wrote:
Path.GetFileName
First guess is that you are only getting the filename and not the full path to the file. Try Path.GetFullPath instead.
Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Individuality is fine, as long as we do it together - F. Burns Help humanity, join the CodeProject grid computing team here
-
Thanks for that it was exactly what was wrong, i was trying to get the mp3 to play the filename but was taking out the full path to the file so it couldn't find it :-D kenny
Glad to help
Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Individuality is fine, as long as we do it together - F. Burns Help humanity, join the CodeProject grid computing team here