Example usage for android.media AudioManager ACTION_AUDIO_BECOMING_NOISY

List of usage examples for android.media AudioManager ACTION_AUDIO_BECOMING_NOISY

Introduction

In this page you can find the example usage for android.media AudioManager ACTION_AUDIO_BECOMING_NOISY.

Prototype

String ACTION_AUDIO_BECOMING_NOISY

To view the source code for android.media AudioManager ACTION_AUDIO_BECOMING_NOISY.

Click Source Link

Document

Broadcast intent, a hint for applications that audio is about to become 'noisy' due to a change in audio outputs.

Usage

From source file:org.videolan.vlc.audio.AudioService.java

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

    // Get libVLC instance
    try {//from   ww  w.  j a  v a 2  s . c  om
        mLibVLC = VLCInstance.getLibVlcInstance();
    } catch (LibVlcException e) {
        e.printStackTrace();
    }

    mCallback = new HashMap<IAudioServiceCallback, Integer>();
    mCurrentIndex = -1;
    mPrevIndex = -1;
    mNextIndex = -1;
    mPrevious = new Stack<Integer>();
    mEventHandler = EventHandler.getInstance();
    mRemoteControlClientReceiverComponent = new ComponentName(getPackageName(),
            RemoteControlClientReceiver.class.getName());

    // Make sure the audio player will acquire a wake-lock while playing. If we don't do
    // that, the CPU might go to sleep while the song is playing, causing playback to stop.
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);

    IntentFilter filter = new IntentFilter();
    filter.setPriority(Integer.MAX_VALUE);
    filter.addAction(ACTION_REMOTE_BACKWARD);
    filter.addAction(ACTION_REMOTE_PLAYPAUSE);
    filter.addAction(ACTION_REMOTE_PLAY);
    filter.addAction(ACTION_REMOTE_PAUSE);
    filter.addAction(ACTION_REMOTE_STOP);
    filter.addAction(ACTION_REMOTE_FORWARD);
    filter.addAction(ACTION_REMOTE_LAST_PLAYLIST);
    filter.addAction(ACTION_WIDGET_INIT);
    filter.addAction(Intent.ACTION_HEADSET_PLUG);
    filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
    filter.addAction(VLCApplication.SLEEP_INTENT);
    registerReceiver(serviceReceiver, filter);

    final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
    boolean stealRemoteControl = pref.getBoolean("enable_steal_remote_control", false);

    if (!LibVlcUtil.isFroyoOrLater() || stealRemoteControl) {
        /* Backward compatibility for API 7 */
        filter = new IntentFilter();
        if (stealRemoteControl)
            filter.setPriority(Integer.MAX_VALUE);
        filter.addAction(Intent.ACTION_MEDIA_BUTTON);
        mRemoteControlClientReceiver = new RemoteControlClientReceiver();
        registerReceiver(mRemoteControlClientReceiver, filter);
    }
}

From source file:org.videolan.vlc2.audio.AudioService.java

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

    // Get libVLC instance
    try {//from  w  ww . ja  v a  2  s. c o  m
        mLibVLC = VLCInstance.getLibVlcInstance();
    } catch (LibVlcException e) {
        e.printStackTrace();
    }

    mCallback = new HashMap<IAudioServiceCallback, Integer>();
    mCurrentIndex = -1;
    mPrevIndex = -1;
    mNextIndex = -1;
    mPrevious = new Stack<Integer>();
    mEventHandler = EventHandler.getInstance();
    mRemoteControlClientReceiverComponent = new ComponentName(getPackageName(),
            RemoteControlClientReceiver.class.getName());

    // Make sure the audio player will acquire a wake-lock while playing. If we don't do
    // that, the CPU might go to sleep while the song is playing, causing playback to stop.
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);

    IntentFilter filter = new IntentFilter();
    filter.setPriority(Integer.MAX_VALUE);
    filter.addAction(ACTION_REMOTE_BACKWARD);
    filter.addAction(ACTION_REMOTE_PLAYPAUSE);
    filter.addAction(ACTION_REMOTE_PLAY);
    filter.addAction(ACTION_REMOTE_PAUSE);
    filter.addAction(ACTION_REMOTE_STOP);
    filter.addAction(ACTION_REMOTE_FORWARD);
    filter.addAction(ACTION_REMOTE_LAST_PLAYLIST);
    filter.addAction(ACTION_WIDGET_INIT);
    filter.addAction(Intent.ACTION_HEADSET_PLUG);
    filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
    filter.addAction(VLCApplication.SLEEP_INTENT);
    filter.addAction(VLCApplication.INCOMING_CALL_INTENT);
    filter.addAction(VLCApplication.CALL_ENDED_INTENT);
    registerReceiver(serviceReceiver, filter);

    final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
    boolean stealRemoteControl = pref.getBoolean("enable_steal_remote_control", false);

    if (!LibVlcUtil.isFroyoOrLater() || stealRemoteControl) {
        /* Backward compatibility for API 7 */
        filter = new IntentFilter();
        if (stealRemoteControl)
            filter.setPriority(Integer.MAX_VALUE);
        filter.addAction(Intent.ACTION_MEDIA_BUTTON);
        mRemoteControlClientReceiver = new RemoteControlClientReceiver();
        registerReceiver(mRemoteControlClientReceiver, filter);
    }
}

