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.vanco.abplayer.BiliVideoViewActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    if (!io.vov.vitamio.LibsChecker.checkVitamioLibs(this))
        return;//from   w  w w. j  a v a 2 s.  c  o m

    vPlayerServiceConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            vPlayer = ((PlayerService.LocalBinder) service).getService();
            mServiceConnected = true;
            if (mSurfaceCreated)
                vPlayerHandler.sendEmptyMessage(OPEN_FILE);
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            vPlayer = null;
            mServiceConnected = false;
        }
    };

    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    parseIntent(getIntent());
    loadView(R.layout.activity_video);
    manageReceivers();

    findViews();

    mCreated = true;
    startText = startText + "??\n??...??\n...";
    startVideoInfo.setText(startText);
    new VideoViewInitTask().execute();
    //      AdPublic.addAd(BiliVideoViewActivity.this);
    // ?
    //    timer.schedule(task, 0, AdPublic.time);
}

From source file:com.studyjams.mdvideo.PlayerModule.PlayerActivity.java

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

    setContentView(R.layout.player_activity);
    View root = findViewById(R.id.root);
    root.setOnTouchListener(new OnTouchListener() {
        @Override//from   ww w .j a  v a  2s  .  c  om
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                toggleControlsVisibility();
            } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
                view.performClick();
            }
            return true;
        }
    });
    root.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE
                    || keyCode == KeyEvent.KEYCODE_MENU) {
                return false;
            }
            return mediaController.dispatchKeyEvent(event);
        }
    });

    shutterView = findViewById(R.id.shutter);
    //        debugRootView = findViewById(R.id.controls_root);

    videoFrame = (AspectRatioFrameLayout) findViewById(R.id.video_frame);
    surfaceView = (SurfaceView) findViewById(R.id.surface_view);
    surfaceView.getHolder().addCallback(this);
    //        debugTextView = (TextView) findViewById(R.id.debug_text_view);

    //        playerStateTextView = (TextView) findViewById(R.id.player_state_view);
    subtitleLayout = (SubtitleLayout) findViewById(R.id.subtitles);

    mediaController = new ExtractorMediaController(this);
    mediaController.setAnchorView(root);
    //        retryButton = (Button) findViewById(R.id.retry_button);
    //        retryButton.setOnClickListener(this);
    //        videoButton = (Button) findViewById(R.id.video_controls);
    //        audioButton = (Button) findViewById(R.id.audio_controls);
    //        textButton = (Button) findViewById(R.id.text_controls);

    //?mediaController??window
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    CookieHandler currentHandler = CookieHandler.getDefault();
    if (currentHandler != defaultCookieManager) {
        CookieHandler.setDefault(defaultCookieManager);
    }

    audioCapabilitiesReceiver = new AudioCapabilitiesReceiver(this, this);
    audioCapabilitiesReceiver.register();
}

From source file:nuclei.media.playback.FallbackPlayback.java

@Override
protected void internalPlay(MediaMetadata metadataCompat, Timing timing, boolean seek) {
    mPlayOnFocusGain = true;/*from  www  . j  a  v  a 2  s.com*/
    tryToGetAudioFocus();
    registerAudioNoisyReceiver();
    boolean mediaHasChanged = mCurrentMediaId == null
            || !TextUtils.equals(metadataCompat.getDescription().getMediaId(), mCurrentMediaId.toString());
    if (mediaHasChanged) {
        mCurrentPosition = getStartStreamPosition();
        mMetadata = metadataCompat;
        mCurrentMediaId = MediaProvider.getInstance().getMediaId(metadataCompat.getDescription().getMediaId());
    }

    if (mState == PlaybackStateCompat.STATE_PLAYING && !mediaHasChanged && mMediaPlayer != null
            && mMediaPlayer.isPlaying()) {
        if (mCallback != null) {
            mCallback.onPlaybackStatusChanged(mState);
        }
    } else if (mState == PlaybackStateCompat.STATE_PAUSED && !mediaHasChanged && mMediaPlayer != null) {
        configMediaPlayerState();
    } else {
        mState = PlaybackStateCompat.STATE_STOPPED;
        relaxResources(false); // release everything except MediaPlayer
        //noinspection ResourceType
        String source = metadataCompat.getString(MediaProvider.CUSTOM_METADATA_TRACK_SOURCE);

        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 (Exception ex) {
            if (mCallback != null) {
                mCallback.onError(ex, true);
            }
        }
    }

    if (timing != null && seek)
        internalSeekTo(timing.start);
}

