Sorez
Sorez

Reputation: 19

Need to show the selected file's name in a label on WPF, not the full path

I currently have an mp3 player in which a Label should show the name of the selected song. As I have it set right now it shows the full path to the song instead:

label1.Content = media.Source.ToString();

As the song can be selected there is no set location or filepath mentioned in the code, letting the user select a song from wherever they want.

I've tried media.Name.ToString(); but it only gave me the word "media", so Im probably missing something simple. Would like some help!

EDIT: Here's an example of what I want to see: "“TestMp3.mp3 is playing”"

Also would need to show "paused" or "stopped" when it is.

Upvotes: 0

Views: 1503

Answers (1)

René Vogt
René Vogt

Reputation: 43876

If you want to show only the file name instead of the full path, you may use

label1.Content = Path.GetFileName(media.Source.ToString());

using the static method GetFileName of the class System.IO.Path.

This will return test.mp3 from e.g. C:\MyFiles\Audio\test.mp3.

How to show if it is playing or paused depends highly on how you manage those states. Unfortunatly your question doesn't show what type media is of, so I don't know if the information is in there.

Upvotes: 1

Related Questions