Example usage for android.media AudioManager STREAM_MUSIC

List of usage examples for android.media AudioManager STREAM_MUSIC

Introduction

In this page you can find the example usage for android.media AudioManager STREAM_MUSIC.

Prototype

int STREAM_MUSIC

To view the source code for android.media AudioManager STREAM_MUSIC.

Click Source Link

Document

Used to identify the volume of audio streams for music playback

Usage

From source file:com.intel.xdk.notification.Notification.java

public void beep(int count) {
    beepCount = (count > 0) ? count - 1 : 0;
    AudioManager mgr = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
    final int streamVolume = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
    soundPool.play(SOUND_BEEP, streamVolume, streamVolume, 1, beepCount, 1f);
}

From source file:com.example.android.uamp.playback.LocalPlayback.java

@Override
public void play(QueueItem item) {
    mPlayOnFocusGain = true;/*from  w  w w  .j  a  v  a2 s  .  c  om*/
    tryToGetAudioFocus();
    registerAudioNoisyReceiver();
    String mediaId = item.getDescription().getMediaId();
    boolean mediaHasChanged = !TextUtils.equals(mediaId, mCurrentMediaId);
    if (mediaHasChanged) {
        mCurrentPosition = 0;
        mCurrentMediaId = mediaId;
    }

    if (mState == PlaybackStateCompat.STATE_PAUSED && !mediaHasChanged && mMediaPlayer != null) {
        configMediaPlayerState();
    } else {
        mState = PlaybackStateCompat.STATE_STOPPED;
        relaxResources(false); // release everything except MediaPlayer
        MediaMetadataCompat track = mMusicProvider
                .getMusic(MediaIDHelper.extractMusicIDFromMediaID(item.getDescription().getMediaId()));

        //noinspection ResourceType
        String source = track.getString(MusicProviderSource.CUSTOM_METADATA_TRACK_SOURCE);
        if (source != null) {
            source = source.replaceAll(" ", "%20"); // Escape spaces for URLs
        }

        try {
            createMediaPlayerIfNeeded();

            mState = PlaybackStateCompat.STATE_BUFFERING;

            mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            mMediaPlayer.setDataSource(source);

            // Starts preparing the media player in the background. When
            // it's done, it will call our OnPreparedListener (that is,
            // the onPrepared() method on this class, since we set the
            // listener to 'this'). Until the media player is prepared,
            // we *cannot* call start() on it!
            mMediaPlayer.prepareAsync();

            // If we are streaming from the internet, we want to hold a
            // Wifi lock, which prevents the Wifi radio from going to
            // sleep while the song is playing.
            mWifiLock.acquire();

            if (mCallback != null) {
                mCallback.onPlaybackStatusChanged(mState);
            }

        } catch (IOException ex) {
            LogHelper.e(TAG, ex, "Exception playing song");
            if (mCallback != null) {
                mCallback.onError(ex.getMessage());
            }
        }
    }
}

From source file:com.custom.music.MusicBrowserActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i(TAG, ">>> onCreate", Log.APP);
    setContentView(R.layout.main);//ww w  .  j  av  a  2s.c o m
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    mToken = MusicUtils.bindToService(this, this);
    mHasMenukey = ViewConfiguration.get(this).hasPermanentMenuKey();
    mActivityManager = new LocalActivityManager(this, false);
    mActivityManager.dispatchCreate(savedInstanceState);

    mTabHost = getTabHost();
    initTab();
    mCurrentTab = MusicUtils.getIntPref(this, SAVE_TAB, ARTIST_INDEX);
    Log.i(TAG, "onCreate mCurrentTab: " + mCurrentTab, Log.APP);
    if ((mCurrentTab < 0) || (mCurrentTab >= mTabCount)) {
        mCurrentTab = ARTIST_INDEX;
    }
    /// M: reset the defalt tab value
    if (mCurrentTab == ARTIST_INDEX) {
        mTabHost.setCurrentTab(ALBUM_INDEX);
    }
    mTabHost.setOnTabChangedListener(this);

    initPager();
    mViewPager = (ViewPager) findViewById(R.id.viewpage);
    mViewPager.setAdapter(new MusicPagerAdapter());
    mViewPager.setOnPageChangeListener(this);

    //add by zjw
    categories = (TextView) findViewById(R.id.categorisetab);
    categories.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            showPupopMenu(categories);
        }
    });

    IntentFilter f = new IntentFilter();
    f.addAction(MusicUtils.SDCARD_STATUS_UPDATE);
    registerReceiver(mSdcardstatustListener, f);

    createFakeMenu();

    /// M: Init search button click listener in nowplaying.
    //        initSearchButton();

    Log.i(TAG, "onCreate >>>", Log.APP);
}

From source file:com.watabou.noosa.Game.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Context context = getApplicationContext();
    StringsManager.setContext(context);/*  w ww  . j a v a  2  s.co m*/

    if (!BuildConfig.DEBUG) {
        EventCollector.logEvent("apk signature", Util.getSignature(this));
    }

    FileSystem.setContext(context);
    ModdingMode.setContext(context);

    try {
        version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
        versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
    } catch (NameNotFoundException e) {
        version = "???";
        versionCode = 0;
    }

    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    view = new GLSurfaceView(this);
    view.setEGLContextClientVersion(2);

    // Hope this allow game work on broader devices list
    // view.setEGLConfigChooser( false );
    view.setRenderer(this);
    view.setOnTouchListener(this);

    layout = new LinearLayout(this);
    getLayout().setOrientation(LinearLayout.VERTICAL);
    getLayout().addView(view);

    setContentView(getLayout());
}

