Android Open Source - android-tools Sound Manager






From Project

Back to project page android-tools.

License

The source code is released under:

MIT License

If you think the Android project android-tools listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.comfreeze.lib.audio;
//w  w w  .  j  a v  a2 s  .c  om
import android.media.AudioManager;
import android.media.SoundPool;
import android.util.Log;

import net.comfreeze.lib.CFZApplication;

import java.util.HashMap;

public class SoundManager {
    private static final String TAG = SoundManager.class.getSimpleName();

    private static SoundManager instance;

    private final SoundPool pool;
    private final HashMap<Object, Integer> poolMap;
    private final AudioManager manager;
    private final CFZApplication application;

    public static boolean silent = false;

    public static int streamMax = 4;
    public static int streamType = AudioManager.STREAM_MUSIC;
    public static int streamQuality = 0;

    public SoundManager(CFZApplication application) {
        this.application = application;
        this.pool = new SoundPool(streamMax, streamType, streamQuality);
        this.poolMap = new HashMap<Object, Integer>();
        this.manager = CFZApplication.getAudioManager(application);
    }

    public static synchronized SoundManager instance(CFZApplication application) {
        if (null == instance) {
            if (!silent)
                Log.d(TAG, "Creating instance");
            instance = new SoundManager(application);
        }
        return instance;
    }

    public void addSound(Object name, int resourceId) {
        if (!silent)
            Log.d(TAG, "Adding sound");
        this.poolMap.put(name, this.pool.load(this.application, resourceId, 1));
    }

    public void playSound(Object name) {
        if (!silent)
            Log.d(TAG, "Playing sound: " + name);
        float streamVolume = manager.getStreamVolume(streamType);
        streamVolume = streamVolume / manager.getStreamMaxVolume(streamType);
        this.pool.play(this.poolMap.get(name), streamVolume, streamVolume, 1, 0, 1f);
    }

    public void playLoopedSound(Object name) {
        if (!silent)
            Log.d(TAG, "Playing looped sound: " + name);
        float streamVolume = manager.getStreamVolume(streamType);
        streamVolume = streamVolume / manager.getStreamMaxVolume(streamType);
        this.pool.play(this.poolMap.get(name), streamVolume, streamVolume, 1, -1, 1f);
    }
}




Java Source Code List

net.comfreeze.lib.BundleBuilder.java
net.comfreeze.lib.CFZApplication.java
net.comfreeze.lib.ContentValueBuilder.java
net.comfreeze.lib.FragmentMap.java
net.comfreeze.lib.adapter.HeaderListAdapter.java
net.comfreeze.lib.adapter.IHeaderListAdapter.java
net.comfreeze.lib.adapter.SeparatedListAdapter.java
net.comfreeze.lib.api.BaseAPI.java
net.comfreeze.lib.api.RestAPI.java
net.comfreeze.lib.api.XMLAPI.java
net.comfreeze.lib.api.helper.CursorHelper.java
net.comfreeze.lib.api.helper.JSONHelper.java
net.comfreeze.lib.api.helper.ModelHelper.java
net.comfreeze.lib.api.xml.WordpressAPI.java
net.comfreeze.lib.audio.SoundManager.java
net.comfreeze.lib.db.DatabaseHelper.java
net.comfreeze.lib.db.DatabaseTable.java
net.comfreeze.lib.db.helper.HelperCursor.java
net.comfreeze.lib.db.model.CFZModel.java
net.comfreeze.lib.db.model.FieldColumnMap.java
net.comfreeze.lib.fragments.CFZListFragment.java
net.comfreeze.lib.provider.CFZSimpleProvider.java
net.comfreeze.lib.service.CFZService.java
net.comfreeze.lib.ui.SupportFragmentActivity.java
net.comfreeze.lib.ui.dialog.CFZDialogProgress.java
net.comfreeze.lib.ui.fragment.CFZFragmentBase.java
net.comfreeze.lib.views.BiScrollView.java
net.comfreeze.lib.views.CFZViewHelper.java
net.comfreeze.lib.views.FlowLayout.java
net.comfreeze.lib.views.GestureHelper.java
net.comfreeze.lib.views.HeaderListView.java
net.comfreeze.lib.views.ResizingView.java
net.comfreeze.lib.views.ViewCollection.java
net.comfreeze.lib.views.ViewUtils.java
net.comfreeze.lib.xml.XMLParser.java
net.comfreeze.lib.xml.wordpress.FeedXmlParser.java