From source file:com.baruckis.nanodegree.spotifystreamer.PlayerService.java

private void initMediaPlayer() {
    // Set mMediaPlayer properties
    mMediaPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    // Set listeners
    mMediaPlayer.setOnPreparedListener(this);
    mMediaPlayer.setOnCompletionListener(this);
    mMediaPlayer.setOnErrorListener(this);
}

From source file:com.andryr.musicplayer.PlaybackService.java

@Override
public void onCreate() {
    super.onCreate();
    mStatePrefs = getSharedPreferences(STATE_PREFS_NAME, MODE_PRIVATE);

    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    mMediaPlayer = new MediaPlayer();
    mMediaPlayer.setOnCompletionListener(this);
    mMediaPlayer.setOnErrorListener(this);
    mMediaPlayer.setOnPreparedListener(this);
    mMediaPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

    Intent i = new Intent(this, AudioEffectsReceiver.class);
    i.setAction(AudioEffectsReceiver.ACTION_OPEN_AUDIO_EFFECT_SESSION);
    i.putExtra(AudioEffectsReceiver.EXTRA_AUDIO_SESSION_ID, mMediaPlayer.getAudioSessionId());
    sendBroadcast(i);/*www. j a va 2 s  .c  om*/

    IntentFilter receiverFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
    registerReceiver(mHeadsetStateReceiver, receiverFilter);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    mAutoPause = prefs.getBoolean(PREF_AUTO_PAUSE, false);

    initTelephony();

    restoreState();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        setupMediaSession();
    }

}

