Import pool audio file

MrKim

Well-Known Member
Licensed User
Longtime User
Where is file added using the files tab?

Yes. Add the audio files to the Files tab and then use MediaPlayer (or SoundPool) to play the sounds.

For us :sign0104::sign0104: I added a .ogg file on the files tab, but I don't know where it is or how to access it once it is installed. It doesn't show up in the RTM. I have the files available in the ringtone manager playing just fine. what I would really like to do is add a couple of new files that show up in RTM and set one of them to be MY default when the app is installed.

I took a longer look at RTM and now see how to add it, but how do I know where it is? I have used the Eclipse file explorer and cannot for the life of me find the .ogg file I added using the files tab.

Thanks,
Kim
 
Upvote 0

manios

Active Member
Licensed User
Longtime User
You will find the files from the "files tab" in File.DirAssets!
As this directory is "private" to the app you will not be able to see it with a file explorer.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Manios, thanks for the quick reply. Any way to put it in the default media folder?
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Help with custonm sound.

Well, a little additional testing leaves me confused.
The following line confirms the file exists"

B4X:
Log("File Exists: " & File.Exists(File.DirAssets ,"myfile.ogg"))

So I run the next line:

B4X:
S=RTM.AddToMediaStore(File.DirAssets, "myfile.ogg", "Nag", True, True, True, False)

When I run the ringtonepicker "Nag" is indeed in the list, but it plays no sound while the others do.

If I try to play it with mediaplayer I get "FileNotFoundException" error.

This file plays fine in the windows media player once I downloaded the proper codec.

I tried the same with myfile.mp3 with the same result.

What am I mssing?

Thanks,
Kim
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Thaks for the quick responses guys.

Well, then this brings me around to why I am confused.

I didi it this way because the original post said,

"Yes. Add the audio files to the Files tab and then use MediaPlayer (or SoundPool) to play the sounds."

Now your telling me that won't work? If so, is there a way to add the files to the manifest so they will be installed in the appropriate directory during the install? I hate to add code to my project for a one time thing.

Thanks,
Kim
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Sorry for the confusion.

What I want to do is add a couple of ringtones which I will use as defaults, but I would like to add them in the appropriate directory and make them avaiable as choices for ringtones/notifications as well.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
I understand that. That is why what I was asking is, is there a way to have the files placed in exernal storage during my install, rather than having to copy them to external storage AFTER install?

While I was waiting for an answer to this and since this is all a bit of a learning excesize for me I decided to go ahead and copy the file to external stoage after install, but I am having some issues there as well.

the line:

B4X:
File.Copy(File.DirAssets, "clong.ogg", RTM.GetContentDir, "clong.ogg")

returns a java error "File or directory not found."

BUT the following code:

B4X:
   Msgbox( File.DirAssets,"")
   Dim Li As List, zzx As Int
   Li.Initialize
   Li=File.ListFiles(File.DirAssets)
   If Li.Size > 0 Then
      For  zzx=0 To Li.Size - 1
         Msgbox(Li.Get(zzx),"")
      Next
   End If

clearly shows the file clong.ogg IS in that directory. The one discepency I notice is: The first line of the code above lists File.DirAssets as "AssetsDir"

The actual android error from the copy line is:
java.io.FileNotFoundException: /ContentDir/clong.ogg (No such file or directory)

So it gives it a different name?

Any help is appreciated,
Kim
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
There is no way to automatically copy the files to the external storage during installation. You should check whether the files exist in the external storage and copy them when your app starts.

RTM.GetContentDir is a reference to a special virtual folder. You cannot copy files to this location. You should instead copy the files to:
B4X:
File.Combine(File.DirRootExternal, "Ringtones")
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
I figured out the virtual folder thing late last nightby playing around. Thanks so much for your help. As a windows database programmer for 25 years there is a LOT that is very different here. This brings up yet another can of snakes I am trying to get a handle on.

First of all, File.Combine as you show it does not jibe with the documentation. The documentaition says:

B4X:
Combine (Dir As String, FileName As String) As String
"Returns the full path to the given file.
This methods does not support files in the assets folder."

(Just realized I interpreted the Combine command incorrectly I thought it simply concantenated the path and file as that is frequently referred to as a fully qualified path in windows. As I now uderstand it, Combine is really a "find" command which returns the location of a file/directory?)

1. Your'e saying it also returns the path to a directory?
2. What if the file/directory doesn't exist? What is returned?
3. Newly created Android emulators do not appear to contain a ringtone directory. As a practical matter (my app is only for phones) can I count on the ringtone directory always being there or should I check and create it if necessary?

Thanks again,
Kim
 
Last edited:
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Sigh, it never ends. Using
B4X:
File.DirRootExternal

seems to work MOST of the time, however I am doing some testing and downloaded some skins. Tried to install on a Nexus-S emulator which has NO external SDcard (although it emulates one). The app installs and runs just fine, EXCEPT it won't create the directories and copy the file to the sdcard.

I get

B4X:
java.io.FileNotFoundException: /mnt/sdcard/Nag/Ringtones/clong.ogg (Permission denied)

error. On the Nexus-One emulator it works fine.

As an aside it does NOT fail on the code to create the directories but it doesn't create them either. It fails on the line to copy the file.

Here is the code with some debug lines. as mentioned it works fine so far except on Nexux-s emulation.
B4X:
   Msgbox ("Ext Dir " & File.DirRootExternal,"")
   If File.Exists(File.DirRootExternal, "Nag") = False Then File.MakeDir(File.DirRootExternal, "Nag")
   Log("1")
   If File.Exists(File.DirRootExternal & "/Nag", "ringtones") = False Then File.MakeDir(File.DirRootExternal & "/Nag", "Ringtones")
   B = False
   Log("2")
   If File.Exists(File.DirRootExternal & "/Nag/Ringtones", "clong.ogg") = False Then 
      File.Copy(File.DirAssets, "clong.ogg", File.DirRootExternal & "/Nag/Ringtones", "clong.ogg")
      B = True
   End If
   Log("3")
   If (File.Exists(File.DirRootExternal & "/Nag/Ringtones", "clong.ogg")) AND (B = True)  Then
      S =  RTM.AddToMediaStore(File.DirRootExternal & "/Nag/Ringtones", "clong.ogg", "Nag", True, True, True, False)
      NagMod.smgr.SetString("NagRingtone", S)
   Else
      NagMod.smgr.SetString("NagRingtone", RTM.GetDefault(RTM.TYPE_NOTIFICATION))
   End If

Any ideas greatly appreciated.
 
Last edited:
Upvote 0
Top