Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I dont know how to title this.....

Status
Not open for further replies.

LAwebTek

Programmer
Jan 23, 2003
13
US
I'm trying to do something a little unique and I'm sure it can be done because I'm already quite close. I'm trying to write a code that will first, look to see if the "continue" radio button is checked (that part works). Then it needs to check if the media's playState is == 1 (that part works, too). Here's where my code goes a little wacky -- I need it to advance to the next select option in the select list and play it after meeting the above conditions and auto select the option that is playing. My code does advance to and play the next song and even moves the selected focus to the item in the list, but afterward it just keeps playing the second item and doesn't continue down the list. Code is below, any thoughts??

//Continue() is called from "playSound()" which is
//called by the "play" button.

function Continue() {
if (document.cPlay.cButton[0].checked == true) {
playNext(); //if continuous play is checked, move on..
}
}

function playNext()
{
//playList is the form.select object
var playList = document.amp.playlist;
if (MediaPlayer.playState == 1) //if player is stopped
{
for(var i = 0; i < playList.options.length - 1; i++)
{
var next = playList.options.value;
MediaPlayer.URL = next; //song to play next
MediaPlayer.Controls.Play(); //Play current song
//make the current song the selected option
playList.options.selected = playList.options[i+1];
}
}
//if the playState
setTimeout('Continue()',1000);
}

Please help!
Thanks - LAwebTek
 
I dont know. Isnt playList.options.selected a boolean value? I mean it is either true or false.

And isnt playList.options[i+1] an object, a way to refer to option i+1?

If so what would it mean to assign an object to true or false?

Maybe you need to increment the selectedIndex by 1. And then select that option.
Code:
var iOld = playList.options.selectedIndex;
playList.options[iOld+1].selected = true;

I dont see why you would need to loop through the options but Im probably missing something.
 
Problem solved - here's what worked:

function playNext() {
if (MediaPlayer.playState == 1) { //if player is stopped
var playList = document.amp.playlist.options;
var i, len = playList.length;
for(i=0; i<len; i++) { // find current selection
if (playList.selected) break;
}
if (i<(len-1)) i++; // next selection
else i=0; // or start over
playList.selected = true; // select new selection
var next = playList.value; // extract new selection
MediaPlayer.URL = next; //song to play next
MediaPlayer.Controls.Play(); //Play current song
}
//if the playState is not 1 - keep checking..
setTimeout('Continue()',1000);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top