Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript Selection logic got too complicated

thesoundsmith

Active Coder
My "radio station" works just great, except for a selection question. Try it here: DashRadio
I am trying to select from a series of XML files for music playlists. Here is a typical XML entry:
XML:
<item>
<media:content url="https://www.davidkempton.com/wp-content/uploads/02-By-The-Time-I-Get-To-Phoenix.mp3" />
<media:thumbnail url="pix/esp4web.gif" />
<title>By The Time I Get To Phoenix</title>
<description>Especially For Groovers</description>
<link>https://www.davidkempton.com/rec/esp4/</link>
</item>

When selecting a "New" file, isAlbum is set False, and I want it to always select a different 'Link' from the current AND previous link, so the choice doesn't select this same link OR the previous one.

When pressing the "More" button, isAlbum is set True. It matches the Description field and opens a specific playlist for THAT project. Now all the link AND Descriptions are the same so I want to select a different Title, again not from the current or last titles. I hope this is clear. All XML files have each item twice just to prevent search issues.

The selection works perfectly except it allows repeats of tracks. I try to prevent picking a duplicate "Title" but it's not working. (It's best to test on Rhinoblossom, it has the fewest tracks so repeats will happen quickly) - select "New" till a Rhinoblossoom track plays, then press 'More' Now press 'New' to look for duplicates...

Here is the function, it is triggered by clicking New or More: I thought this was correct, but pressing New still finds duplicate projects AND titles. I did not condense it down to avoid confusion - didn't help...
JavaScript:
                 function swapAlbum() {

                    var newProj = jwplayer(radio).getPlaylistItem().link;

                    newTitle == newProj.title;

                    if (((isAlbum == false) && (newProj == thisProj)) || thisTitle== prevTitle) || thisTitle== newTitle)) {

                            newProj = jwplayer(radio).playlistNext();

                            newTitle == newProj.title;

                    } else {

                          prevTitle = thisTitle;

                          thisTitle = newTitle;

                          prevProj = thisProj;

                          thisProj = newProj;

                    }

            }

Thanks in advance for your help.
 
My "radio station" works just great, except for a selection question. Try it here: DashRadio
I am trying to select from a series of XML files for music playlists. Here is a typical XML entry:
XML:
<item>
<media:content url="https://www.davidkempton.com/wp-content/uploads/02-By-The-Time-I-Get-To-Phoenix.mp3" />
<media:thumbnail url="pix/esp4web.gif" />
<title>By The Time I Get To Phoenix</title>
<description>Especially For Groovers</description>
<link>https://www.davidkempton.com/rec/esp4/</link>
</item>

When selecting a "New" file, isAlbum is set False, and I want it to always select a different 'Link' from the current AND previous link, so the choice doesn't select this same link OR the previous one.

When pressing the "More" button, isAlbum is set True. It matches the Description field and opens a specific playlist for THAT project. Now all the link AND Descriptions are the same so I want to select a different Title, again not from the current or last titles. I hope this is clear. All XML files have each item twice just to prevent search issues.

The selection works perfectly except it allows repeats of tracks. I try to prevent picking a duplicate "Title" but it's not working. (It's best to test on Rhinoblossom, it has the fewest tracks so repeats will happen quickly) - select "New" till a Rhinoblossoom track plays, then press 'More' Now press 'New' to look for duplicates...

Here is the function, it is triggered by clicking New or More: I thought this was correct, but pressing New still finds duplicate projects AND titles. I did not condense it down to avoid confusion - didn't help...
JavaScript:
                 function swapAlbum() {

                    var newProj = jwplayer(radio).getPlaylistItem().link;

                    newTitle == newProj.title;

                    if (((isAlbum == false) && (newProj == thisProj)) || thisTitle== prevTitle) || thisTitle== newTitle)) {

                            newProj = jwplayer(radio).playlistNext();

                            newTitle == newProj.title;

                    } else {

                          prevTitle = thisTitle;

                          thisTitle = newTitle;

                          prevProj = thisProj;

                          thisProj = newProj;

                    }

            }

Thanks in advance for your help.
Do you get any errors?
 
I have one error trap for typos in the "Description" field that weeds out bad matches, but the XML and HTML files are error rfree. IT's all in the one if clause. I rewrote it to see if it made it clearer, like this
JavaScript:
             function swapAlbum() {
                    var newProj = jwplayer(radio).getPlaylistItem().link;
                    newTitle == newProj.title;
                    trackCount = newProj.length;
/* the query */
                    if (((thisTitle == prevTitle) || (thisTitle == newTitle)) ||  ((isAlbum == false) && ((newProj == thisProj) || (newProj == prevProj))))
                    {
                            newProj = jwplayer(radio).playlistNext();
                            newTitle == newProj.title;
                    } else {
                          prevTitle = thisTitle;
                          thisTitle = newTitle;
                          prevProj = thisProj;
                          thisProj = newProj;
                    }
            }
Same issues.
 

Buy us a coffee!

Back
Top Bottom