I'm working on a sample code same as http://developer.android.com/guide/topics/media, I'm successfully playing the ringtone, but I want to know the length of the ringtone(in sec) or atleast a notification after end of the ringtone, so that i have to do some other task after playing the ringtone.
Thanks
nehatha
Put it in a MediaPlayer. You dont have to play it just .prepare() it. Then you can ask MediaPlayer about the duration.
Related
I am making a calling app and while the user is waiting for the call to connect, I want to play the default sound which is played when we call someone and wait for the correspondent to pick up.
You have to implement RingtoneManager for play default ringtone of system, have look
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
Ringtone ringtone = RingtoneManager.getRingtone(this,uri);
ringtone.play();
Hope it will help you!!
It is not possible as such.
You are talking about the ringing tone, also called ringback tone sometimes. It is not generated by the Android system, but the switching system, so you don't have access to it from the API.
To include that sound in your app, you have to include an asset for that sound (mp3).
I have an app that is open for hours and uses a background service with foreground notification attached to it. Every once in a while a sound is played using:
try {
Ringtone r = RingtoneManager.getRingtone(context, uri);
r.play();
} catch (Exception e) {
e.printStackTrace();
}
The sounds are working, but after a while the sounds don't play anymore.
No errors, no warnings, no crashes. Just no sound.
My users are complaining as well, so it doesn't look like a device specific issue.
Android Docs don't mention anything about this.
Anyone knows why this is?
Don't create a Ringtone or MediaPlayer in a BroadcastReceiver!
The problem was the context of the Ringtone or MediaPlayer. By triggering the sound form a broadcast receiver a new MediaPlayer or Ringtone was created every time the sound played. After 28 times, the sound just didn't play anymore.
By playing the sound from an IntentSerice, or re-useing a static instance of the MediaPlayer or Ringtone, everything played as expected.
In my app I have just built in a ringtone preference so that the user can select what type of sound they would like to receive when they get notifications, however the problem Im running into here is that the list that is presented gives both ringtone for phone calls and notification sounds for messengers etc, I want just the notification sounds for messengers, If a user selects a ringtone for a phone call my app could become very annoying very fast. Is there a way to filter the notification sounds from the ringtone sounds? I see other apps doing this but Im unable to find a way to do it online, any help would be massive thanks!
Filter the list by chossing only audio which is a notification sound. When you query for audio files, you would need to check it in the where clause that : MediaStore.Audio.AudioColumns.IS_NOTIFICATION is non-zero ( and all other fields such as IS_ALARM is zero). You will find more info about the table colums i am referring to here: http://developer.android.com/reference/android/provider/MediaStore.Audio.AudioColumns.html
Nevermind I figured it out, for ringtone type in the xml I had it set to all, I simply changed it to android:ringtoneType="notification" and that solved it, there also other ringtone types for alarm and all of that, hope this helps someone else who encounters the same problem!
I want to know how to get the ringtone,audio files in the device and I want set them as alarm. How to do it?
I am working in the code to set the alarm and I want to know how to retreive audio or ringtones from the device.
Read the docs on RingtoneManager and Ringtone
RingtoneManager
Ringtone
I am trying to build an Android Service that should get notified when the user starts playing an MP3. I checked LogCat when I start playing a song and saw that the following Intent is logged:
Intent { act=com.android.music.PLAYBACK_VIEWER flg=0x4000000 cmp=com.android.music/.MediaPlaybackActivity }
I couldn't figure out how to write an IntentFilter to let my Service know that this event has occurred and let me know the name of the song that will be played. I searched Android reference but could not find anything on PLAYBACK_VIEWER.
Thanks,
C
I would do neither. First, none of this is part of the SDK and so may change at any point. Second, this will only work for the built-in media player application, not any third-party or OEM-supplied media players, and I expect more people to gravitate to those.