From source file:fi.mikuz.boarder.gui.internet.InternetMenu.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.internet_menu);
    setTitle("Internet Menu");
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);

    mWaitDialog = new TimeoutProgressDialog(this, "Waiting for response", TAG, true);

    mInternetDownload = (Button) findViewById(R.id.internet_download);
    mInternetRegisterSettings = (Button) findViewById(R.id.internet_register_settings);
    mInternetLoginLogout = (Button) findViewById(R.id.internet_login_logout);
    mInternetUploads = (Button) findViewById(R.id.internet_uploads);
    mInternetFavorites = (Button) findViewById(R.id.internet_favorites);
    mAccountMessage = (TextView) findViewById(R.id.account_message_text);

    mDbHelper = new LoginDbAdapter(this);
    mDbHelper.open();//from   w  w w. j  av a 2  s  .c om

    mGlobalVariableDbHelper = new GlobalVariablesDbAdapter(this);
    mGlobalVariableDbHelper.open();
    int dbTosVersion = 0;
    try {
        Cursor variableCursor = mGlobalVariableDbHelper.fetchVariable(GlobalVariablesDbAdapter.TOS_VERSION_KEY);
        startManagingCursor(variableCursor);
        dbTosVersion = variableCursor.getInt(variableCursor.getColumnIndexOrThrow(LoginDbAdapter.KEY_DATA));
    } catch (SQLException e) {
        mGlobalVariableDbHelper.createIntVariable(GlobalVariablesDbAdapter.TOS_VERSION_KEY, 0);
        Log.d(TAG, "Couldn't get tosVersion", e);

    } catch (CursorIndexOutOfBoundsException e) {
        mGlobalVariableDbHelper.createIntVariable(GlobalVariablesDbAdapter.TOS_VERSION_KEY, 0);
        Log.d(TAG, "Couldn't get tosVersion", e);
    }

    if (dbTosVersion < mTosVersion) {
        AlertDialog.Builder builder = new AlertDialog.Builder(InternetMenu.this);
        builder.setTitle("Terms of service");
        builder.setMessage("Excited to get your hands on those sweet boards? - Good.\n\n"
                + "There are some terms you must agree to and follow to get things rolling smoothly;\n\n"
                + "You may only communicate in English in the Boarder Internet service.\n\n"
                + "An uploaded board may contain any languages. However, if the board is not 'in English' that must be visibly stated in the description.\n\n"
                + "You agree to always follow applicable laws when using Boarder.\n\n"
                + "Pornographic and other adult only material is not allowed.\n\n"
                + "You must be at least 13 years old to register to the Boarder Internet service.\n\n"
                + "You may never transmit anything or communicate a way that can be deemed offensive.\n\n"
                + "Don't make cheap copies of another users boards.\n\n"
                + "We can use material(s) publicly shared by you as promotional material.\n\n"
                + "We will suspend your Boarder releated accounts and/or remove your material from the Boarder service if you behave badly.");

        builder.setPositiveButton("Agree", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                mGlobalVariableDbHelper.updateIntVariable(GlobalVariablesDbAdapter.TOS_VERSION_KEY,
                        mTosVersion);
            }
        });

        builder.setNegativeButton("Disagree", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                InternetMenu.this.finish();
            }
        });

        builder.setCancelable(false);
        builder.show();
    }

    if (mLoginInfo == null) {
        try {
            String userId;
            String sessionToken;

            Cursor loginCursor = mDbHelper.fetchLogin(USER_ID_KEY);
            startManagingCursor(loginCursor);
            userId = loginCursor.getString(loginCursor.getColumnIndexOrThrow(LoginDbAdapter.KEY_DATA));

            loginCursor = mDbHelper.fetchLogin(SESSION_TOKEN_KEY);
            startManagingCursor(loginCursor);
            sessionToken = loginCursor.getString(loginCursor.getColumnIndexOrThrow(LoginDbAdapter.KEY_DATA));

            mLoginInfo = new HashMap<String, String>();
            mLoginInfo.put(USER_ID_KEY, userId);
            mLoginInfo.put(SESSION_TOKEN_KEY, sessionToken);
            sendDonationInfo();

            mSessionValidityChecked = false;
            checkSessionValidity();

        } catch (CursorIndexOutOfBoundsException e) {
            Log.d(TAG, "Couldn't get database session info", e);
            mSessionValidityChecked = true;
        }
    }

    getVersionInfo(); // Keep under login stuff

    mInternetDownload.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent i = new Intent(InternetMenu.this, DownloadBoardList.class);
            i.putExtra(LOGIN_KEY, mLoginInfo);
            startActivity(i);
        }
    });

    mInternetRegisterSettings.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (mInternetRegisterSettings.getText().toString().equals(SETTINGS_TEXT)) {
                Intent i = new Intent(InternetMenu.this, Settings.class);
                i.putExtra(LOGIN_KEY, mLoginInfo);
                startActivityForResult(i, LOGIN_RETURN);
            } else {
                Intent i = new Intent(InternetMenu.this, Register.class);
                startActivity(i);
            }
        }
    });

    mInternetLoginLogout.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            startLogin();
        }
    });

    mInternetUploads.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent i = new Intent(InternetMenu.this, Uploads.class);
            i.putExtra(LOGIN_KEY, mLoginInfo);
            startActivityForResult(i, LOGIN_RETURN);
        }
    });

    mInternetFavorites.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent i = new Intent(InternetMenu.this, Favorites.class);
            i.putExtra(LOGIN_KEY, mLoginInfo);
            startActivityForResult(i, LOGIN_RETURN);
        }
    });

}

From source file:hyplink.net.pot.GameActivity.java

private void playSound(int soundId) {
    if (soundEnabled) {
        float curVol = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
        float maxVol = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
        float vol = curVol / maxVol;
        soundPool.play(soundId, vol, vol, 0, 0, 1);
    }//  w w w .jav  a  2  s .c  o  m
}

From source file:com.stillnojetpacks.huffr.activities.MainActivity.java

@SuppressWarnings("deprecation")
private void buildBeforeAPI21() {
    soundPool = new SoundPool(PREF_SOUNDPOOL_MAX_STREAMS, AudioManager.STREAM_MUSIC, 0);
}

From source file:com.lithiumli.fiction.PlaybackService.java

private boolean acquireAudioFocus() {
    int result = getAudioManager().requestAudioFocus(this, AudioManager.STREAM_MUSIC,
            AudioManager.AUDIOFOCUS_GAIN);

    if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
        return true;
    }/*from   w w w.j  a va  2  s.c  om*/
    return false;
}

From source file:com.classiqo.nativeandroid_32bitz.playback.LocalPlayback.java

private void tryToGetAudioFocus() {
    LogHelper.d(TAG, "tryToGetAudioFocus");
    int result = mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);

    if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
        mAudioFocus = AUDIO_FOCUSED;/*from w w  w  .ja  v  a  2  s .  c o m*/
    } else {
        mAudioFocus = AUDIO_NO_FOCUS_NO_DUCK;
    }
}