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.mdground.screen.activity.MainActivity.java

private void initBaiduTTS() {
    System.loadLibrary("gnustl_shared");
    // ??BDSpeechDecoder_V1
    try {// ww w .  jav a 2  s.  c o m
        System.loadLibrary("BDSpeechDecoder_V1");
    } catch (UnsatisfiedLinkError e) {
        SpeechLogger.logD("load BDSpeechDecoder_V1 failed, ignore");
    }
    System.loadLibrary("bd_etts");
    System.loadLibrary("bds");

    speechSynthesizer = SpeechSynthesizer.newInstance(SpeechSynthesizer.SYNTHESIZER_AUTO,
            getApplicationContext(), "holder", this);
    // ???apikeysecretkey (?)
    speechSynthesizer.setApiKey("Dj4jyvL8cO8STPQ7PWY8YmHM", "a9ac5facd39ebfcab3b0bceb24606d90");
    // ???App ID (?)
    speechSynthesizer.setAppId("6691671");
    // ?LICENCE_FILE_NAME???license?[?]?????
    // speechSynthesizer.setParam(SpeechSynthesizer.PARAM_TTS_LICENCE_FILE,
    // LICENCE_FILE_NAME);
    // TTS????????
    String ttsTextModelFilePath = getApplicationContext().getApplicationInfo().dataDir
            + "/lib/libbd_etts_text.dat.so";
    String ttsSpeechModelFilePath = getApplicationContext().getApplicationInfo().dataDir
            + "/lib/libbd_etts_speech_female.dat.so";

    // ?
    speechSynthesizer.setParam(SpeechSynthesizer.PARAM_TTS_THREAD_PRIORITY, "1");
    speechSynthesizer.setParam(SpeechSynthesizer.PARAM_VOCODER_OPTIM_LEVEL, "0");
    speechSynthesizer.setParam(SpeechSynthesizer.PARAM_TTS_TEXT_MODEL_FILE, ttsTextModelFilePath);
    speechSynthesizer.setParam(SpeechSynthesizer.PARAM_TTS_SPEECH_MODEL_FILE, ttsSpeechModelFilePath);
    speechSynthesizer.setParam(SpeechSynthesizer.PARAM_VOLUME, "9");
    // speechSynthesizer.setParam(SpeechSynthesizer.PARAM_PITCH, "9");
    speechSynthesizer.setParam(SpeechSynthesizer.PARAM_SPEED, "3");

    DataInfoUtils.verifyDataFile(ttsTextModelFilePath);
    DataInfoUtils.getDataFileParam(ttsTextModelFilePath, DataInfoUtils.TTS_DATA_PARAM_DATE);
    DataInfoUtils.getDataFileParam(ttsTextModelFilePath, DataInfoUtils.TTS_DATA_PARAM_SPEAKER);
    DataInfoUtils.getDataFileParam(ttsTextModelFilePath, DataInfoUtils.TTS_DATA_PARAM_GENDER);
    DataInfoUtils.getDataFileParam(ttsTextModelFilePath, DataInfoUtils.TTS_DATA_PARAM_CATEGORY);
    DataInfoUtils.getDataFileParam(ttsTextModelFilePath, DataInfoUtils.TTS_DATA_PARAM_LANGUAGE);
    speechSynthesizer.initEngine();
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

}

From source file:dk.bearware.gui.MainActivity.java

