PDA

View Full Version : ComboBox and WMP Plugin


Gerri
10-10-2006, 01:36 PM
It's Alive!!! I've built my Frankenstein by piecing together bits and pieces of code from the samples others have so generously supplied here and my project works...sorta.

The ComboBox is populated with a table -- good there.
When selected in the ComboBox, the MP3 files play in the default player -- well okay.

But, I really want the MP3 files to play in the WMP plugin!!

Here's what I have so far. I'd be really grateful if someone could just get me past this one last hurdle.

On preload:

--populate a table with all the text files
MP3s = File.Find(_SourceFolder.."\\AutoPlay\\Audio", "*.mp3", false, false, nil);
zero = File.Find(_SourceFolder.."\\AutoPlay\\Audio", "*.mp3", false, false, nil);

On Show:

-- An if statement that compares two numbers
if zero = nil then
-- Do something here
else
--do the following for each file:
for j,file_path in MP3s do
--add the item to the combobox, with the name visible and path as data
ComboBox.AddItem("ComboBox1", String.SplitPath(file_path).Filename, file_path);

end
end

On Select:

-- Get the selected items
tSelected = ComboBox.GetSelected("ComboBox1");

if tSelected then
-- There is an item selected, get the data! (I know this part needs to change but I'm not quite sure how to change it)
sFiletoOpen = ComboBox.GetItemData("ComboBox1", tSelected);
File.Open(sFiletoOpen, "", SW_SHOWNORMAL);


else
-- Display an error message
Dialog.Message("Error", "There is no item selected.");
end

And, that's as far as I've gotten. Hope it's not too confusing.

Thanks in advance to whoever can give me a hand.

Gerri

TJ_Tigger
10-10-2006, 02:34 PM
Instead of doing a File.Open on the data returned from the combobox you can use the MediaPlayer.Load and MediaPlayer.Play

MediaPlayer.Load("MediaPlayer1", sFiletoOpen);
MediaPlayer.Play("MediaPlayer1");

HTH
Tigg

Gerri
10-10-2006, 05:33 PM
Many thanks for the help, Tigg.

That sure seems like the logical solution except that I have numerous MP3 files to select from and I'm not sure how to code my project so that when a title is selected it will play in WMP. BTW, that 'FilestoOpen' was from a previous project and it can go away as I am not using it in mine.

Populating the combobox with a table was my attempt at saving myself some work (I'm not sure if I got my wish) and now I'm stuck on how to GetItemData for a selected title since I'm not dealing with Line numbers?

Previously, when I used a combobox for a similar project, I manually entered the information into the Item Text and Item Data fields. I have the coding for that process but I don't know how to (if I even can) manipulate that code to work in this situation.

This scripting stuff befuddles me so well that I'm never sure if my explanations make sense. I hope this is understandable.

Thanks again,

Gerri

TJ_Tigger
10-11-2006, 07:46 AM
Gerri,

There are a lot of examples on the forums on ways to do what you are asking. My suggestion would be to run a Search for comboboxes and how to dynamically populate them. I would also suggest looking at azmanars site as there are a lot of examples on dynamically populating listboxes there.

The code you have looks good and seems to be a great start.

Tigg

Gerri
10-11-2006, 01:46 PM
Thanks so much for your help and encouragement, Tigg.

I did get my project to work and I am currently doing the Happy Dance around my office.

I appreciate this forum soooo much. I couldn't do it without you guys!

Thanks again!!

Gerri