Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I'm trying to make an MP3 player for a school project...
My treeview looks like this

+C:\Folders\Folders\Files
+Album1
    Song1
    Song2
    Song3
+Album2
    Song1
    Song2
    Song3
    Song4
+Album3
    Song1
    Song2
    Song3
    Song4
    Song5


Once the treeview reaches song3 in album1, I want it to go back up to song1 in album1 for a continuous playback

I have tried

C#
treeView.SelectedNode = treeView.SelectedNode.FirstNode;
treeView.SelectedNode = treeView.Nodes[0];



I'm lost...any help would be appreciated!

I would also like to know how to make it go to Album2, song1...or once it reaches album3, song5, shoot back up to album1. However, I'm more concerned about going back up to song1 in album1 once it reaches song3. Thank you!
Posted
Updated 23-Apr-15 4:24am
v5
Comments
Sergey Alexandrovich Kryukov 22-Apr-15 22:36pm    
TreeView? Which one? Full type name, please. There are different unrelated "TreeView" types.
—SA

You did not provide enough information to help you direct way. Nevertheless, i suppose that your code is incomplete or your logic is wrong. If you need to play songs in a loop, you have to check if user choose 'continuously play'.

pseudo-code:
C#
bool playinloop = CheckBoxPlayInLoop.Checked;
do
{
    foreach (TreeViewNode n in treeView.Nodes) //album
    {
        foreach (TreeViewNode sn in n.SubNodes) //song
        {
            //play song
        }
    }
} while (playinloop)//play again
 
Share this answer
 
Sorry, I am just using a regular treeView control, one that is dragged from the toolbox to the designer form. Yes, I have a continuous play radiobutton. The code I have is within a timer. I am using Windows Media Player control to check a label for "MediaEnded" event that fires in Windows Media Player when a song ends. When the user selects a song to play the timer starts. Here is the code I have for right now.

C#
private void mainTimer_Tick_1(object sender, EventArgs e)
{
    mainTimer.Interval = 3;
    if (checkLabel.Text == "MediaEnded")
    {
        if (rbRepeat.Checked == true)
        {
            PlaySong();
            checkLabel.Text = "";
        }

        if (rbContinuous.Checked == true)
        {

            checkLabel.Text = "";
            try
            {
                mainTreeView.SelectedNode = mainTreeView.SelectedNode.NextNode;
                PlaySong();
                checkLabel.Text = "";
            }
            catch
            {
                mainTreeView.SelectedNode = mainTreeView.SelectedNode.FirstNode;
                label5.Text = mainTreeView.SelectedNode.ToString();
                PlaySong();
                checkLabel.Text = "";

            }


PlaySong() is a method I made that plays a song which works fine. The repeat function also works fine. The try block in the rbContinuous.Checked == true is where errors occur when the user would reach "Song3" in continuous mode and try to go to a Song4 when one doesn't exist. The label5.Text is irrelevant, it was just me trying to figure out what is being returned, nothing is returned in FirstNode.

I tried your code above, however Visual Studio was listing exceptions. I am very unfamiliar with TreeView, is TreeViewNodes a way of copying the contents of a TreeView control? Visual Studio was underlining TreeViewNodes as "a namespace could not be found, are you missing a using directive or assembly reference?" I changed TreeViewNodes to TreeNode to see if that would work, and it did work, however, SubNodes was then underlined as an error. I changed SubNodes to Nodes and it was not underlined, then executed the code but it did not work for me.

Edit: I did get your code to execute, however, it only works as a repeat function for me, the song ends up replaying. I removed the code I had in the try block and replaced with a code similar to yours except, TreeViewNodes replaced as TreeNode and SubNodes replaced as Nodes.

Hopefully, this clears my problem up a little bit. Any help would be appreciated and thank you guys for your replies! Sorry for the long post, just trying to figure this out if I can.
 
Share this answer
 
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900