@Override
protected void onResume() {
    super.onResume();

    if (audioIcons != null)
        audioIcons.release();/*from   ww  w  .jav  a  2s  .  c  om*/
    sounds.clear();

    audioIcons = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    audioManager.setMode(prefs.getBoolean(Preferences.PREF_SOUNDSYSTEM_VOICEPROCESSING, false)
            ? AudioManager.MODE_IN_COMMUNICATION
            : AudioManager.MODE_NORMAL);
    audioManager.setSpeakerphoneOn(prefs.getBoolean(Preferences.PREF_SOUNDSYSTEM_SPEAKERPHONE, false));

    if (prefs.getBoolean("server_lost_audio_icon", true)) {
        sounds.put(SOUND_SERVERLOST, audioIcons.load(getApplicationContext(), R.raw.serverlost, 1));
    }
    if (prefs.getBoolean("rx_tx_audio_icon", true)) {
        sounds.put(SOUND_VOICETXON, audioIcons.load(getApplicationContext(), R.raw.on, 1));
        sounds.put(SOUND_VOICETXOFF, audioIcons.load(getApplicationContext(), R.raw.off, 1));
    }
    if (prefs.getBoolean("personal_message_audio_icon", true)) {
        sounds.put(SOUND_USERMSG, audioIcons.load(getApplicationContext(), R.raw.user_message, 1));
    }
    if (prefs.getBoolean("channel_message_audio_icon", true)) {
        sounds.put(SOUND_CHANMSG, audioIcons.load(getApplicationContext(), R.raw.channel_message, 1));
    }
    if (prefs.getBoolean("broadcast_message_audio_icon", true)) {
        sounds.put(SOUND_BCASTMSG, audioIcons.load(getApplicationContext(), R.raw.channel_message, 1));
    }
    if (prefs.getBoolean("files_updated_audio_icon", true)) {
        sounds.put(SOUND_FILESUPDATE, audioIcons.load(getApplicationContext(), R.raw.fileupdate, 1));
    }
    if (prefs.getBoolean("voiceact_triggered_icon", true)) {
        sounds.put(SOUND_VOXON, audioIcons.load(getApplicationContext(), R.raw.voiceact_on, 1));
        sounds.put(SOUND_VOXOFF, audioIcons.load(getApplicationContext(), R.raw.voiceact_off, 1));
    }
    if (prefs.getBoolean("transmitready_icon", true)) {
        sounds.put(SOUND_TXREADY, audioIcons.load(getApplicationContext(), R.raw.txqueue_start, 1));
        sounds.put(SOUND_TXSTOP, audioIcons.load(getApplicationContext(), R.raw.txqueue_stop, 1));
    }
    if (prefs.getBoolean("userjoin_icon", true)) {
        sounds.put(SOUND_USERJOIN, audioIcons.load(getApplicationContext(), R.raw.user_join, 1));
    }
    if (prefs.getBoolean("userleft_icon", true)) {
        sounds.put(SOUND_USERLEFT, audioIcons.load(getApplicationContext(), R.raw.user_left, 1));
    }

    getTextMessagesAdapter().showLogMessages(prefs.getBoolean("show_log_messages", true));

    getWindow().getDecorView().setKeepScreenOn(prefs.getBoolean("keep_screen_on_checkbox", false));

    createStatusTimer();
}

From source file:com.telestax.restcomm_olympus.CallActivity.java

public void onDisconnected(RCConnection connection) {
    Log.i(TAG, "RCConnection disconnected");
    lblStatus.setText("Disconnected");

    btnMuteAudio.setVisibility(View.INVISIBLE);
    btnMuteVideo.setVisibility(View.INVISIBLE);

    this.connection = null;
    pendingConnection = null;/*from  www .  jav  a2s .c om*/
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    if (!pendingError) {
        finish();
    } else {
        pendingError = false;
    }
}

From source file:com.android.onemedia.playback.LocalRenderer.java

private void requestAudioFocus() {
    int result = mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
    mHasAudioFocus = result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED;
}

From source file:com.commontime.cordova.audio.AudioHandler.java

private void onFirstPlayerCreated() {
    origVolumeStream = cordova.getActivity().getVolumeControlStream();
    cordova.getActivity().setVolumeControlStream(AudioManager.STREAM_MUSIC);
}

From source file:com.trogdan.nanospotify.service.MusicService.java

void playSong(int index) {
    if (index > mTrackList.size() - 1)
        return;//from  ww w.  j  av a 2  s.co  m

    final ParcelableTrack track = mTrackList.get(mCurrentTrack);

    mState = State.Stopped;
    relaxResources(false); // release everything except MediaPlayer

    try {
        // set the source of the media player to a manual URL or path
        createMediaPlayerIfNeeded();
        mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mPlayer.setDataSource(mTrackList.get(index).getTrack().toString());

        mSongTitle = track.getTrackName();

        mState = State.Preparing;
        setUpAsForeground(mSongTitle + " (loading)");

        // 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!
        mPlayer.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. If, on the other hand,
        // we are *not* streaming, we want to release the lock if we were holding it before.
        mWifiLock.acquire();

        mNextTrack = mCurrentTrack + 1;

        startTimer();
    } catch (IOException ex) {
        Log.e("MusicService", "IOException playing next song: " + ex.getMessage());
        ex.printStackTrace();
    }
}

From source file:com.owncloud.android.media.MediaService.java

/**
 * Requests the audio focus to the Audio Manager 
 *//*from  w w  w.  ja  v  a 2s .  c  o m*/
private void tryToGetAudioFocus() {
    if (mAudioFocus != AudioFocus.FOCUS && mAudioManager != null
            && (AudioManager.AUDIOFOCUS_REQUEST_GRANTED == mAudioManager.requestAudioFocus(this,
                    AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN))) {
        mAudioFocus = AudioFocus.FOCUS;
    }
}

From source file:com.kaku.weac.fragment.AlarmClockOntimeFragment.java

