Jump to content

playSound with table problem


John Smith

Recommended Posts

i am trying to play a song which was selected in gridlist but failing in doing so

  
rowMusic = { 
"Ke$ha - We R Who We R", 
"Eric Saade - Popular", 
"Loreen - Euphoria" 
} 
  
-- some hidden code in here which isnt needed here 
  
function onPlayButtonClick() 
if not guiGridListGetSelectedItem(GUIEditor.gridlist[1]) then outputChatBox("You need to select a song!",255,0,0) end 
if source == GUIEditor.button[1] then 
   for i,mName in pairs(rowMusic) do 
       local theMusic = guiGridListGetItemText ( GUIEditor.gridlist[1], guiGridListGetSelectedItem ( GUIEditor.gridlist[1] ), 1 ) 
       if mName == theMusic then 
          if fileExists(theMusic) then 
           
             sound = playSound(theMusic) 
             guiSetText(GUIEditor.button[1],"Play") 
          else 
             downloadFile(theMusic) 
             outputChatBox("Please stand by while song you requested is downloading.",255,0,0) 
  
          end 
     end 
end 
end 
end 
addEventHandler("onClientGUIClick",root,onPlayButtonClick) 

theMusic (which i selected) was Ke$ha - We R Who We R and when i used outputDebugString to get that string

as wiki says filepath must be a string,but already is a string so why isn't it working?

or do i need to do something like this?

theMusic = """..theMusic..""" 
-- should(?) become "Ke$ha - We R Who We R" aka filepath 

Any help is appreaciated

Link to comment

Try;

local theMusic = guiGridListGetItemText ( GUIEditor.gridlist[1], guiGridListGetSelectedItem ( GUIEditor.gridlist[1] ), 1 )..".mp3" 
  

As the wiki mentioned, the filepath must be a string. But you're checking if the file "Ke$ha - We R Who We R" exists - not "Ke$ha - We R Who We R.mp3". It has to be a filepath. :)

It might be something else causing it, I may have overlooked it - didn't read through all of your code. Writing this from my phone :lol:

Edit:

I should have a link to a radio resource in my signature, which I made a while back, to stream URLs. You're free to download it and see if you find anything useful - it's open source as with all my releases. :)

Link to comment
  • 2 weeks later...

it has been a while since i posted a new post in here

now i got this code without any errors but music isn't playing though.

function onPlayButtonClick() 
if not guiGridListGetSelectedItem(GUIEditor.gridlist[1]) then outputChatBox("You need to select a song!",255,0,0) end 
if source == GUIEditor.button[1] then 
   for i,mName in pairs(rowMusic) do 
       local theMusic = guiGridListGetItemText ( GUIEditor.gridlist[1], guiGridListGetSelectedItem ( GUIEditor.gridlist[1] ), 1 ) 
       if mName == theMusic then 
          if fileExists(theMusic..".mp3") then 
             sound = playSound(theMusic..".mp3") 
             guiSetText(GUIEditor.button[1],"Play") 
          else 
             downloadFile(theMusic..".mp3") 
             outputDebugString(tostring(theMusic..".mp3")) 
             outputChatBox("Please stand by while song you requested is downloading.",255,0,0) 
             setElementData(localPlayer,"state","Downloading\n "..theMusic) 
             exports.loading:startLoading() 
          end 
     end 
end 
end 
end 
addEventHandler("onClientGUIClick",root,onPlayButtonClick) 

anybody knows what's the cause?

Link to comment
  • 2 weeks later...
  • Moderators
it starts downloading and onClientFileDownloadComplete or whatever says that download has failed, and it keeps restarting

Post the other part of the code, you said that the file is constantly in a re- download progress.

A file which get overwrite every time can't be played, since it is never complete.

Link to comment
function handleSongDownload(fname,state) 
if getElementType(source) == "resource" and getResourceName(getThisResource()) == "musicpanel" then 
   if state then 
      setElementData(localPlayer,"state","Music Download Finished. ") 
      outputDebugString("download finished "..tostring(state)) 
      setTimer(function() 
      exports.loading:stopLoading() 
      setElementData(localPlayer,"state","Playing") 
      end,5000,1) 
   else 
      downloadFile(fname) 
      outputDebugString("download failed of "..tostring(fname).." restarting...") 
      setElementData(localPlayer,"state","Trouble in Music Download.\nRestarting...") 
   end 
end 
end 
addEventHandler("onClientFileDownloadComplete",root,handleSongDownload) 

Link to comment

1.it just keeps returning that download has failed for forever

2.

"Ke$ha - We R Who We R.mp3" download="false" /> 
"Eric Saade - Popular.mp3" download="false" /> 
"Loreen - Euphoria.mp3" download="false" /> 

3.

-- originally when i click a button 
else 
-- if music file doesn't exist then 
downloadFile(tostring(theMusic)..".mp3") -- becomes a correct string wwith .mp3 on the end which becomes string filepath 
  
-- if file download fails, it activates this 
downloadFile(fname) -- filepath is fname 

Link to comment
  • Moderators

Well, try first to download one successful.

I will recommend you to remove those spaces between the file name and replace them with _

They always bring bad luck.

@ Gallardo9944

That way they can become corrupted and they will be corrupted when the download gets interrupted by a disconnect.

Link to comment

i have done some tests and confirmed that spaces are not the problem @iiyama

@gallardo excuse me but i dont want to use those function(s) i haven't yet used them and its harder than downloadFile and i just want to do it like this way because there isnt any reason why to complicate all this when it's easy with downloadFile

by "investigating" i have found no clue of this problem

in my server it would always fail to download(even when i have turned off all custom resource), even though some other resources like my custom downloader can download things perfectly fine.

So, my knowledge of mta and lua itself ends in here, and i am stuck without knowing what to do and how to fix the problem.

In my local server it downloads perfectly fine even if file has name fioefj32f o2f23.r.-2.,32,.-23.,4"#"&%$#$%#$.txt

and it has no custom resources

Link to comment

i have found out that it was a host problem about downloading files because some test examples didn't work (like easiest example of downloadFile), but still musicpanel isn't downloading anything properly, leaving files at 0 byte of size.

though my music panel still isn't downloading.

The only possible error i could have caught is this.

BASS ERROR 1 in LoadMedia path:C:\Program Files (x86)\MTA San Andreas 1.4\mods\deathmatch\resources\musicpanel\Eric Saade - Popular.mp3 3d:0 loop:

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...