Advertisement
enderpro100

Music launcher app

Apr 13th, 2023 (edited)
604
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.10 KB | Gaming | 0 0
  1. --- Program : Music launcher app
  2. --- Author : LightKnight51
  3. --- last modification : 18/04/2023
  4. --- (In editing ...)
  5.  
  6.  
  7. --- Utils API
  8. os.loadAPI("MarquitoLuaUtils")
  9.  
  10. -- Music launcher program
  11. function RunMusicLaunch()
  12.     local dfpwm = require("cc.audio.dfpwm")
  13.     -- Find the speaker
  14.     local speaker = MarquitoLuaUtils.FindSpeaker()
  15.  
  16.     print("Please enter a valid url for download an audio file")
  17.  
  18.     local audioUrl = nil
  19.     while audioUrl == nil do
  20.         audioUrl = tostring(read())
  21.     end
  22.    
  23.     local fileName = "MusicTest"
  24.  
  25.     MarquitoLuaUtils.DownloadAndGetAudioFile(audioUrl, fileName)
  26.     local decoder = dfpwm.make_decoder()
  27.     LaunchMusic(dfpwm, speaker, fileName)
  28. end
  29.  
  30. -- Launch new music
  31. function LaunchMusic(dfpwmLib, speaker, musicFileName)
  32.     local dfpwm = require("cc.audio.dfpwm")
  33.  
  34.     local decoder = dfpwm.make_decoder()
  35.     for chunk in io.lines("/data/audio/" .. musicFileName .. ".dfpwm", 16 * 1024) do
  36.         local buffer = decoder(chunk)
  37.        
  38.         while not speaker.playAudio(buffer) do
  39.             os.pullEvent("speaker_audio_empty")
  40.         end
  41.     end
  42.  
  43. end
  44.  
  45. RunMusicLaunch()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement