Page 1 of 1

Full path with OpenFileRequester()

Posted: Mon Oct 31, 2016 2:03 pm
by JohnJohnsonSHERMAN
Hi all!
I was just trying to create a (basic) music player to discover SB, but when I use the OpenFileRequester() function, it gives me only the name of the file by using both SelectedFileName() and SelectedFileID() :( ... The full path is never returned, eg. if I had a file located like this : D:/Data/music/mymusic.wav, I can only get the name (mymusic.wav), instead of the full path. How can I get the full path?

Re: Full path with OpenFileRequester()

Posted: Mon Oct 31, 2016 2:54 pm
by Fred
You can't get the full path as the browser doesn't have access to it.

Re: Full path with OpenFileRequester()

Posted: Mon Oct 31, 2016 4:16 pm
by JohnJohnsonSHERMAN
So, how applications like music converters or Google Drive file importer can upload files? Does it means that you've to read and copy the whole file in a known location (like "Data/somefiles.xxx") to be able, for example, to load a sound that the user selected in the OpenFileRequester?

Re: Full path with OpenFileRequester()

Posted: Tue Nov 01, 2016 6:27 am
by Fred
No, you can access the file once the user selected it, but you can't know the local path of it, only the filename.

Re: Full path with OpenFileRequester()

Posted: Tue Nov 01, 2016 11:43 am
by JohnJohnsonSHERMAN
It doesn't works for me :(

Code: Select all

;
InitSound()

Procedure Play()
  PlaySound(0)
EndProcedure

Procedure RequesterSuccess()
  
  ; Process all the selected filename
  ;
  While NextSelectedFile()
    Debug "Filename: " + SelectedFileName()
    LoadSound(0,SelectedFileID())
    Debug "Loading the sound..."
  Wend
EndProcedure

Procedure Open()
  OpenFileRequester("", @RequesterSuccess(), #PB_Requester_MultiSelection)
EndProcedure

Procedure Start()
  If OpenWindow(0, 0, 0, 200, 90, "Sound example", #PB_Window_TitleBar | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
    
    ButtonGadget(0, 10, 10, 180, 30, "Play")
    ButtonGadget(1, 10, 50, 180, 30, "Open")
    
    BindGadgetEvent(0, @Play())
    BindGadgetEvent(1, @Open())
  EndIf
EndProcedure


Procedure Loading(Type, Filename$, ObjectId)
  Static NbLoadedElements
  
  Debug Filename$ + " loaded (id = " + ObjectId + ")"
  
  NbLoadedElements+1
  If NbLoadedElements = 1 ; Finished the loading of all sounds, we can start the application
    If IsSound(0)
      Debug "Ok, sound loaded."
    Else
      Debug "Error !" ;This always happends...
    EndIf
    
    Start()
  EndIf
EndProcedure


Procedure LoadingError(Type, Filename$)
  Debug Filename$ + ": loading error"
EndProcedure


; Register the loading event before calling any resource load command
BindEvent(#PB_Event_Loading, @Loading())
BindEvent(#PB_Event_LoadingError, @LoadingError())

LoadSound(0, "Data/Lazer.wav")
When using this small code (from the documentation's examples), the lazer sound is correcly loaded and works fine, but when you try to open another sound, it fails... There is none error nor loading... It dont load anything...

Edit : In fact, it loads only sound files that are in the same directory as the sourcecode. And loads only one file before stopping working.