2014년 12월 29일 월요일

How to read a file

I want to read a saved record as a file, but somehow it just wont work. The saved directory is "/storage/emulated/0/ My Documents/Recordings/NAME.3gp" but these all don't work:
  • Reading exact this directory
  • Reading this directory without the slash at the beginning
  • Reading this directory with a "file://" in front
  • Reading this directory with a "file://" in front and without the "/storage"
Does anyone know what I am doing wrong or cant you open files on the device memory?



you like to read the sound file with the Player component, correct?
does this snippet work for you? How to use the Sound Recorder

the correct path to your file is this:
file:///mnt/sdcard/My Documents/Recordings/NAME.3gp

note: file names are case sensitive!



Is that a blank I see before the word " My" ?



@Taifun, no I want to read it with the file component to change the name of the file by saving it again with a different name and deleting the old one.
@Abraham Getzler yes it is or is it actually a "_" (underscore), because both the File-Browser on my phone and a notification in App Inventor show it as space



as you can see from the documentation, http://ai2.appinventor.mit.edu/reference/components/storage.html#File
this should work

/My Documents/Recordings/NAME.3gp

of course underscores etc. must be considered
if you store the recorded sound file in a global variable, you only have to remove the leading /storage/emulated/0 to get the correct path for the file component

however I don't know, if you can read the sound file as text and store it again using another name, you can test this, just let us know what you find out ...



Reading a sound file as text would probably give just everything
up till its first hex zero byte.  Isn't that the universal text stopper?



Actually it seems like it got some of the "text" from the sound file but then the media player cannot read it, probably because there is some of the "text" missing from the sound file.
Do you know another way to rename or/and move a file?



you could send your file to a web server, see this examplehttps://puravidaapps.com/postfile.php and download it again using the web component and the GotFile event. The filename you can define in the ResponseFileName property, see also http://ai2.appinventor.mit.edu/reference/components/connectivity.html#Web



Well that is too complicated for what I want to use it for but still thank you to both of you :)


댓글 없음:

댓글 쓰기