@Override
public void onDestroy() {
    LogUtil.d(LOG_TAG, getActivity().toString() + "onDestroy");
    super.onDestroy();
    // ??/*from  w  w w .j  a v  a2  s . co m*/
    mIsRun = false;

    // ??????
    if (!mIsOnclick) {
        // ??
        nap();
    }

    // ??Activity
    if (WeacStatus.sActivityNumber <= 1) {
        // ?
        AudioPlayer.getInstance(getActivity()).stop();
    }

    // ?Activity?
    WeacStatus.sActivityNumber--;

    // If null, all callbacks and messages will be removed.
    if (mShowTimeHandler != null) {
        mShowTimeHandler.removeCallbacksAndMessages(null);
    }

    // ??
    mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mCurrentVolume, AudioManager.ADJUST_SAME);
}

From source file:com.shinymayhem.radiopresets.ServiceRadioPlayer.java

@SuppressLint("NewApi")
public void onPrepared(MediaPlayer mediaPlayer) {
    if (LOCAL_LOGV)
        log("onPrepared()", "v");
    if (mCurrentPlayerState.equals(ServiceRadioPlayer.STATE_RESTARTING)
            || mCurrentPlayerState.equals(ServiceRadioPlayer.STATE_COMPLETE)) {
        if (LOCAL_LOGD)
            log("newPlayer ready", "d");
    } else {//from   w w w.  j a va  2 s. co m
        int result = mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC,
                AudioManager.AUDIOFOCUS_GAIN);
        if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
            mAudioFocused = true;

            if (LOCAL_LOGV)
                log("mediaPlayer.start()", "v");
            mediaPlayer.start();
            mCurrentPlayerState = ServiceRadioPlayer.STATE_PLAYING;
            if (mInterrupted) {
                if (LOCAL_LOGV)
                    log("set interrupted = false", "v");
            }
            mInterrupted = false;

            //this.startForegroundNotification(getResources().getString(R.string.status_playing), getResources().getString(R.string.stop), true);
            this.updateNotification(getResources().getString(R.string.status_playing),
                    getResources().getString(R.string.stop), true);

            if (LOCAL_LOGV)
                log("start foreground notification: playing", "v");
            //Toast.makeText(this, "Playing", Toast.LENGTH_SHORT).show();
        } else if (result == AudioManager.AUDIOFOCUS_REQUEST_FAILED) {
            mAudioFocused = false;

            String title = getResources().getString(R.string.error_title);
            String text = getResources().getString(R.string.error_audio_focus);
            log(text, "w");
            this.getErrorNotification(title, text);
        }

    }
}

From source file:com.lybeat.lilyplayer.widget.media.IjkVideoView.java

@TargetApi(Build.VERSION_CODES.M)
private void openVideo() {
    if (mUri == null || mSurfaceHolder == null) {
        // not ready for playback just yet, will try again later
        return;/*from ww w .  ja v  a  2s  .c o m*/
    }
    // we shouldn't clear the target state, because somebody might have
    // called start() previously
    release(false);

    AudioManager am = (AudioManager) mAppContext.getSystemService(Context.AUDIO_SERVICE);
    am.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);

    try {
        mMediaPlayer = createPlayer(mSettings.getPlayer());

        // TODO: create SubtitleController in MediaPlayer, but we need
        // a context for the subtitle renderers
        final Context context = getContext();
        // REMOVED: SubtitleController

        // REMOVED: mAudioSession
        mMediaPlayer.setOnPreparedListener(mPreparedListener);
        mMediaPlayer.setOnVideoSizeChangedListener(mSizeChangedListener);
        mMediaPlayer.setOnCompletionListener(mCompletionListener);
        mMediaPlayer.setOnErrorListener(mErrorListener);
        mMediaPlayer.setOnInfoListener(mInfoListener);
        mMediaPlayer.setOnBufferingUpdateListener(mBufferingUpdateListener);
        mCurrentBufferPercentage = 0;
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            mMediaPlayer.setDataSource(mAppContext, mUri, mHeaders);
        } else {
            mMediaPlayer.setDataSource(mUri.toString());
        }
        bindSurfaceHolder(mMediaPlayer, mSurfaceHolder);
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mMediaPlayer.setScreenOnWhilePlaying(true);
        mMediaPlayer.prepareAsync();
        if (mHudViewHolder != null)
            mHudViewHolder.setMediaPlayer(mMediaPlayer);

        // REMOVED: mPendingSubtitleTracks

        // we don't set the target state here either, but preserve the
        // target state that was there before.
        mCurrentState = STATE_PREPARING;
        attachMediaController();
    } catch (IOException ex) {
        Log.w(TAG, "Unable to open content: " + mUri, ex);
        mCurrentState = STATE_ERROR;
        mTargetState = STATE_ERROR;
        mErrorListener.onError(mMediaPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
        return;
    } catch (IllegalArgumentException ex) {
        Log.w(TAG, "Unable to open content: " + mUri, ex);
        mCurrentState = STATE_ERROR;
        mTargetState = STATE_ERROR;
        mErrorListener.onError(mMediaPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
        return;
    } finally {
        // REMOVED: mPendingSubtitleTracks.clear();
    }
}