From source file:org.videolan.vlc.PlaybackService.java

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

    if (!VLCInstance.testCompatibleCPU(this)) {
        stopSelf();/*from www  .j av  a 2s .c o  m*/
        return;
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    mDetectHeadset = prefs.getBoolean("enable_headset_detection", true);

    mMediaListPlayer = MediaWrapperListPlayer.getInstance();

    mCallback = new HashMap<IPlaybackServiceCallback, Integer>();
    mCurrentIndex = -1;
    mPrevIndex = -1;
    mNextIndex = -1;
    mPrevious = new Stack<Integer>();
    mEventHandler = EventHandler.getInstance();
    mRemoteControlClientReceiverComponent = new ComponentName(BuildConfig.APPLICATION_ID,
            RemoteControlClientReceiver.class.getName());

    // Make sure the audio player will acquire a wake-lock while playing. If we don't do
    // that, the CPU might go to sleep while the song is playing, causing playback to stop.
    PowerManager pm = (PowerManager) VLCApplication.getAppContext().getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);

    IntentFilter filter = new IntentFilter();
    filter.setPriority(Integer.MAX_VALUE);
    filter.addAction(ACTION_REMOTE_BACKWARD);
    filter.addAction(ACTION_REMOTE_PLAYPAUSE);
    filter.addAction(ACTION_REMOTE_PLAY);
    filter.addAction(ACTION_REMOTE_PAUSE);
    filter.addAction(ACTION_REMOTE_STOP);
    filter.addAction(ACTION_REMOTE_FORWARD);
    filter.addAction(ACTION_REMOTE_LAST_PLAYLIST);
    filter.addAction(ACTION_WIDGET_INIT);
    filter.addAction(Intent.ACTION_HEADSET_PLUG);
    filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
    filter.addAction(VLCApplication.SLEEP_INTENT);
    filter.addAction(VLCApplication.INCOMING_CALL_INTENT);
    filter.addAction(VLCApplication.CALL_ENDED_INTENT);
    registerReceiver(serviceReceiver, filter);

    final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
    boolean stealRemoteControl = pref.getBoolean("enable_steal_remote_control", false);

    if (!AndroidUtil.isFroyoOrLater() || stealRemoteControl) {
        /* Backward compatibility for API 7 */
        filter = new IntentFilter();
        if (stealRemoteControl)
            filter.setPriority(Integer.MAX_VALUE);
        filter.addAction(Intent.ACTION_MEDIA_BUTTON);
        mRemoteControlClientReceiver = new RemoteControlClientReceiver();
        registerReceiver(mRemoteControlClientReceiver, filter);
    }
    try {
        getPackageManager().getPackageInfo("com.getpebble.android", PackageManager.GET_ACTIVITIES);
        mPebbleEnabled = true;
    } catch (PackageManager.NameNotFoundException e) {
        mPebbleEnabled = false;
    }
}

From source file:com.dzt.musicplay.player.AudioService.java

