Android Open Source - PlayTunes Music Intent Receiver






From Project

Back to project page PlayTunes.

License

The source code is released under:

Copyright (c) 2014, Impeccable Labs, LLC. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions ar...

If you think the Android project PlayTunes listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*   
 * Copyright (C) 2011 The Android Open Source Project
 *//  w  ww  .  j a  v a 2 s.c o m
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.ideabag.playtunes.media;

import com.ideabag.playtunes.service.MusicPlayerService;
import com.ideabag.playtunes.util.GAEvent;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.Toast;

/**
 * Receives broadcasted intents. In particular, we are interested in the
 * android.media.AUDIO_BECOMING_NOISY and android.intent.action.MEDIA_BUTTON intents, which is
 * broadcast, for example, when the user disconnects the headphones. This class works because we are
 * declaring it in a <receiver> tag in AndroidManifest.xml.
 */
public class MusicIntentReceiver extends BroadcastReceiver {
  
    @Override public void onReceive( Context context, Intent intent ) {
      
      String action = intent.getAction();
      
      Intent mIntent = new Intent();
        
      
        if ( action.equals( android.media.AudioManager.ACTION_AUDIO_BECOMING_NOISY ) ) {
          
          context.sendBroadcast( new Intent( MusicPlayerService.ACTION_PAUSE ) );

        } else if ( action.equals( Intent.ACTION_MEDIA_BUTTON ) ) {
            
          if ( intent.hasExtra( Intent.EXTRA_KEY_EVENT ) ) {
            
              KeyEvent keyEvent = ( KeyEvent ) intent.getExtras().get( Intent.EXTRA_KEY_EVENT );
              
              if ( keyEvent.getAction() != KeyEvent.ACTION_DOWN )
                  return;
              
              
              mIntent.putExtra( GAEvent.Categories.LOCKSCREEN, true );
              
              switch ( keyEvent.getKeyCode() ) {
                
                case KeyEvent.KEYCODE_MEDIA_PAUSE:
                case KeyEvent.KEYCODE_MEDIA_PLAY:
                  case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
                  case KeyEvent.KEYCODE_HEADSETHOOK:
                    
                    mIntent.setAction( MusicPlayerService.ACTION_PLAY_OR_PAUSE );
                    
                    context.sendBroadcast( mIntent );
                      
                      break;
                      /*
                  case KeyEvent.KEYCODE_MEDIA_PLAY:
                    
                    mIntent.setAction( MusicPlayerService.ACTION_PLAY );
                    
                      context.sendBroadcast( mIntent );
                      
                      break;
                      
                  case KeyEvent.KEYCODE_MEDIA_PAUSE:
                      
                    mIntent.setAction( MusicPlayerService.ACTION_PAUSE );
                    
                    context.sendBroadcast( mIntent );
                      
                      break;
                 
                  case KeyEvent.KEYCODE_MEDIA_STOP:
                    
                      context.startService( new Intent( MusicPlayerService.ACTION_STOP ) );
                      
                      break;
                   */
                  case KeyEvent.KEYCODE_MEDIA_NEXT:
                    
                    mIntent.setAction( MusicPlayerService.ACTION_NEXT );
                    
                      context.sendBroadcast( mIntent );
                      
                      break;
                      
                  case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
                      
                    mIntent.setAction( MusicPlayerService.ACTION_BACK );
                    
                      context.sendBroadcast( mIntent );
                      
                      break;
                      
              }
              
          }
          
        }
        
    }
    
}




Java Source Code List

