List of usage examples for android.media AudioManager STREAM_MUSIC
int STREAM_MUSIC
To view the source code for android.media AudioManager STREAM_MUSIC.
Click Source Link
From source file:org.botlibre.sdk.activity.MicConfiguration.java
private void setStreamVolume() { AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); int volume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC); if (volume != 0) { Log.d("ChatActivity", "The volume changed and saved to : " + volume); MainActivity.volume = volume;// w ww . j a v a 2s . c o m } }
From source file:com.phonegap.DroidGap.java
/** * Called when the activity is first created. * /*from w w w .j a va 2s. co m*/ * @param savedInstanceState */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); //getWindow().requestFeature(Window.FEATURE_NO_TITLE); //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN, // WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); // This builds the view. We could probably get away with NOT having a LinearLayout, but I like having a bucket! root = new LinearLayout(this); //Disable ScrollBar root.setVerticalScrollBarEnabled(false); root.setHorizontalScrollBarEnabled(false); root.setOrientation(LinearLayout.VERTICAL); root.setBackgroundColor(Color.BLACK); root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, 0.0F)); // If url was passed in to intent, then init webview, which will load the url Bundle bundle = this.getIntent().getExtras(); if (bundle != null) { String url = bundle.getString("url"); if (url != null) { this.init(); } } // Setup the hardware volume controls to handle volume control setVolumeControlStream(AudioManager.STREAM_MUSIC); }
From source file:org.mariotaku.harmony.activity.MusicPlaybackActivity.java
/** Called when the activity is first created. */ @Override/*from www . j a v a 2s .com*/ public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); mImageLoader = HarmonyApplication.getInstance(this).getImageLoaderWrapper(); mPreferences = new PreferencesEditor(this); mRefreshRunnable = new RefreshRunnable(this); mHideActionBarRunnable = new HideActionBarRunnable(this); setVolumeControlStream(AudioManager.STREAM_MUSIC); setContentView(R.layout.music_playback); mActionBar = getActionBar(); mActionBar.addOnMenuVisibilityListener(this); mActionBar.hide(); mSeekBar.setMax(1000); mSeekBar.setOnSeekBarChangeListener(this); mPlayPauseButton.setOnClickListener(this); mPrevButton.setOnClickListener(this); mNextButton.setOnClickListener(this); mPrevButton.setRepeatListener(this, 260); mNextButton.setRepeatListener(this, 260); mDeviceHasDpad = getResources().getConfiguration().navigation == Configuration.NAVIGATION_DPAD; mGestureDector = new GestureDetector(this, this); mPlaybackContainer.setTouchInterceptor(this); mAdapter = new PagerAdapter(this); mViewPager.setAdapter(mAdapter); mAdapter.addFragment(QueueFragment.class); mAdapter.addFragment(Fragment.class); mAdapter.addFragment(LyricsFragment.class); mViewPager.setOnPageChangeListener(this); mViewPager.setOffscreenPageLimit(3); mViewPager.setCurrentItem(1, false); }
From source file:com.cyanogenmod.eleven.ui.activities.SearchActivity.java
/** * {@inheritDoc}/*from w w w . j a va 2 s. com*/ */ @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPopupMenuHelper = new PopupMenuHelper(this, getSupportFragmentManager()) { private SearchResult mSelectedItem; @Override public PopupMenuType onPreparePopupMenu(int position) { mSelectedItem = mAdapter.getTItem(position); return PopupMenuType.SearchResult; } @Override protected long[] getIdList() { switch (mSelectedItem.mType) { case Artist: return MusicUtils.getSongListForArtist(SearchActivity.this, mSelectedItem.mId); case Album: return MusicUtils.getSongListForAlbum(SearchActivity.this, mSelectedItem.mId); case Song: return new long[] { mSelectedItem.mId }; case Playlist: return MusicUtils.getSongListForPlaylist(SearchActivity.this, mSelectedItem.mId); default: return null; } } @Override protected long getSourceId() { return mSelectedItem.mId; } @Override protected Config.IdType getSourceType() { return mSelectedItem.mType.getSourceType(); } @Override protected void updateMenuIds(PopupMenuType type, TreeSet<Integer> set) { super.updateMenuIds(type, set); if (mSelectedItem.mType == ResultType.Album) { set.add(FragmentMenuItems.MORE_BY_ARTIST); } } @Override protected String getArtistName() { return mSelectedItem.mArtist; } }; // Fade it in overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); // Control the media volume setVolumeControlStream(AudioManager.STREAM_MUSIC); // Bind Apollo's service mToken = MusicUtils.bindToService(this, this); // Set the layout setContentView(R.layout.activity_search); // get the input method manager mImm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // Initialize the adapter SummarySearchAdapter adapter = new SummarySearchAdapter(this); mAdapter = new SectionAdapter<SearchResult, SummarySearchAdapter>(this, adapter); // Set the prefix mAdapter.getUnderlyingAdapter().setPrefix(mFilterString); mAdapter.setupHeaderParameters(R.layout.list_search_header, false); mAdapter.setupFooterParameters(R.layout.list_search_footer, true); mAdapter.setPopupMenuClickedListener(new IPopupMenuCallback.IListener() { @Override public void onPopupMenuClicked(View v, int position) { mPopupMenuHelper.showPopupMenu(v, position); } }); mLoadingEmptyContainer = (LoadingEmptyContainer) findViewById(R.id.loading_empty_container); // setup the no results container NoResultsContainer noResults = mLoadingEmptyContainer.getNoResultsContainer(); noResults.setMainText(R.string.empty_search); noResults.setSecondaryText(R.string.empty_search_check); initListView(); // setup handler and runnable mHandler = new Handler(); mLoadingRunnable = new Runnable() { @Override public void run() { setState(VisibleState.Loading); } }; // Theme the action bar final ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); // Get the query String mFilterString = getIntent().getStringExtra(SearchManager.QUERY); // if we have a non-empty search string, this is a 2nd lvl search if (!TextUtils.isEmpty(mFilterString)) { mTopLevelSearch = false; // get the search type to filter by int type = getIntent().getIntExtra(SearchManager.SEARCH_MODE, -1); if (type >= 0 && type < ResultType.values().length) { mSearchType = ResultType.values()[type]; } int resourceId = 0; switch (mSearchType) { case Artist: resourceId = R.string.search_title_artists; break; case Album: resourceId = R.string.search_title_albums; break; case Playlist: resourceId = R.string.search_title_playlists; break; case Song: resourceId = R.string.search_title_songs; break; } actionBar.setTitle(getString(resourceId, mFilterString).toUpperCase()); actionBar.setDisplayHomeAsUpEnabled(true); // Set the prefix mAdapter.getUnderlyingAdapter().setPrefix(mFilterString); // Start the loader for the query getSupportLoaderManager().initLoader(SEARCH_LOADER, null, this); } else { mTopLevelSearch = true; mSearchHistoryCallback = new SearchHistoryCallback(); // Start the loader for the search history getSupportLoaderManager().initLoader(HISTORY_LOADER, null, mSearchHistoryCallback); } // set the background on the root view getWindow().getDecorView().getRootView() .setBackgroundColor(getResources().getColor(R.color.background_color)); }
From source file:com.ksharkapps.musicnow.ui.activities.AudioPlayerActivity.java
/** * {@inheritDoc}//from w w w. j ava 2 s . c o m */ @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (SettingsActivity.getTranslucentMode(this) && Utils.hasKitKat()) { setTheme(R.style.Apollo_Theme_Dark_Translucent); setTranslucentStatus(true); } // Set up the action bar actionBar = getSupportActionBar(); actionBar.setTitle(R.string.now_playing); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayUseLogoEnabled(false); // Sets fonts for all Typeface font = Typeface.createFromAsset(getAssets(), "RobotoThin.ttf"); ViewGroup root = (ViewGroup) findViewById(R.id.player_bg); // setFont(root, font); // Fade it in overridePendingTransition(R.anim.swipeup_in, R.anim.swipeup_out); // Control the media volume setVolumeControlStream(AudioManager.STREAM_MUSIC); // Bind Apollo's service mToken = MusicUtils.bindToService(this, this); // Initialize the image fetcher/cache mImageFetcher = ApolloUtils.getImageFetcher(this); // Initialize the handler used to update the current time mTimeHandler = new TimeHandler(this); // Initialize the broadcast receiver mPlaybackStatus = new PlaybackStatus(this); // Theme the action bar final ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); // Set the layout setContentView(R.layout.activity_player_base); // Cache all the items initPlaybackControls(); }
From source file:net.reichholf.dreamdroid.fragment.SignalFragment.java
void playSound(double freqOfTone) { double duration = 0.1; // seconds int sampleRate = 8000; // a number double dnumSamples = duration * sampleRate; dnumSamples = Math.ceil(dnumSamples); int numSamples = (int) dnumSamples; double sample[] = new double[numSamples]; byte generatedSnd[] = new byte[2 * numSamples]; for (int i = 0; i < numSamples; ++i) { // Fill the sample array sample[i] = Math.sin(freqOfTone * 2 * Math.PI * i / (sampleRate)); }//from ww w . ja va 2s .co m // convert to 16 bit pcm sound array // assumes the sample buffer is normalized. int idx = 0; int i = 0; int ramp = numSamples / 20; // Amplitude ramp as a percent of sample // count for (i = 0; i < numSamples; ++i) { // Ramp amplitude up (to avoid // clicks) if (i < ramp) { double dVal = sample[i]; // Ramp up to maximum final short val = (short) ((dVal * 32767 * i / ramp)); // in 16 bit wav PCM, first byte is the low order byte generatedSnd[idx++] = (byte) (val & 0x00ff); generatedSnd[idx++] = (byte) ((val & 0xff00) >>> 8); } else if (i < numSamples - ramp) { // Max amplitude for most of the samples double dVal = sample[i]; // scale to maximum amplitude final short val = (short) ((dVal * 32767)); // in 16 bit wav PCM, first byte is the low order byte generatedSnd[idx++] = (byte) (val & 0x00ff); generatedSnd[idx++] = (byte) ((val & 0xff00) >>> 8); } else { double dVal = sample[i]; // Ramp down to zero final short val = (short) ((dVal * 32767 * (numSamples - i) / ramp)); // in 16 bit wav PCM, first byte is the low order byte generatedSnd[idx++] = (byte) (val & 0x00ff); generatedSnd[idx++] = (byte) ((val & 0xff00) >>> 8); } } AudioTrack audioTrack = null; // Get audio track try { audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT, (int) numSamples * 2, AudioTrack.MODE_STATIC); // Load the track audioTrack.write(generatedSnd, 0, generatedSnd.length); audioTrack.play(); // Play the track } catch (Exception e) { } int x = 0; do { // Montior playback to find when done if (audioTrack != null) x = audioTrack.getPlaybackHeadPosition(); else x = numSamples; } while (x < numSamples); if (audioTrack != null) audioTrack.release(); // Track play done. Release track. }
From source file:com.allthatseries.RNAudioPlayer.Playback.java
/** * Try to get the system audio focus./*from w w w. j a v a 2s .co m*/ */ private void tryToGetAudioFocus() { int result = mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { mAudioFocus = AUDIO_FOCUSED; } else { mAudioFocus = AUDIO_NO_FOCUS_NO_DUCK; } }
From source file:com.darly.im.ui.CCPActivityBase.java
/** * * @return */ public int getStreamMaxVolume() { return mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); }
From source file:androidx.media.MediaSession2ImplBase.java
private PlaybackInfo createPlaybackInfo(VolumeProviderCompat volumeProvider, AudioAttributesCompat attrs) { PlaybackInfo info;//from ww w . ja v a 2 s . com if (volumeProvider == null) { int stream; if (attrs == null) { stream = AudioManager.STREAM_MUSIC; } else { stream = attrs.getVolumeControlStream(); if (stream == AudioManager.USE_DEFAULT_STREAM_TYPE) { // It may happen if the AudioAttributes doesn't have usage. // Change it to the STREAM_MUSIC because it's not supported by audio manager // for querying volume level. stream = AudioManager.STREAM_MUSIC; } } int controlType = VolumeProviderCompat.VOLUME_CONTROL_ABSOLUTE; if (Build.VERSION.SDK_INT >= 21 && mAudioManager.isVolumeFixed()) { controlType = VolumeProviderCompat.VOLUME_CONTROL_FIXED; } info = PlaybackInfo.createPlaybackInfo(PlaybackInfo.PLAYBACK_TYPE_LOCAL, attrs, controlType, mAudioManager.getStreamMaxVolume(stream), mAudioManager.getStreamVolume(stream)); } else { info = PlaybackInfo.createPlaybackInfo(PlaybackInfo.PLAYBACK_TYPE_REMOTE, attrs, volumeProvider.getVolumeControl(), volumeProvider.getMaxVolume(), volumeProvider.getCurrentVolume()); } return info; }
From source file:com.google.android.apps.santatracker.games.matching.MemoryMatchFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_memory_match, container, false); rootView.setKeepScreenOn(true);/*from ww w . java2 s.c o m*/ // Below ICS, display a special, simplified background for the entire fragment if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { rootView.findViewById(R.id.match_score_layout) .setBackgroundResource(R.drawable.score_background_gingerbread); } // Initialise the sound pool and all sound effects mSoundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0); mSoundDoorOpen = mSoundPool.load(getActivity(), R.raw.mmg_open_door_3, 1); mSoundDoorClose = mSoundPool.load(getActivity(), R.raw.mmg_close_door, 1); mSoundMatchWrong = mSoundPool.load(getActivity(), R.raw.mmg_wrong, 1); mSoundMatchRight = mSoundPool.load(getActivity(), R.raw.mmg_right, 1); mSoundGameOver = mSoundPool.load(getActivity(), R.raw.gameover, 1); mSoundBeep = mSoundPool.load(getActivity(), R.raw.mmg_open_door_2, 1); // Set up all animations. loadAnimations(); // G+ sign-in views mViewGPlusSignIn = (ImageView) rootView.findViewById(R.id.gplus_button); mViewGPlusSignIn.setOnClickListener(this); mLayoutGPlus = rootView.findViewById(R.id.play_again_gplus); mLayoutGPlus.setVisibility(View.GONE); // 'Play again' screen views mTextPlayAgainScore = (TextView) rootView.findViewById(R.id.play_again_score); mTextPlayAgainScore.setText(String.valueOf(mMatchScore)); mTextPlayAgainLevel = (TextView) rootView.findViewById(R.id.play_again_level); mTextPlayAgainLevel.setText(String.valueOf(mLevelNumber)); mViewPlayAgainBackground = rootView.findViewById(R.id.play_again_bkgrd); mViewPlayAgainMain = rootView.findViewById(R.id.play_again_main); mPlayAgainBtn = (Button) rootView.findViewById(R.id.play_again_btn); mPlayAgainBtn.setOnClickListener(this); // Level, countdown and score views at the bottom of the screen mTimerTextView = (TextView) rootView.findViewById(R.id.match_timer); mLevelNumberText = (LevelTextView) rootView.findViewById(R.id.card_end_level_number); mLevelNumberText.setVisibility(View.GONE); mScoreText = (TextView) rootView.findViewById(R.id.match_score); mScoreText.setText(String.valueOf(mMatchScore)); // End of level animated circle mEndLevelCircle = (CircleView) rootView.findViewById(R.id.card_end_level_circle); mEndLevelCircle.setVisibility(View.GONE); // The snowman that is animated as a bonus when the player is particularly awesome mViewBonusSnowman = rootView.findViewById(R.id.match_snowman); // 'Pause' screen views mButtonMenu = (ImageButton) rootView.findViewById(R.id.main_menu_button); mButtonMenu.setOnClickListener(this); mButtonMenu.setVisibility(View.GONE); mButtonPlay = (ImageView) rootView.findViewById(R.id.match_play_button); mButtonPlay.setOnClickListener(this); mButtonPlay.setVisibility(View.GONE); mButtonPause = (ImageView) rootView.findViewById(R.id.match_pause_button); mButtonPause.setOnClickListener(this); mButtonPause.setVisibility(View.VISIBLE); mViewPauseOverlay = rootView.findViewById(R.id.match_pause_overlay); mViewPauseOverlay.setVisibility(View.GONE); mButtonBigPlay = (ImageButton) rootView.findViewById(R.id.match_big_play_button); mButtonBigPlay.setOnClickListener(this); mButtonCancelBar = (ImageButton) rootView.findViewById(R.id.match_cancel_bar); mButtonCancelBar.setOnClickListener(this); mButtonCancelBar.setVisibility(View.GONE); // Playing cards (doors) mViewCard[0] = rootView.findViewById(R.id.card_position_1); mViewCard[1] = rootView.findViewById(R.id.card_position_2); mViewCard[2] = rootView.findViewById(R.id.card_position_3); mViewCard[3] = rootView.findViewById(R.id.card_position_4); mViewCard[4] = rootView.findViewById(R.id.card_position_5); mViewCard[5] = rootView.findViewById(R.id.card_position_6); mViewCard[6] = rootView.findViewById(R.id.card_position_7); mViewCard[7] = rootView.findViewById(R.id.card_position_8); mViewCard[8] = rootView.findViewById(R.id.card_position_9); mViewCard[9] = rootView.findViewById(R.id.card_position_10); mViewCard[10] = rootView.findViewById(R.id.card_position_11); mViewCard[11] = rootView.findViewById(R.id.card_position_12); // Display the instructions if they haven't been seen by the player yet. mPreferences = getActivity().getSharedPreferences(MatchingGameConstants.PREFERENCES_FILENAME, Context.MODE_PRIVATE); if (!mPreferences.getBoolean(MatchingGameConstants.MATCH_INSTRUCTIONS_VIEWED, false)) { // Instructions haven't been viewed yet. Construct an AnimationDrawable with instructions. mInstructionDrawable = new AnimationDrawable(); mInstructionDrawable.addFrame(getResources().getDrawable(R.drawable.instructions_touch_1), 300); mInstructionDrawable.addFrame(getResources().getDrawable(R.drawable.instructions_touch_2), 300); mInstructionDrawable.setOneShot(false); mViewInstructions = (ImageView) rootView.findViewById(R.id.instructions); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { mViewInstructions.setImageResource(R.drawable.instructions_touch_1); } else { mViewInstructions.setImageDrawable(mInstructionDrawable); mInstructionDrawable.start(); } // Set a timer to hide the instructions after 2 seconds mViewInstructions.postDelayed(new StartGameDelay(), 2000); } else { //Instructions have already been viewed. Start the first level. setUpLevel(); } return rootView; }