Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9198873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:23:30+00:00 2026-06-17T22:23:30+00:00

I’m creating a simple mp3 player just to see how Dictionary works. I have

  • 0

I’m creating a simple mp3 player just to see how Dictionary works. I have 6 classes in my project which 2 of them are irrelevant. The first class includes tags, the second is search and the third is play, and the fourth which is an abstract class, includes the dictionary. Both search and play classes inherit from the fourth class.

When I go to search, objects are successfully added to the dictionary Dictionary dict<string, Tags>, and tags are added from Tags class.
My problem is, when I try to reach from Play class to get the path from dictionary it says the key is not present.
The code is dict[playSongName].Path;, where playSongName is the name of the song with which it is stored in the dictionary.

class Player : Liste
{
        public void Play(string playSongName)
        {
            currentSongPath = dictPesmi[playSongName].Path; // Error here, key was not found
            currentSongName = playSongName;
            media.Source = new Uri(currentSongPath);
            media.Play();
        }
}

abstract class Liste
{
    public Dictionary<string, Tagi> dictPesmi = new Dictionary<string, Tagi>();
    public Id3TagClass id3tagi = new Id3TagClass();
}

class Search : Liste
{

    string[] filesFound;
    const string extension = "*.mp3";


    public void Find(string searchPath)
    {
        if (Directory.Exists(searchPath))
        {
            filesFound = Directory.GetFiles(searchPath, extension, SearchOption.AllDirectories);
            foreach (string filePath in filesFound)
            {
                string[] filePathSplit = filePath.Split('\\');
                string fileName = filePathSplit[filePathSplit.Length - 1];

                dictPesmi[fileName] = new Tagi() { Path = filePath, Name = fileName };
                dictPesmi[fileName].Author = id3tagi.GetArtist(filePath);
                dictPesmi[fileName].Album = id3tagi.GetAlbum(filePath);
                dictPesmi[fileName].Title = id3tagi.GetTitle(filePath);
                System.Windows.MessageBox.Show(dictPesmi[fileName].Path);
            }


        }

    }
}

class Tagi
{

    string path;
    string name;
    string title;
    string author;
    string album;

    public string Album
    {
        get { return album; }
        set { album = value; }
    }

    public string Author
    {
        get { return author; }
        set { author = value; }
    }

    public string Title
    {
        get { return title; }
        set { title = value; }
    }

    public string Name
    {
        get { return name; }
        set { name = value; }
    }

    public string Path
    {
        get { return path; }
        set { path = value; }
    }

}

Main class

public partial class MainWindow : Window
{

    Player player = new Player();
    Search search = new Search();

   // string selectedSong;

    public MainWindow()
    {
        InitializeComponent();
    }

    public void KeyDownEvent_(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.F1)
            player.Play(lbPlaylist.Items[lbPlaylist.Items.IndexOf(lbPlaylist.SelectedItem)].ToString());// passed string
        if (e.Key == Key.F3)
            search.Find(tbSearch.Text);
        if (e.Key == Key.F5)
        {
            foreach (Tagi d in search.dictPesmi.Values)
            {
                if (!lbPlaylist.Items.Contains(d.Name))
                    lbPlaylist.Items.Add(d.Name);
            }
        }
        if (e.Key == Key.F9)
        {

        }
    }

It’s when i press the F1 the described error shows up

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:23:31+00:00Added an answer on June 17, 2026 at 10:23 pm

    Your problem here is the fact that you are filling the Dictionary contained in the instance of Search, but you are looking for the data in the one contained in the instance of Player, which is still empty.

    Everytime you create an instance of a class derived from Liste a new empty Dictionary is created. Things would work modifying your code as follows, but this is not really object oriented, I consider it really “ugly” and I would change the design of your application instead:

    public void KeyDownEvent_(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.F1)
            player.Play(lbPlaylist.Items[lbPlaylist.Items.IndexOf(lbPlaylist.SelectedItem)].ToString());// passed string
        if (e.Key == Key.F3)
            search.Find(tbSearch.Text);
        if (e.Key == Key.F5)
        {
            foreach (Tagi d in search.dictPesmi.Values)
            {
                if (!lbPlaylist.Items.Contains(d.Name))
                    lbPlaylist.Items.Add(d.Name);
            }
            // add this line to use the data just collected:
            player.dictPesmi = search.dictPesmi;
        }
        if (e.Key == Key.F9)
        {
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.