@Override
public void onCreate() {
    super.onCreate();
    GlobalConstants.print_i(getClass(), "onCreate");
    // Get libVLC instance
    try {/*from  w  w  w.j  a  v  a  2s .c o m*/
        mLibVLC = VLCInstance.getLibVlcInstance(getApplicationContext());
    } catch (LibVlcException e) {
        e.printStackTrace();
    }
    StartLoadFileThread();

    mCallback = new HashMap<IAudioServiceCallback, Integer>();
    mMediaList = new ArrayList<Media>();
    mCurrentIndex = -1;
    mPrevIndex = -1;
    mNextIndex = -1;
    mPrevious = new Stack<Integer>();
    mEventHandler = EventHandler.getInstance();
    mRemoteControlClientReceiverComponent = new ComponentName(getPackageName(),
            RemoteControlClientReceiver.class.getName());

    // Make sure the audio player will acquire a wake-lock while playing. If
    // we don't do
    // that, the CPU might go to sleep while the song is playing, causing
    // playback to stop.
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);

    IntentFilter filter = new IntentFilter();
    filter.setPriority(Integer.MAX_VALUE);
    filter.addAction(ACTION_REMOTE_BACKWARD);
    filter.addAction(ACTION_REMOTE_PLAYPAUSE);
    filter.addAction(ACTION_REMOTE_PLAY);
    filter.addAction(ACTION_REMOTE_PAUSE);
    filter.addAction(ACTION_REMOTE_STOP);
    filter.addAction(ACTION_REMOTE_FORWARD);
    filter.addAction(ACTION_REMOTE_LAST_PLAYLIST);
    filter.addAction(ACTION_WIDGET_INIT);
    filter.addAction(Intent.ACTION_HEADSET_PLUG);
    filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
    filter.addAction(SLEEP_INTENT);
    registerReceiver(serviceReceiver, filter);

    final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
    boolean stealRemoteControl = pref.getBoolean("enable_steal_remote_control", false);

    if (!LibVlcUtil.isFroyoOrLater() || stealRemoteControl) {
        /* Backward compatibility for API 7 */
        filter = new IntentFilter();
        if (stealRemoteControl)
            filter.setPriority(Integer.MAX_VALUE);
        filter.addAction(Intent.ACTION_MEDIA_BUTTON);
        mRemoteControlClientReceiver = new RemoteControlClientReceiver();
        registerReceiver(mRemoteControlClientReceiver, filter);
    }
    GlobalConstants.print_i(getClass(), "onCreate----end");
}

From source file:dk.nota.lyt.libvlc.PlaybackService.java

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

    mSettings = PreferenceManager.getDefaultSharedPreferences(this);
    mMediaPlayer = newMediaPlayer();/*from  ww w  . jav a  2  s .c  o  m*/
    if (!Utils.testCompatibleCPU(this)) {
        stopSelf();
        return;
    }

    mDetectHeadset = mSettings.getBoolean("enable_headset_detection", true);

    mCurrentIndex = -1;
    mPrevIndex = -1;
    mNextIndex = -1;
    mPrevious = new Stack<Integer>();
    mRemoteControlClientReceiverComponent = new ComponentName(this.getApplicationContext(),
            RemoteControlEventReceiver.class.getName());

    // Make sure the audio player will acquire a wake-lock while playing. If we don't do
    // that, the CPU might go to sleep while the song is playing, causing playback to stopService.
    PowerManager pm = (PowerManager) this.getApplicationContext().getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);

    IntentFilter filter = new IntentFilter();
    filter.setPriority(Integer.MAX_VALUE);
    filter.addAction(ACTION_REMOTE_BACKWARD);
    filter.addAction(ACTION_REMOTE_PLAYPAUSE);
    filter.addAction(ACTION_REMOTE_PLAY);
    filter.addAction(ACTION_REMOTE_PAUSE);
    filter.addAction(ACTION_REMOTE_STOP);
    filter.addAction(ACTION_REMOTE_FORWARD);
    filter.addAction(Intent.ACTION_HEADSET_PLUG);
    filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
    registerReceiver(mReceiver, filter);
}

From source file:com.rks.musicx.services.MusicXService.java

