android - Set AudioStreamType for an audio file played from Resource (raw folder) -
[first app] creating sort of alarm app allows user select alarm sound either sd-card or app-supplied sounds. since, app plays alarms, want volume 'alarm volume' of device. able accomplish sd card sounds. but, unable setaudiostreamtype
raw resource sounds.
i using next code :
mediaplayer m_player = new mediaplayer(); m_player.setaudiostreamtype(audiomanager.stream_alarm); switch (bin_name) { //bin_name = various user selectable music files default: m_player = mediaplayer.create(context, r.raw.blu); break; } m_player.setlooping(true); m_player.start();
my blu.mp3
plays @ media volume only. upon checking documentation mediaplayer.create(context context, int resid)
, found :
note since prepare() called automatically in method, cannot alter sound stream type (see setaudiostreamtype(int)), sound session id (see setaudiosessionid(int)) or sound attributes (see setaudioattributes(audioattributes) of new mediaplayer.
i tried finding code samples above method none of them showed how set audiostreamtype
audiomanager.steam_alarm
. take answers alternative ways play sound infinite loop. how accomplish ?
as documentation referring says, must create , prepare mediaplayer yourself. haven't tried stream_alarm i'm using next snippet play on stream_voice_call
uri uri = uri.parse("android.resource://com.example.app/" + r.raw.hdsweep); mediaplayer mmediaplayer = new mediaplayer(); mmediaplayer.setaudiostreamtype(audiomanager.stream_voice_call); mmediaplayer.setdatasource(context, uri); mmediaplayer.prepare(); mmediaplayer.start()
android android-mediaplayer android-audiomanager
No comments:
Post a Comment