com.ideabag.playtunes.PlaylistManager.java
com.ideabag.playtunes.DragNDrop.DragListener.java
com.ideabag.playtunes.DragNDrop.DragNDropListView.java
com.ideabag.playtunes.DragNDrop.DropListener.java
com.ideabag.playtunes.DragNDrop.RemoveListener.java
com.ideabag.playtunes.activity.MainActivity.java
com.ideabag.playtunes.activity.NowPlayingActivity.java
com.ideabag.playtunes.activity.SettingsActivity.java
com.ideabag.playtunes.adapter.AlbumListAdapter.java
com.ideabag.playtunes.adapter.AlbumsAllAdapter.java
com.ideabag.playtunes.adapter.AlbumsOneAdapter.java
com.ideabag.playtunes.adapter.ArtistAlbumsAdapter.java
com.ideabag.playtunes.adapter.ArtistAllSongsAdapter.java
com.ideabag.playtunes.adapter.ArtistListAdapter.java
com.ideabag.playtunes.adapter.ArtistSinglesAdapter.java
com.ideabag.playtunes.adapter.ArtistsAllAdapter.java
com.ideabag.playtunes.adapter.AsyncQueryAdapter.java
com.ideabag.playtunes.adapter.GenresAllAdapter.java
com.ideabag.playtunes.adapter.GenresOneAdapter.java
com.ideabag.playtunes.adapter.NavigationListAdapter.java
com.ideabag.playtunes.adapter.PlaylistsAllAdapter.java
com.ideabag.playtunes.adapter.PlaylistsOneAdapter.java
com.ideabag.playtunes.adapter.SongListAdapter.java
com.ideabag.playtunes.adapter.SongsAllAdapter.java
com.ideabag.playtunes.adapter.search.SearchAlbumsAdapter.java
com.ideabag.playtunes.adapter.search.SearchArtistsAdapter.java
com.ideabag.playtunes.adapter.search.SearchSongsAdapter.java
com.ideabag.playtunes.database.MediaQuery.java
com.ideabag.playtunes.dialog.AddToPlaylistDialogFragment.java
com.ideabag.playtunes.dialog.CreatePlaylistDialogFragment.java
com.ideabag.playtunes.dialog.FeedbackDialogFragment.java
com.ideabag.playtunes.dialog.PlaylistDeleteDialogFragment.java
com.ideabag.playtunes.dialog.PlaylistMenuDialogFragment.java
com.ideabag.playtunes.dialog.PlaylistRenameDialogFragment.java
com.ideabag.playtunes.dialog.RateAppDialogFragment.java
com.ideabag.playtunes.dialog.SongMenuDialogFragment.java
com.ideabag.playtunes.fragment.AlbumsAllFragment.java
com.ideabag.playtunes.fragment.AlbumsOneFragment.java
com.ideabag.playtunes.fragment.ArtistSinglesFragment.java
com.ideabag.playtunes.fragment.ArtistsAllFragment.java
com.ideabag.playtunes.fragment.ArtistsOneFragment.java
com.ideabag.playtunes.fragment.FooterControlsFragment.java
com.ideabag.playtunes.fragment.GenresAllFragment.java
com.ideabag.playtunes.fragment.GenresOneFragment.java
com.ideabag.playtunes.fragment.MusicBrowserFragment.java
com.ideabag.playtunes.fragment.NavigationDrawerFragment.java
com.ideabag.playtunes.fragment.NavigationFragment.java
com.ideabag.playtunes.fragment.PlaylistsAllFragment.java
com.ideabag.playtunes.fragment.PlaylistsOneFragment.java
com.ideabag.playtunes.fragment.SaveScrollListFragment.java
com.ideabag.playtunes.fragment.SongsFragment.java
com.ideabag.playtunes.fragment.TrackProgressFragment.java
com.ideabag.playtunes.fragment.search.SearchAlbumsFragment.java
com.ideabag.playtunes.fragment.search.SearchAllFragment.java
com.ideabag.playtunes.fragment.search.SearchArtistsFragment.java
com.ideabag.playtunes.fragment.search.SearchFragment.java
com.ideabag.playtunes.fragment.search.SearchSongsFragment.java
com.ideabag.playtunes.fragment.search.SearchSuggestionsFragment.java
com.ideabag.playtunes.media.AudioFocusHelper.java
com.ideabag.playtunes.media.MusicFocusable.java
com.ideabag.playtunes.media.MusicIntentReceiver.java
com.ideabag.playtunes.media.PlaylistMediaPlayer.java
com.ideabag.playtunes.media.RemoteControlClientCompat.java
com.ideabag.playtunes.media.RemoteControlHelper.java
com.ideabag.playtunes.service.LockscreenManager.java
com.ideabag.playtunes.service.MusicPlayerService.java
com.ideabag.playtunes.service.PlaybackNotification.java
com.ideabag.playtunes.util.AdmobUtil.java
com.ideabag.playtunes.util.AlbumSongsCountTask.java
com.ideabag.playtunes.util.AsyncDrawable.java
com.ideabag.playtunes.util.BitmapWorkerTask.java
com.ideabag.playtunes.util.CheckRemoteVersionFileTask.java
com.ideabag.playtunes.util.DrawerLayout.java
com.ideabag.playtunes.util.GAEvent.java
com.ideabag.playtunes.util.IMusicBrowser.java
com.ideabag.playtunes.util.ISearchableAdapter.java
com.ideabag.playtunes.util.LoadAlbumStackTask.java
com.ideabag.playtunes.util.MergeAdapter.java
com.ideabag.playtunes.util.QueryCountTask.java
com.ideabag.playtunes.util.SackOfViewsAdapter.java
com.ideabag.playtunes.util.SearchHistory.java
com.ideabag.playtunes.util.StarToggleTask.java
com.ideabag.playtunes.util.TrackerSingleton.java