private void otherstuff() {
    recent = new CommonDatabase(this, Constants.RecentlyPlayed_TableName, true);
    queue = new CommonDatabase(this, Constants.Queue_TableName, true);
    CurrentSong = new Song();
    audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    checkTelephonyState();// w ww .j a  va2  s .c  o  m
    headsetState();
    mediaLockscreen();
    restoreState();
    mediaButtonReceiver = new MediaButtonReceiver();
    if (controlReceiver == null) {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(android.media.AudioManager.ACTION_AUDIO_BECOMING_NOISY);
        intentFilter.addAction(ACTION_PREVIOUS);
        intentFilter.addAction(ACTION_PAUSE);
        intentFilter.addAction(ACTION_PLAY);
        intentFilter.addAction(ACTION_TOGGLE);
        intentFilter.addAction(ACTION_NEXT);
        intentFilter.addAction(ACTION_CHANGE_STATE);
        intentFilter.addAction(ACTION_COMMAND1);
        intentFilter.addAction(ACTION_COMMAND);
        intentFilter.addAction(ACTION_FAV);
        registerReceiver(controlReceiver, intentFilter);
        registerReceiver(mediaButtonReceiver, intentFilter);
        Log.d(TAG, "Broadcast");
    }
    if (permissionManager.isAudioRecordGranted(this)) {
        int audioID = audioSession();
        Equalizers.initEq(audioID);
        BassBoosts.initBass(audioID);
        Virtualizers.initVirtualizer(audioID);
        Loud.initLoudnessEnhancer(audioID);
        Reverb.initReverb();
    } else {
        Log.d(TAG, "permission not granted");
    }
    favHelper = new FavHelper(this);
    handler = new Handler();
    helper = new Helper(this);
    if (permissionManager.isSystemAlertGranted(MusicXService.this)) {
        widgetPermission = true;
    } else {
        widgetPermission = false;
        Log.d(TAG, "Overlay permission not detected");
    }
}

