Android Open Source - osu-taste-portable Sample Provider






From Project

Back to project page osu-taste-portable.

License

The source code is released under:

Apache License

If you think the Android project osu-taste-portable 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 com.dgsrz.osuTaste.services;
//from w ww .  j a v a2s.  c o m
import android.content.Context;
import android.content.res.AssetManager;
import android.util.Log;
import com.un4seen.bass.BASS;

import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;

/**
 * Created by: dgsrz
 * Date: 2014-02-01 19:41
 */
public class SampleProvider {

    private int channel;
    private int sample = 0;

    public SampleProvider(Context context, String fileName) {
        BASS.BASS_SampleFree(sample);
        AssetManager assetManager = context.getAssets();
        ByteBuffer buf = null;
        try {
            InputStream is = assetManager.open(fileName);
            buf = ByteBuffer.allocateDirect(is.available());
            int b;
            while ((b = is.read()) != -1) {
                buf.put((byte)b);
            }
        } catch (IOException ioe) {
        }

        sample = BASS.BASS_SampleLoad(buf, 0, buf.capacity(), 64, BASS.BASS_SAMPLE_OVER_POS);
        if (sample == 0) {
            Log.e("SAMPLE load failed", "Code: " + BASS.BASS_ErrorGetCode());
        }
    }

    public boolean play() {
        channel = BASS.BASS_SampleGetChannel(sample, false);
        if (sample != 0) {
            BASS.BASS_ChannelPlay(channel, false);
        }
        return true;
    }

    public float getVolume() {
        Float volume = 1.0f;
        BASS.BASS_ChannelGetAttribute(channel, BASS.BASS_ATTRIB_VOL, volume);
        return volume;
    }

    public void setVolume(float volume) {
        BASS.BASS_ChannelSetAttribute(channel, BASS.BASS_ATTRIB_VOL, volume);
    }

}




Java Source Code List

com.dgsrz.osuTaste.activities.BaseActivity.java
com.dgsrz.osuTaste.activities.HomeActivity.java
com.dgsrz.osuTaste.activities.SearchActivity.java
com.dgsrz.osuTaste.activities.SettingsActivity.java
com.dgsrz.osuTaste.activities.SplashActivity.java
com.dgsrz.osuTaste.adapters.PagerAdapter.java
com.dgsrz.osuTaste.beatmap.BeatmapParser.java
com.dgsrz.osuTaste.beatmap.HitObjectType.java
com.dgsrz.osuTaste.beatmap.HitObject.java
com.dgsrz.osuTaste.beatmap.InheritedTimingPoint.java
com.dgsrz.osuTaste.beatmap.TimingPoint.java
com.dgsrz.osuTaste.exception.BeatmapParsingException.java
com.dgsrz.osuTaste.fragments.AlbumFragment.java
com.dgsrz.osuTaste.loaders.BeatmapLoader.java
com.dgsrz.osuTaste.loaders.WrappedAsyncTaskLoader.java
com.dgsrz.osuTaste.model.Beatmap.java
com.dgsrz.osuTaste.provider.BeatmapStore.java
com.dgsrz.osuTaste.services.BassInterface.java
com.dgsrz.osuTaste.services.BassService.java
com.dgsrz.osuTaste.services.SampleProvider.java
com.dgsrz.osuTaste.services.StreamProvider.java
com.dgsrz.osuTaste.utils.ApplicationUtils.java
com.dgsrz.osuTaste.utils.Lists.java
com.dgsrz.osuTaste.utils.MusicUtils.java
com.dgsrz.osuTaste.utils.NavUtils.java
com.dgsrz.osuTaste.utils.PreferenceUtils.java
com.un4seen.bass.BASS.java