mrjoz
06-15-2006, 07:28 PM
Hi all, i hope this will be of use to a few ppl. What ive done is add/doctor examples to get what i believe is a dynamic audio player. but what i really want is to be able to call funtions from the Global Events so i dont have to put all this code on each and every page. As my project has multiple pages i feel that im wasting code and therefore resouces. So if anyone can workout how to make it Global it'll be even more productive to us all.
At Preload:
-- this gets the OGG files in the below folder and loads them into the listbox
atbFiles = File.Find("AutoPlay\\Audio\\music", "*.ogg", false, false, nil, nil);
TextFile.WriteFromTable("AutoPlay\\Audio\\music\\playlist.ini", atbFiles, false);
if atbFiles then
for i,v in atbFiles do
ListBox.AddItem("Music list", String.SplitPath(v).Filename, v);
end
end
audio = File.Find("AutoPlay\\Audio\\music", "*.ogg", false, false, nil, nil);
ListBox.SetVisible("Music list", false);
this gets the OGG Audio files from a folder and stores them in a table, while also writing the table to "playlist.ini" (this is because i am using multiple pages and it seems easier to call/clear a file). the last line of code also hides the listbox that the table is stored in (wasn't needed for me).
On show:
-- this gets the selected song and loads it.
ListBox.SelectItem("Music list", 1)
tbSelected = ListBox.GetSelected("Music list")
for index, item in tbSelected do
output = item;
end
if tbSelected then
strScript = ListBox.GetItemData("Music list", tbSelected[1]);
Audio.Load(CHANNEL_BACKGROUND, strScript, true, false)
end
-- Make sure the Load action was successful
if (Application.GetLastError() == 0) then
-- Check for file description tags
tags = Audio.GetOggTags(CHANNEL_BACKGROUND);
if (tags ~= nil) then
albumtitle = tags.TITLE;
artist = tags.ARTIST;
album = tags.ALBUM;
track = tags.TRACKNUMBER;
end
end
-- Update the status text display
Paragraph.SetText("track_title", albumtitle);
Paragraph.SetText("artist", artist);
Paragraph.SetText("current_ablum", album);
Paragraph.SetText("track_number", track);
this code selects the first Ogg track and starts playing it, while the latter code collects the OggTags and stores them in variables to be called on the paragraph objects displaying the Tag data
On audio:
-- This is to set up the next song when the one playing finishes.
--if you want more than 4 songs, just continue the code as below.
if e_State == "Finish" then
if output == 1 then
ListBox.SelectItem("Music list", 2)
strScript = ListBox.GetItemData("Music list", 2);
elseif output == 2 then
ListBox.SelectItem("Music list", 3)
strScript = ListBox.GetItemData("Music list", 3);
elseif output == 3 then
ListBox.SelectItem("Music list", 4)
strScript = ListBox.GetItemData("Music list", 4);
elseif output == 4 then
ListBox.SelectItem("Music list", 1)
strScript = ListBox.GetItemData("Music list", 1);
end
--this just gets the selected song and loads it.
tbSelected = ListBox.GetSelected("Music list")
for index, item in tbSelected do
output = item;
end
if tbSelected then
Audio.Load(CHANNEL_BACKGROUND, strScript, true, false)
end
end
tags = Audio.GetOggTags(CHANNEL_BACKGROUND);
if (tags ~= nil) then
albumtitle = tags.TITLE;
artist = tags.ARTIST;
album = tags.ALBUM;
track = tags.TRACKNUMBER;
end
-- Update the status text display
Paragraph.SetText("track_title", albumtitle);
Paragraph.SetText("artist", artist);
Paragraph.SetText("current_ablum", album);
Paragraph.SetText("track_number", track);
all the on audio code does is select the next track and play it after the current track finishes playing. oh, and it also updates the OggTags data which is displayed along side the listbox
On key:
-- e_Key is a built in variable that gets generated by the On Key event.
-- 13 is the virtual key code value for the [Enter] key.
if e_Key == 222 then
ListBox.SetVisible("Music list", true);
else
end
sets the listbox "music list" to visible on ---> # <--- key press
i have only been using this to troubleshoot and make sure the code is doing what i want it to do when i have no visial signs to work from.
On close
ListBox.DeleteItem("Music list", -1);
Code for listbox named "Music list"
tbSelected = ListBox.GetSelected("Music list")
for index, item in tbSelected do
output = item;
end
if tbSelected then
strScript = ListBox.GetItemData("Music list", tbSelected[1]);
Audio.Load(CHANNEL_BACKGROUND, strScript, true, false)
end
as i said, i use multiple pages. this code clears the listbox so when i jump page i dont get repeat items (tracks) in my now newly populated playlist
At Preload:
-- this gets the OGG files in the below folder and loads them into the listbox
atbFiles = File.Find("AutoPlay\\Audio\\music", "*.ogg", false, false, nil, nil);
TextFile.WriteFromTable("AutoPlay\\Audio\\music\\playlist.ini", atbFiles, false);
if atbFiles then
for i,v in atbFiles do
ListBox.AddItem("Music list", String.SplitPath(v).Filename, v);
end
end
audio = File.Find("AutoPlay\\Audio\\music", "*.ogg", false, false, nil, nil);
ListBox.SetVisible("Music list", false);
this gets the OGG Audio files from a folder and stores them in a table, while also writing the table to "playlist.ini" (this is because i am using multiple pages and it seems easier to call/clear a file). the last line of code also hides the listbox that the table is stored in (wasn't needed for me).
On show:
-- this gets the selected song and loads it.
ListBox.SelectItem("Music list", 1)
tbSelected = ListBox.GetSelected("Music list")
for index, item in tbSelected do
output = item;
end
if tbSelected then
strScript = ListBox.GetItemData("Music list", tbSelected[1]);
Audio.Load(CHANNEL_BACKGROUND, strScript, true, false)
end
-- Make sure the Load action was successful
if (Application.GetLastError() == 0) then
-- Check for file description tags
tags = Audio.GetOggTags(CHANNEL_BACKGROUND);
if (tags ~= nil) then
albumtitle = tags.TITLE;
artist = tags.ARTIST;
album = tags.ALBUM;
track = tags.TRACKNUMBER;
end
end
-- Update the status text display
Paragraph.SetText("track_title", albumtitle);
Paragraph.SetText("artist", artist);
Paragraph.SetText("current_ablum", album);
Paragraph.SetText("track_number", track);
this code selects the first Ogg track and starts playing it, while the latter code collects the OggTags and stores them in variables to be called on the paragraph objects displaying the Tag data
On audio:
-- This is to set up the next song when the one playing finishes.
--if you want more than 4 songs, just continue the code as below.
if e_State == "Finish" then
if output == 1 then
ListBox.SelectItem("Music list", 2)
strScript = ListBox.GetItemData("Music list", 2);
elseif output == 2 then
ListBox.SelectItem("Music list", 3)
strScript = ListBox.GetItemData("Music list", 3);
elseif output == 3 then
ListBox.SelectItem("Music list", 4)
strScript = ListBox.GetItemData("Music list", 4);
elseif output == 4 then
ListBox.SelectItem("Music list", 1)
strScript = ListBox.GetItemData("Music list", 1);
end
--this just gets the selected song and loads it.
tbSelected = ListBox.GetSelected("Music list")
for index, item in tbSelected do
output = item;
end
if tbSelected then
Audio.Load(CHANNEL_BACKGROUND, strScript, true, false)
end
end
tags = Audio.GetOggTags(CHANNEL_BACKGROUND);
if (tags ~= nil) then
albumtitle = tags.TITLE;
artist = tags.ARTIST;
album = tags.ALBUM;
track = tags.TRACKNUMBER;
end
-- Update the status text display
Paragraph.SetText("track_title", albumtitle);
Paragraph.SetText("artist", artist);
Paragraph.SetText("current_ablum", album);
Paragraph.SetText("track_number", track);
all the on audio code does is select the next track and play it after the current track finishes playing. oh, and it also updates the OggTags data which is displayed along side the listbox
On key:
-- e_Key is a built in variable that gets generated by the On Key event.
-- 13 is the virtual key code value for the [Enter] key.
if e_Key == 222 then
ListBox.SetVisible("Music list", true);
else
end
sets the listbox "music list" to visible on ---> # <--- key press
i have only been using this to troubleshoot and make sure the code is doing what i want it to do when i have no visial signs to work from.
On close
ListBox.DeleteItem("Music list", -1);
Code for listbox named "Music list"
tbSelected = ListBox.GetSelected("Music list")
for index, item in tbSelected do
output = item;
end
if tbSelected then
strScript = ListBox.GetItemData("Music list", tbSelected[1]);
Audio.Load(CHANNEL_BACKGROUND, strScript, true, false)
end
as i said, i use multiple pages. this code clears the listbox so when i jump page i dont get repeat items (tracks) in my now newly populated playlist