From source file:com.cw.litenote.DrawerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    /////from  www. j  a v  a  2 s  .c om
    //        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
    //
    //          .detectDiskReads()
    //          .detectDiskWrites()
    //          .detectNetwork() 
    //          .penaltyLog()
    //          .build());
    //
    //           StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
    ////          .detectLeakedSqlLiteObjects() //??? unmark this line will cause strict mode error
    //          .penaltyLog() 
    //          .penaltyDeath()
    //          .build());        
    ///
    super.onCreate(savedInstanceState);

    mDrawerActivity = this;
    setContentView(R.layout.drawer_activity);

    // Release mode: no debug message
    if (Define.CODE_MODE == Define.RELEASE_MODE) {
        OutputStream nullDev = new OutputStream() {
            public void close() {
            }

            public void flush() {
            }

            public void write(byte[] b) {
            }

            public void write(byte[] b, int off, int len) {
            }

            public void write(int b) {
            }
        };
        System.setOut(new PrintStream(nullDev));
    }

    //Log.d below can be disabled by applying proguard
    //1. enable proguard-android-optimize.txt in project.properties
    //2. be sure to use newest version to avoid build error
    //3. add the following in proguard-project.txt
    /*-assumenosideeffects class android.util.Log {
    public static boolean isLoggable(java.lang.String, int);
    public static int v(...);
    public static int i(...);
    public static int w(...);
    public static int d(...);
    public static int e(...);
    }
    */
    Log.d("test log tag", "start app");

    System.out.println("================start application ==================");
    System.out.println("DrawerActivity / onCreate");

    UtilImage.getDefaultSacleInPercent(DrawerActivity.this);

    mAppTitle = getTitle();

    mDrawerChildTitles = new ArrayList<String>();

    Context context = getApplicationContext();

    if (mDb != null)
        mDb.close();

    mDb = new DB(context);
    mDb.initDrawerDb(mDb);

    if (mDb_tabs != null)
        mDb_tabs.close();

    mDb_tabs = new DB(context, Util.getPref_lastTimeView_tabs_tableId(this));
    mDb_tabs.initTabsDb(mDb_tabs);

    if (mDb_notes != null)
        mDb_tabs.close();

    mDb_notes = new DB(context, Util.getPref_lastTimeView_notes_tableId(this));
    mDb_notes.initNotesDb(mDb_notes);

    //Add note with the link
    String intentLink = addIntentLink(getIntent());
    if (!Util.isEmptyString(intentLink)) {
        finish(); // for no active DrawerActivity case
    } else {
        // check DB
        final boolean ENABLE_DB_CHECK = false;//true;//
        if (ENABLE_DB_CHECK) {
            // list all drawer tables
            int drawerCount = mDb.getDrawerChildCount();
            for (int drawerPos = 0; drawerPos < drawerCount; drawerPos++) {
                String drawerTitle = mDb.getDrawerChild_Title(drawerPos);
                DrawerActivity.mFocus_drawerChildPos = drawerPos;

                // list all tab tables
                int tabsTableId = mDb.getTabsTableId(drawerPos);
                System.out.println("--- tabs table Id = " + tabsTableId + ", drawer title = " + drawerTitle);
                mDb_tabs = new DB(context, tabsTableId);
                mDb_tabs.initTabsDb(mDb_tabs);
                int tabsCount = mDb_tabs.getTabsCount(true);
                for (int tabPos = 0; tabPos < tabsCount; tabPos++) {
                    TabsHostFragment.mCurrent_tabIndex = tabPos;
                    int tabId = mDb_tabs.getTabId(tabPos, true);
                    int notesTableId = mDb_tabs.getNotesTableId(tabPos, true);
                    String tabTitle = mDb_tabs.getTabTitle(tabPos, true);
                    System.out.println("   --- tab Id = " + tabId);
                    System.out.println("   --- notes table Id = " + notesTableId);
                    System.out.println("   --- tab title = " + tabTitle);

                    mLastOkTabId = tabId;

                    try {
                        mDb_notes = new DB(context, String.valueOf(notesTableId));
                        mDb_notes.initNotesDb(mDb_notes);
                        mDb_notes.doOpenNotes();
                        mDb_notes.doCloseNotes();
                    } catch (Exception e) {
                    }
                }
            }

            // recover focus
            int tabsTableId = Util.getPref_lastTimeView_tabs_tableId(this);
            DB.setFocus_tabsTableId(tabsTableId);
            String notesTableId = Util.getPref_lastTimeView_notes_tableId(this);
            DB.setFocus_notes_tableId(notesTableId);
        } //if(ENABLE_DB_CHECK)

        // get last time drawer number, default drawer number: 1
        if (savedInstanceState == null) {
            for (int i = 0; i < mDb.getDrawerChildCount(); i++) {
                if (mDb.getTabsTableId(i) == Util.getPref_lastTimeView_tabs_tableId(this)) {
                    mFocus_drawerChildPos = i;
                    System.out
                            .println("DrawerActivity / onCreate /  mFocusDrawerId = " + mFocus_drawerChildPos);
                }
            }
            AudioPlayer.mPlayerState = AudioPlayer.PLAYER_AT_STOP;
            UtilAudio.mIsCalledWhilePlayingAudio = false;
        }

        // set drawer title
        if (mDb.getDrawerChildCount() == 0) {
            for (int i = 0; i < Define.ORIGIN_TABS_TABLE_COUNT; i++) {
                String drawerTitle = Define.getDrawerTitle(mDrawerActivity, i);
                mDrawerChildTitles.add(drawerTitle);
                mDb.insertDrawerChild(i + 1, drawerTitle);
            }
        } else {
            for (int i = 0; i < mDb.getDrawerChildCount(); i++) {
                mDrawerChildTitles.add(""); // init only
                mDrawerChildTitles.set(i, mDb.getDrawerChild_Title(i));
            }
        }

        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerListView = (DragSortListView) findViewById(R.id.left_drawer);

        // set a custom shadow that overlays the main content when the drawer opens
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

        // set adapter
        mDb.doOpenDrawer();
        Cursor cursor = DB.mCursor_drawerChild;

        String[] from = new String[] { DB.KEY_DRAWER_TITLE };
        int[] to = new int[] { R.id.drawerText };

        drawerAdapter = new DrawerAdapter(this, R.layout.drawer_list_item, cursor, from, to, 0);

        mDb.doCloseDrawer();

        mDrawerListView.setAdapter(drawerAdapter);

        // set up click listener
        MainUi.addDrawerItemListeners();//??? move to resume?
        mDrawerListView.setOnItemClickListener(MainUi.itemClick);
        // set up long click listener
        mDrawerListView.setOnItemLongClickListener(MainUi.itemLongClick);

        mController = DrawerListview.buildController(mDrawerListView);
        mDrawerListView.setFloatViewManager(mController);
        mDrawerListView.setOnTouchListener(mController);

        // init drawer dragger
        mPref_show_note_attribute = getSharedPreferences("show_note_attribute", 0);
        if (mPref_show_note_attribute.getString("KEY_ENABLE_DRAWER_DRAGGABLE", "no").equalsIgnoreCase("yes"))
            mDrawerListView.setDragEnabled(true);
        else
            mDrawerListView.setDragEnabled(false);

        mDrawerListView.setDragListener(DrawerListview.onDrag);
        mDrawerListView.setDropListener(DrawerListview.onDrop);

        // enable ActionBar app icon to behave as action to toggle nav drawer
        getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setHomeButtonEnabled(true);
        //         getActionBar().setBackgroundDrawable(new ColorDrawable(ColorSet.bar_color));
        getActionBar().setBackgroundDrawable(new ColorDrawable(ColorSet.getBarColor(mDrawerActivity)));

        // ActionBarDrawerToggle ties together the the proper interactions
        // between the sliding drawer and the action bar app icon
        mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
                mDrawerLayout, /* DrawerLayout object */
                R.drawable.ic_drawer, /* navigation drawer image to replace 'Up' caret */
                R.string.drawer_open, /* "open drawer" description for accessibility */
                R.string.drawer_close /* "close drawer" description for accessibility */
        ) {
            public void onDrawerClosed(View view) {
                System.out.println("mDrawerToggle onDrawerClosed ");
                int pos = mDrawerListView.getCheckedItemPosition();
                int tblId = mDb.getTabsTableId(pos);
                DB.setSelected_tabsTableId(tblId);
                mDrawerChildTitle = mDb.getDrawerChild_Title(pos);
                setTitle(mDrawerChildTitle);
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()

                // add for deleting drawer
                if (TabsHostFragment.mTabHost == null) {
                    MainUi.selectDrawerChild(mFocus_drawerChildPos);
                    setTitle(mDrawerChildTitle);
                }
            }

            public void onDrawerOpened(View drawerView) {
                System.out.println("mDrawerToggle onDrawerOpened ");
                setTitle(mAppTitle);
                drawerAdapter.notifyDataSetChanged();
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }
        };
        mDrawerLayout.setDrawerListener(mDrawerToggle);

        mContext = getBaseContext();
        bEnableConfig = false;

        // add on back stack changed listener
        fragmentManager = getSupportFragmentManager();
        mOnBackStackChangedListener = DrawerActivity.this;
        fragmentManager.addOnBackStackChangedListener(mOnBackStackChangedListener);

        // register an audio stream receiver
        if (noisyAudioStreamReceiver == null) {
            noisyAudioStreamReceiver = new NoisyAudioStreamReceiver();
            intentFilter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
            registerReceiver(noisyAudioStreamReceiver, intentFilter);
        }

    }

    // Show license dialog
    new EULA_dlg(this).show();
}

From source file:org.runbuddy.tomahawk.services.PlaybackService.java

public void play(boolean onAudioFocusGain) {
    Log.d(TAG, "play");
    if (onAudioFocusGain && !mPlayOnFocusGain) {
        return;/*from www.  j  ava2  s  .  c o  m*/
    }
    if (mPlaybackManager.getCurrentQuery() != null) {
        if (mAudioBecomingNoisyReceiver == null) {
            mAudioBecomingNoisyReceiver = new AudioBecomingNoisyReceiver();
            registerReceiver(mAudioBecomingNoisyReceiver,
                    new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY));
        }
        mSuicideHandler.stop();
        mSuicideHandler.reset();
        mPluginServiceKillHandler.stop();
        mPluginServiceKillHandler.reset();
        mScrobbleHandler.start();
        mPlayState = PlaybackStateCompat.STATE_PLAYING;
        handlePlayState();

        tryToGetAudioFocus();
        updateMediaPlayState();
        mNotification.startNotification();
    }
}

From source file:mp.teardrop.PlaybackService.java

@Override
public void onCreate() {
    HandlerThread thread = new HandlerThread("PlaybackService", Process.THREAD_PRIORITY_DEFAULT);
    thread.start();/*from   w  ww .j a  v a  2 s . c o m*/

    mTimeline = new SongTimeline(this);
    mTimeline.setCallback(this);
    int state = loadState();

    mPlayCounts = new PlayCountsHelper(this);

    mMediaPlayer = getNewMediaPlayer();
    mBastpUtil = new BastpUtil();
    mReadahead = new ReadaheadThread();
    mReadahead.start();

    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);

    SharedPreferences settings = getSettings(this);
    settings.registerOnSharedPreferenceChangeListener(this);
    mNotificationMode = Integer.parseInt(settings.getString(PrefKeys.NOTIFICATION_MODE, "1"));
    mScrobble = settings.getBoolean(PrefKeys.SCROBBLE, false);
    mIdleTimeout = settings.getBoolean(PrefKeys.USE_IDLE_TIMEOUT, false)
            ? settings.getInt(PrefKeys.IDLE_TIMEOUT, 3600)
            : 0;

    Song.mCoverLoadMode = settings.getBoolean(PrefKeys.COVERLOADER_ANDROID, true)
            ? Song.mCoverLoadMode | Song.COVER_MODE_ANDROID
            : Song.mCoverLoadMode & ~(Song.COVER_MODE_ANDROID);
    Song.mCoverLoadMode = settings.getBoolean(PrefKeys.COVERLOADER_VANILLA, true)
            ? Song.mCoverLoadMode | Song.COVER_MODE_VANILLA
            : Song.mCoverLoadMode & ~(Song.COVER_MODE_VANILLA);
    Song.mCoverLoadMode = settings.getBoolean(PrefKeys.COVERLOADER_SHADOW, true)
            ? Song.mCoverLoadMode | Song.COVER_MODE_SHADOW
            : Song.mCoverLoadMode & ~(Song.COVER_MODE_SHADOW);

    mHeadsetOnly = settings.getBoolean(PrefKeys.HEADSET_ONLY, false);
    mStockBroadcast = settings.getBoolean(PrefKeys.STOCK_BROADCAST, false);
    mInvertNotification = settings.getBoolean(PrefKeys.NOTIFICATION_INVERTED_COLOR, false);
    mNotificationAction = createNotificationAction(settings);
    mHeadsetPause = getSettings(this).getBoolean(PrefKeys.HEADSET_PAUSE, true);
    mShakeAction = settings.getBoolean(PrefKeys.ENABLE_SHAKE, false)
            ? Action.getAction(settings, PrefKeys.SHAKE_ACTION, Action.NextSong)
            : Action.Nothing;
    mShakeThreshold = settings.getInt(PrefKeys.SHAKE_THRESHOLD, 80) / 10.0f;

    mReplayGainTrackEnabled = settings.getBoolean(PrefKeys.ENABLE_TRACK_REPLAYGAIN, false);
    mReplayGainAlbumEnabled = settings.getBoolean(PrefKeys.ENABLE_ALBUM_REPLAYGAIN, false);
    mReplayGainBump = settings.getInt(PrefKeys.REPLAYGAIN_BUMP, 75); /* seek bar is 150 -> 75 == middle == 0 */
    mReplayGainUntaggedDeBump = settings.getInt(PrefKeys.REPLAYGAIN_UNTAGGED_DEBUMP,
            150); /* seek bar is 150 -> == 0 */

    mReadaheadEnabled = settings.getBoolean(PrefKeys.ENABLE_READAHEAD, false);

    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "TeardropMusicLock");

    mReceiver = new Receiver();
    IntentFilter filter = new IntentFilter();
    filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
    filter.addAction(Intent.ACTION_SCREEN_ON);
    registerReceiver(mReceiver, filter);

    getContentResolver().registerContentObserver(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mObserver);

    CompatIcs.registerRemote(this, mAudioManager);

    mLooper = thread.getLooper();
    mHandler = new Handler(mLooper, this);

    initWidgets();

    updateState(state);
    setCurrentSong(0, false);

    sInstance = this;
    synchronized (sWait) {
        sWait.notifyAll();
    }

    mAccelFiltered = 0.0f;
    mAccelLast = SensorManager.GRAVITY_EARTH;
    setupSensor();
}

From source file:com.mine.psf.PsfPlaybackService.java

private void registerNoisyListener() {
    if (mNoisyReceiver == null) {
        mNoisyReceiver = new BroadcastReceiver() {
            @Override//from   w  ww  .  j a v a2  s.  c  o  m
            public void onReceive(Context context, Intent intent) {
                String action = intent.getAction();
                if (action.equals(AudioManager.ACTION_AUDIO_BECOMING_NOISY)) {
                    Log.d(LOGTAG, "To become noisy, pause");
                    pause();
                }
            }
        };
        IntentFilter filter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
        registerReceiver(mNoisyReceiver, filter);
    }
}