From source file:leoisasmendi.android.com.suricatepodcast.services.MediaPlayerService.java

private void initMediaPlayer() {
    mediaPlayer = new MediaPlayer();
    //Set up MediaPlayer event listeners
    mediaPlayer.setOnCompletionListener(this);
    mediaPlayer.setOnErrorListener(this);
    mediaPlayer.setOnPreparedListener(this);
    mediaPlayer.setOnBufferingUpdateListener(this);
    mediaPlayer.setOnSeekCompleteListener(this);
    mediaPlayer.setOnInfoListener(this);
    //Reset so that the MediaPlayer is not pointing to another data source
    mediaPlayer.reset();/*from w ww .  j a v  a2 s .  co  m*/

    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    try {
        publishStatus(STATUS_FETCHING);
        // Set the data source to the mediaFile location
        mediaPlayer.setDataSource(activeAudio.getAudio());
        mediaPlayer.prepareAsync();
    } catch (Exception e) {
        e.printStackTrace();
        publishStatus(STATUS_ERROR);
        stopSelf();
        Log.d(TAG, "initMediaPlayer: " + R.string.media_player_error_1);
    }
}

From source file:nth.com.ares.utils.Utils.java

public static void playSound(Context context, int sound) {
    AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    int currentVolume = audio.getStreamVolume(AudioManager.STREAM_MUSIC);
    int maxVolume = audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    float percent = 0.7f;
    int seventyVolume = (int) (maxVolume * percent);
    audio.setStreamVolume(AudioManager.STREAM_MUSIC, seventyVolume, 0);
    final MediaPlayer mp = MediaPlayer.create(context, sound);
    mp.start();// w  w w .j av a2 s . c  om
}

From source file:org.chromium.latency.walt.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Thread.setDefaultUncaughtExceptionHandler(new LoggingExceptionHandler());
    setContentView(R.layout.activity_main);

    // App bar//from w  ww .j  a  va 2  s . co  m
    toolbar = (Toolbar) findViewById(R.id.toolbar_main);
    setSupportActionBar(toolbar);
    getSupportFragmentManager().addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
        @Override
        public void onBackStackChanged() {
            int stackTopIndex = getSupportFragmentManager().getBackStackEntryCount() - 1;
            if (stackTopIndex >= 0) {
                toolbar.setTitle(getSupportFragmentManager().getBackStackEntryAt(stackTopIndex).getName());
            } else {
                toolbar.setTitle(R.string.app_name);
                getSupportActionBar().setDisplayHomeAsUpEnabled(false);
                // Disable fullscreen mode
                getSupportActionBar().show();
                getWindow().getDecorView().setSystemUiVisibility(0);
            }
        }
    });

    waltDevice = WaltDevice.getInstance(this);

    // Create front page fragment
    FrontPageFragment frontPageFragment = new FrontPageFragment();
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.add(R.id.fragment_container, frontPageFragment);
    transaction.commit();

    logger = SimpleLogger.getInstance(this);
    broadcastManager = LocalBroadcastManager.getInstance(this);

    // Add basic version and device info to the log
    logger.log(String.format("WALT v%s  (versionCode=%d)", BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE));
    logger.log("WALT protocol version " + WaltDevice.PROTOCOL_VERSION);
    logger.log("DEVICE INFO:");
    logger.log("  " + Build.FINGERPRINT);
    logger.log("  Build.SDK_INT=" + Build.VERSION.SDK_INT);
    logger.log("  os.version=" + System.getProperty("os.version"));

    // Set volume buttons to control media volume
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    requestSystraceWritePermission();
    // Allow network operations on the main thread
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
}

From source file:ar.com.martineo14.spotifystreamer2.ui.fragment.TrackPlayerActivityFragment.java

public void createMediaPlayer() {
    mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
}

From source file:fr.shywim.antoinedaniel.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Crashlytics not initialized, only safe code
    mContext = this;

    Fabric.with(this, new Crashlytics());
    Crashlytics.setUserIdentifier(Installation.id(this));

    // Crashlytics initialized, can start doing "unsafe" code
    AnalyticsUtils.initAnalyticsTracker(getApplicationContext());
    mHandler = new Handler();
    mAppContext = this.getApplicationContext();
    utils = Utils.getInstance();/*from w w w  .j a  v  a  2s . c o m*/
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    setContentView(R.layout.activity_main);

    Intent intent = getIntent();
    if (SearchIntents.ACTION_SEARCH.equals(intent.getAction())) {
        searchQuery = intent.getStringExtra(SearchManager.QUERY);
    }

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeButtonEnabled(true);
    }

    attachTaskFragment();

    appState = AppState.getInstance();
    appState.load(this);
}

From source file:com.squalala.talkiewalkie.ui.activities.TalkActivity.java

@Override
public void onHideFragment() {
    amanager.setStreamVolume(AudioManager.STREAM_MUSIC, session.getSoundVolume(amanager), 0);
    blanketView.setVisibility(View.GONE);
}