Android Question Default message sound

Discussion in 'Android Questions' started by francoisg, Jul 22, 2015.

  1. francoisg

    francoisg Active Member Licensed User

    I am using the following code to play a "message" ringtone.

    Sub makeNotificationsound
    ' ** Vibrate ...
    Dim pv As PhoneVibrate
    ' ** Play default authentication sound ...
    Dim mp As MediaPlayer
    ' ** Use ringtone manager to get default sound ...
    Dim rm As RingtoneManager
    mp.Load(rm.GetContentDir, rm.GetDefault(rm.TYPE_NOTIFICATION))
    End Sub

    After upgrading to Android 5.02, I get the following error: "Direct file access no longer supported; ringtone playback is available through"

    What is the proper way to play a default sound?
  2. Erel

    Erel Administrator Staff Member Licensed User

    Use this code instead (it will work on all versions):
    Sub Activity_Create(FirstTime As Boolean)
    Dim rm As RingtoneManager
    End Sub

    Sub PlayRingtone(url As String)
    Dim jo As JavaObject
    Dim jo2 As JavaObject
    Dim u As Uri
    "getRingtone"Array(jo2, u)).RunMethod("play"Null)
    End Sub
    Requires JavaObject and ContentResolver libraries.
    Jmu5667 and luke2012 like this.
  3. imbault

    imbault Well-Known Member Licensed User

    @Erel , thank you, that's interesting, can we play a sound stored in File.DirAssets with this method, because I use the play method in my notification routine
    like :
    mp.Load(File.DirAssets,cSoundFile)     'V1.09
  4. Erel

    Erel Administrator Staff Member Licensed User

    This method is only relevant for ringtones.

    You can use MediaPlayer to play files from the assets folder.
    imbault likes this.
  5. francoisg

    francoisg Active Member Licensed User

    Thank you Erel! I will update my code and test ...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice