'Windows Media Player Duration Not Working?

I am currently making a WPF App as a school project. I chose a Media player topic.

I have a slight problem with returning track length of a song and assigning it as a maximum for a slider (I used a slider for song seeking).

                /*List<string> pathPesme = new List<string>();
                path = od.FileNames;
                for (int i = 0; i < path.Length; i++)
                {
                    lista.Add(path[i]);
                    m.CreateControl();
                    media = this.m.newMedia(path[i]);*/

//When i want to instance a new class Pesma(song) and put the track length(duzina), it works and returns the value in a mm:ss format.

                    string ime = System.IO.Path.GetFileName(path[i]);
                    string duzina = media.durationString;
                    Pesma pesma = new Pesma(ime, path[i], duzina);
                    listaPesmi.Add(pesma);
                }

However, when i try to do a similar thing and put it as Slider.Maximum, it doesn't work.

                        foreach (var pesma in dispesma)/**/
                        {
                            string aa=iseciString(lbxListaPesama.Items[lbxListaPesama.SelectedIndex].ToString(), ':'); 
//Method for cutting string to get song name
                            if (pesma.ImePesme == aa)
                            {
                                m.URL = pesma.Path;
                                premotajSlider.Maximum = Math.Ceiling(m.currentMedia.duration); //Slider: Here i try to put the max value. In the debugger, it returns a 0
                                m.Ctlcontrols.play();
                                jacinaZvukaSlider.Value = m.settings.volume;
                            }
                        }

It's my first time asking on StackOverflow, so I hope I didn't do something bad. If I did, sorry, still in the learning phase.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source