MP play other sounds

rfresh

Well-Known Member
Licensed User
Longtime User
I'm using the following code to play the ringtone using the media player. I'm adding an IF statement to play the Notifications sound but notifications doesn't work. I get a runtime error File Not Found Exception.

B4X:
Sub Play_Ringer
    Dim r As Reflector
    r.Target = "ContentDir"
    r.Target = r.RunMethod("intern")    
   If Main.pPhoneType = "NONE" Then
      mpp.Load(r.Target, "content://settings/system/notifications")
   Else
      mpp.Load(r.Target, "content://settings/system/ringtone")
   End If
    mpp.Play
End Sub
 

rfresh

Well-Known Member
Licensed User
Longtime User
Apparently not.

I saw this piece of code while searching for Notification playing examples. But this is for non-B4A Android. I wonder if this was converted to B4A if it would play the Notification sound?

B4X:
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();

I also tried these two lines (now remmed out) but they produced the same runtime error.

B4X:
Sub Play_Ringer
    Dim r As Reflector
    r.Target = "ContentDir"
    r.Target = r.RunMethod("intern")    
   If Main.pPhoneType = "NONE" Then
      'mpp.Load(r.Target, "content://settings/system/notification")
      'mpp.Load(r.Target, "my.package.name/raw/notification")      
   Else
      mpp.Load(r.Target, "content://settings/system/ringtone")
   End If
    mpp.Play
End Sub
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
I think there're wrong path. I play them well on my phone:

mp.Load(r.Target, "content://settings/system/ringtone")
mp.Load(r.Target, "content://settings/system/notification_sound")
mp.Load(r.Target, "content://settings/system/alarm_alert")
 
Upvote 0

Luiz Fernando Orlandini

Active Member
Licensed User
Longtime User
Apparently not.

I saw this piece of code while searching for Notification playing examples. But this is for non-B4A Android. I wonder if this was converted to B4A if it would play the Notification sound?

B4X:
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();

I also tried these two lines (now remmed out) but they produced the same runtime error.

B4X:
Sub Play_Ringer
    Dim r As Reflector
    r.Target = "ContentDir"
    r.Target = r.RunMethod("intern")   
   If Main.pPhoneType = "NONE" Then
      'mpp.Load(r.Target, "content://settings/system/notification")
      'mpp.Load(r.Target, "my.package.name/raw/notification")     
   Else
      mpp.Load(r.Target, "content://settings/system/ringtone")
   End If
    mpp.Play
End Sub

What kink of variable is mpp?

Thanks.
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Apparently not.

I saw this piece of code while searching for Notification playing examples. But this is for non-B4A Android. I wonder if this was converted to B4A if it would play the Notification sound?

B4X:
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();

I also tried these two lines (now remmed out) but they produced the same runtime error.

B4X:
Sub Play_Ringer
    Dim r As Reflector
    r.Target = "ContentDir"
    r.Target = r.RunMethod("intern")   
   If Main.pPhoneType = "NONE" Then
      'mpp.Load(r.Target, "content://settings/system/notification")
      'mpp.Load(r.Target, "my.package.name/raw/notification")     
   Else
      mpp.Load(r.Target, "content://settings/system/ringtone")
   End If
    mpp.Play
End Sub

What is Main.pPhoneType ??

Thank you
 
Upvote 0
Top