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:de.qspool.clementineremote.backend.ClementinePlayerConnection.java
/** * Register the RemoteControlClient/*from w w w . j a v a2 s .c o m*/ */ private void registerRemoteControlClient() { // Request AudioFocus, so the widget is shown on the lock-screen mAudioManager.requestAudioFocus(mOnAudioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); mAudioManager.registerMediaButtonEventReceiver(mClementineMediaButtonEventReceiver); // Create the intent Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(mClementineMediaButtonEventReceiver); PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(App.mApp.getApplicationContext(), 0, mediaButtonIntent, 0); // Create the client mRcClient = new RemoteControlClient(mediaPendingIntent); if (App.mClementine.getState() == Clementine.State.PLAY) { mRcClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); } else { mRcClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED); } mRcClient.setTransportControlFlags( RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE); mAudioManager.registerRemoteControlClient(mRcClient); }
From source file:com.rks.musicx.ui.fragments.PlayingViews.Playing1Fragment.java
@Override protected void function() { ateKey = Helper.getATEKey(getContext()); accentColor = Config.accentColor(getContext(), ateKey); getActivity().setVolumeControlStream(AudioManager.STREAM_MUSIC); favButton.setOnClickListener(mOnClickListener); favhelper = new FavHelper(getContext()); share.setOnClickListener(mOnClickListener); eqButton.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.eq)); eqButton.setOnClickListener(mOnClickListener); share.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.shares)); shuffleButton.setOnClickListener(mOnClickListener); shuffleButton.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.shuf_off)); repeatButton.setOnClickListener(mOnClickListener); repeatButton.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.rep_no)); moreMenu.setOnClickListener(mOnClickListener); moreMenu.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.ic_menu)); CustomLayoutManager customlayoutmanager = new CustomLayoutManager(getContext()); customlayoutmanager.setOrientation(LinearLayoutManager.VERTICAL); customlayoutmanager.setSmoothScrollbarEnabled(true); queuerv.setLayoutManager(customlayoutmanager); queuerv.addItemDecoration(new DividerItemDecoration(getContext(), 75, true)); queuerv.setHasFixedSize(true);//from www . ja v a 2 s .co m queueAdapter = new QueueAdapter(getContext(), this); queueAdapter.setLayoutId(R.layout.song_list); queuerv.setAdapter(queueAdapter); queueAdapter.setOnItemClickListener(mOnClick); ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(queueAdapter); mItemTouchHelper = new ItemTouchHelper(callback); mItemTouchHelper.attachToRecyclerView(queuerv); slidingpanelayout.setSliderFadeColor(Color.TRANSPARENT); slidingpanelayout.setCoveredFadeColor(Color.TRANSPARENT); Playing3view.setBackgroundColor(accentColor); if (getActivity() == null) { return; } getActivity().getWindow().setStatusBarColor(accentColor); helper = new Helper(getContext()); }
From source file:com.google.android.apps.santatracker.games.gumball.TiltGameFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mRootView = inflater.inflate(R.layout.fragment_gumball, container, false); mRootView.setKeepScreenOn(true);//from w w w . ja v a 2 s . c om // Use a lower resolution background image to conserve memory below ICS if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { View matchScoreLayout = mRootView.findViewById(R.id.tilt_score_layout); matchScoreLayout.setBackgroundResource(R.drawable.score_background_gingerbread); } mViewPlayAgainScore = (TextView) mRootView.findViewById(R.id.play_again_score); mViewPlayAgainScore.setText(String.valueOf(mMatchScore)); mViewPlayAgainLevel = (TextView) mRootView.findViewById(R.id.play_again_level); mViewPlayAgainLevel.setText(String.valueOf(mCurrentLevelNum)); mViewPlayAgainBackground = mRootView.findViewById(R.id.play_again_bkgrd); mViewPlayAgainMain = mRootView.findViewById(R.id.play_again_main); mViewPlayAgainButton = (Button) mRootView.findViewById(R.id.play_again_btn); mViewPlayAgainButton.setOnClickListener(this); mViewGPlusSignIn = (ImageView) mRootView.findViewById(R.id.gplus_button); mViewGPlusSignIn.setOnClickListener(this); mViewGPlusLayout = mRootView.findViewById(R.id.play_again_gplus); mViewGPlusLayout.setVisibility(View.GONE); // Initialise all animations // Construct an animation to blink the timer indefinitely mAnimationTimerAlpha = new AlphaAnimation(0.0f, 1.0f); mAnimationTimerAlpha.setDuration(1000); mAnimationTimerAlpha.setRepeatMode(Animation.REVERSE); mAnimationTimerAlpha.setRepeatCount(Animation.INFINITE); // Load all other animations mAnimationPlayAgainBackground = AnimationUtils.loadAnimation(getActivity(), R.anim.play_again_bkgrd_anim); mAnimationPlayAgainBackground.setFillAfter(true); mAnimationPlayAgainBackground.setAnimationListener(this); mAnimationPlayAgainMain = AnimationUtils.loadAnimation(getActivity(), R.anim.play_again_main_anim); mAnimationPlayAgainMain.setFillAfter(true); mAnimationPlayAgainMain.setAnimationListener(this); mAnimationScaleLevelDown = AnimationUtils.loadAnimation(getActivity(), R.anim.scale_level_anim_down); mAnimationScaleLevelDown.setAnimationListener(this); mAnimationLevelFadeOut = AnimationUtils.loadAnimation(getActivity(), R.anim.level_fade_out_anim); mAnimationLevelFadeOut.setAnimationListener(this); mAnimationLevelScaleUp = AnimationUtils.loadAnimation(getActivity(), R.anim.scale_up_level_anim); mAnimationLevelScaleUp.setAnimationListener(this); mViewMainMenuButton = (ImageButton) mRootView.findViewById(R.id.main_menu_button); mViewMainMenuButton.setVisibility(View.GONE); mViewMainMenuButton.setOnClickListener(this); mGameOutlet = mRootView.findViewById(R.id.tiltGameOutlet); mOutletOffset = getResources().getInteger(R.integer.outlet_offset); mViewIndicators[0] = (ImageView) mRootView.findViewById(R.id.indicator1); mViewIndicators[1] = (ImageView) mRootView.findViewById(R.id.indicator2); mViewIndicators[2] = (ImageView) mRootView.findViewById(R.id.indicator3); mViewIndicators[3] = (ImageView) mRootView.findViewById(R.id.indicator4); mViewIndicators[4] = (ImageView) mRootView.findViewById(R.id.indicator5); mViewIndicators[5] = (ImageView) mRootView.findViewById(R.id.indicator6); mViewCountdown = (TextView) mRootView.findViewById(R.id.tiltTimer); mLevelNumberText = (LevelTextView) mRootView.findViewById(R.id.tilt_end_level_number); mLevelNumberText.setVisibility(View.GONE); mEndLevelCircle = (CircleView) mRootView.findViewById(R.id.tilt_end_level_circle); mEndLevelCircle.setVisibility(View.GONE); mViewPlayButton = (ImageView) mRootView.findViewById(R.id.tilt_play_button); mViewPlayButton.setOnClickListener(this); mViewPlayButton.setVisibility(View.GONE); mViewPauseButton = (ImageView) mRootView.findViewById(R.id.tilt_pause_button); mViewPauseButton.setOnClickListener(this); mViewPauseButton.setVisibility(View.VISIBLE); mViewMatchPauseOverlay = mRootView.findViewById(R.id.tilt_pause_overlay); mViewMatchPauseOverlay.setVisibility(View.GONE); mViewBigPlayButton = (ImageButton) mRootView.findViewById(R.id.tilt_big_play_button); mViewBigPlayButton.setOnClickListener(this); mViewCancelBar = (ImageView) mRootView.findViewById(R.id.tilt_cancel_bar); mViewCancelBar.setOnClickListener(this); mViewCancelBar.setVisibility(View.GONE); mViewScore = (TextView) mRootView.findViewById(R.id.tilt_score); mViewScore.setText(String.valueOf(mMatchScore)); mGameView = (TiltGameView) mRootView.findViewById(R.id.tiltGameView); // Create the Box2D physics world. mWorld = new PhysicsWorld(); Vec2 gravity = new Vec2(0.0f, 0.0f); mWorld.create(gravity); mGameView.setModel(mWorld); mWorld.getWorld().setContactListener(this); mGumballQueue = new LinkedList<>(); // Initialise the sound pool and audio playback mSoundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0); mSoundBounceSmall = mSoundPool.load(getActivity(), R.raw.gbg_ball_bounce_1, 1); mSoundBounceMed = mSoundPool.load(getActivity(), R.raw.gbg_ball_bounce_2, 1); mSoundBounceLarge = mSoundPool.load(getActivity(), R.raw.gbg_ball_bounce_3, 1); mSoundBallInMachine = mSoundPool.load(getActivity(), R.raw.gbg_ball_into_machine, 1); mSoundBallFail = mSoundPool.load(getActivity(), R.raw.gbg_ball_fall_out, 1); mSoundBallDrop = mSoundPool.load(getActivity(), R.raw.gbg_new_ball_bounce_drop, 1); mSoundGameOver = mSoundPool.load(getActivity(), R.raw.gameover, 1); // Display the instructions if they haven't been seen before mSharedPreferences = getActivity().getSharedPreferences(MatchingGameConstants.PREFERENCES_FILENAME, Context.MODE_PRIVATE); if (!mSharedPreferences.getBoolean(MatchingGameConstants.GUMBALL_INSTRUCTIONS_VIEWED, false)) { mDrawableTransition = new AnimationDrawable(); mDrawableTransition.addFrame(getResources().getDrawable(R.drawable.instructions_shake_1), 300); mDrawableTransition.addFrame(getResources().getDrawable(R.drawable.instructions_shake_2), 300); mDrawableTransition.addFrame(getResources().getDrawable(R.drawable.instructions_shake_3), 300); mDrawableTransition.setOneShot(false); mViewInstructions = (ImageView) mRootView.findViewById(R.id.instructions); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { mViewInstructions.setImageResource(R.drawable.instructions_shake_1); } else { mViewInstructions.setImageDrawable(mDrawableTransition); mViewInstructions.post(new Runnable() { public void run() { mDrawableTransition.start(); } }); } // Hide the instructions after 2 seconds mViewInstructions.postDelayed(new HideInstructionsRunnable(), 2200); } return mRootView; }
From source file:com.adityarathi.muo.services.AudioPlaybackService.java
/** * Requests AudioFocus from the OS.//from w w w.j a v a2 s .c o m * * @return True if AudioFocus was gained. False, otherwise. */ private boolean requestAudioFocus() { int result = mAudioManager.requestAudioFocus(audioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { //Stop the service. mService.stopSelf(); Toast.makeText(mContext, R.string.close_other_audio_apps, Toast.LENGTH_LONG).show(); return false; } else { return true; } }
From source file:com.intel.xdk.player.Player.java
public void playSoundById(final int id) { AudioManager mgr = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE); int streamVolume = mgr.getStreamVolume(AudioManager.STREAM_MUSIC); int streamMaximum = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC); float volume = (float) streamVolume / (float) streamMaximum; int playingSound = soundPool.play(id, volume, volume, 0, 0, 1f); //should inject playingSound so it can be stopped/paused/resumed? }
From source file:org.drrickorang.loopback.LoopbackActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Set the layout for this activity. You can find it View view = getLayoutInflater().inflate(R.layout.main_activity, null); setContentView(view);/*w ww. j a v a2 s . c o m*/ mTextInfo = (TextView) findViewById(R.id.textInfo); mBarMasterLevel = (SeekBar) findViewById(R.id.BarMasterLevel); AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); int maxVolume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); mBarMasterLevel.setMax(maxVolume); mBarMasterLevel.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); am.setStreamVolume(AudioManager.STREAM_MUSIC, progress, 0); refreshState(); log("Changed stream volume to: " + progress); } }); mWavePlotView = (WavePlotView) findViewById(R.id.viewWavePlot); mTextViewCurrentLevel = (TextView) findViewById(R.id.textViewCurrentLevel); mTextViewCurrentLevel.setTextSize(15); mTextViewEstimatedLatency = (TextView) findViewById(R.id.textViewEstimatedLatency); refreshState(); applyIntent(getIntent()); }
From source file:com.google.fpl.gim.examplegame.MainService.java
/** * Obtain audio focus for the application. This also checks if we are currently playing any * other audio clips, so it checks for "audio focus" within the app. * @return True if audio focus is obtained. False otherwise. */// w ww. j a v a 2 s .c o m public boolean obtainAudioFocus() { if (mMediaPlayer.isPlaying() || mTextToSpeech.isSpeaking()) { return false; } int result = mAudioManager.requestAudioFocus(mAudioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT); return (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED); }
From source file:com.google.dotorg.crisisresponse.translationcards.RecordingActivity.java
private void startListening() { recordButton.setBackgroundResource(R.drawable.button_record_disabled); listenButton.setBackgroundResource(R.drawable.button_listen_active); recordingStatus = RecordingStatus.LISTENING; mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); try {/*from w w w.j ava2s .c om*/ if (isAsset) { AssetFileDescriptor fd = getAssets().openFd(filename); mediaPlayer.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength()); fd.close(); } else { mediaPlayer.setDataSource(new FileInputStream(filename).getFD()); } mediaPlayer.prepare(); } catch (IOException e) { Log.d(TAG, "Error preparing audio."); throw new IllegalArgumentException(e); // TODO(nworden): something } mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { finishListening(mp); } }); mediaPlayer.start(); }
From source file:se.droidgiro.scanner.CaptureActivity.java
/** * Creates the beep MediaPlayer in advance so that the sound can be * triggered with the least latency possible. *//* w w w . ja v a 2 s . c o m*/ private void initBeepSound() { if (playBeep && mediaPlayer == null) { // The volume on STREAM_SYSTEM is not adjustable, and users found it // too loud, // so we now play on the music stream. setVolumeControlStream(AudioManager.STREAM_MUSIC); mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mediaPlayer.setOnCompletionListener(beepListener); AssetFileDescriptor file = getResources().openRawResourceFd(R.raw.beep); try { mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength()); file.close(); mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME); mediaPlayer.prepare(); } catch (IOException e) { mediaPlayer = null; } } }
From source file:com.yohpapa.research.simplemusicplayer.PlaybackService.java
private boolean requestAudioFocus() { AudioManager manager = (AudioManager) getSystemService(AUDIO_SERVICE); int result = manager.requestAudioFocus(onAudioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); return result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED; }