RingtoneManager - choosing an MP3 a second time problem

MDEnt

Member
Licensed User
Longtime User
When using the ringtonemanager - like the example below - is there a way to check to see if the bounce.mp3 has already been added to the mediastore (without invoking ringtone picker)? I am setting the ringtone in the background from a list of possible MP3s, and what I notice is that the first time an MP3 is selected it works ok. If I choose the same MP3 from the list again - it raises a null pointer on the AddToMediaStore line.

B4X:
Dim r As RingtoneManager
Dim u As String
u = r.AddToMediaStore(File.DirRootExternal, "bounce.mp3", "Bounce!", True, True, True, True)
r.SetDefault(r.TYPE_RINGTONE, u)
 

MDEnt

Member
Licensed User
Longtime User
Strange thing is - I just tested a prior version of what I was doing and I don't get any error. Other than a different mp3 name - the code is the same. Perhaps I went wrong elsewhere in my app that is impacting this now - it always works the first time selecting an MP3 and not the second. Attached is the log.

Also, What do you mean by save the Uri in a file?

Thanks!
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Also, What do you mean by save the Uri in a file?
Why do you need to add the same ringtone again? You will just end up cluttering the ringtone list.

You should instead add it only on the first time your application runs and save the returned value in a file. Now you can read the Uri from the file and access the ringtone.
 
Upvote 0

MDEnt

Member
Licensed User
Longtime User
I don't want to add it a second time - but wanted to see what happened if a user clicked the same entry a second time.
 
Upvote 0

koaunglay

Member
Licensed User
Longtime User
You can use Try... Catch to catch this error.
Hi Erel
I've the same error.
When I use Try Catch it is not success for setdefault ringtone.
======This is Error Log=====

B4X:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
main_show_lis (java line: 597)
java.lang.NullPointerException
    at anywheresoftware.b4a.phone.RingtoneManagerWrapper.AddToMediaStore(RingtoneManagerWrapper.java:93)
    at b4a.example.main._show_lis(main.java:597)
    at b4a.example.main._img_longclick(main.java:485)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
    at anywheresoftware.b4a.objects.ViewWrapper$2.onLongClick(ViewWrapper.java:88)
    at android.view.View.performLongClick(View.java:4276)
    at android.view.View$CheckForLongPress.run(View.java:17731)
    at android.os.Handler.handleCallback(Handler.java:730)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5457)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:875)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:691)
    at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException

=======Please===
This is my lesson project. There is no two files ("2myatnaryuu.ogg", "3yinkaung.ogg"). I deleted because I can't upload
========Help me please
 

Attachments

  • tast.zip
    265.8 KB · Views: 352
Upvote 0

koaunglay

Member
Licensed User
Longtime User
Erel said:
Which error did you get before you add the Try / Catch block?
Please help Erel. I'm not well in English. So see my tast zip file. Or I'll upload error log when I use Laptop. Thanks anyway erel .
 
Upvote 0
Top