Saturday, October 1, 2011

[android-developers] Re: Loading soundpool and music in activity A and calling in Activity B

You can store data to share between activities in an an object using
the singleton pattern.

Doug

On Sep 30, 7:22 pm, R S <music...@gmail.com> wrote:
> Hi!
>
> Right now I am loading my tiny music clips in the same class that I am using
> it in like this:
> ========================================================================
> public static final int A1 = 1;
>  public static final int A3 = 3;
> private SoundPool soundPool;
> private HashMap<Integer, Integer> soundPoolMap;
>  soundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 100);
>  soundPoolMap = new HashMap<Integer, Integer>();
>
> soundPoolMap.put(A1,soundPool.load(GameScreen_bugfix.this, R.raw.a, 1));
>  soundPoolMap.put(A3,soundPool.load(GameScreen_bugfix.this, R.raw.b, 1));
> //etc
>
> AudioManager mgr = (AudioManager)
> GameScreen_bugfix.this.getSystemService(Context.AUDIO_SERVICE);
> float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
>  float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
> float volume = streamVolumeCurrent / streamVolumeMax;
>
> try {
> soundPool.play(soundPoolMap.get(sound), volume, volume, 1, 0,
>  1f);} catch (Exception e) {
>
> e.printStackTrace();
>  }
> ========================================================================
>
> Can someone please tell me how I can load all the soundclips in Activity A,
> and then call them in Activity B?
>
> Thanks!
> Ryan

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment