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.keithcassidy.finishline.HomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);

    //volume controls will adjust media playback when this app has focus
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();// getSupportActionBar();
    actionBar.setDisplayShowHomeEnabled(true);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.pinstripe_actionbar_tile));

    currentFragment = PreferencesUtils.getCurrentFragment(this);

    homeFragment = new HomeFragment();
    setupFragment1 = new SetupFragment();
    ((SetupFragment) setupFragment1).setBuoyNumber(1);
    setupFragment2 = new SetupFragment();
    ((SetupFragment) setupFragment2).setBuoyNumber(2);
    lineCrossFragment = new LineCrossingsFragment();
    mapFragment = new FinishLineMapFragment();

    // Create the adapter that will return a fragment for each of the 
    // primary sections of the app.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setCurrentItem(currentFragment);

    mIndicator = (TitlePageIndicator) findViewById(R.id.indicator);
    mIndicator.setViewPager(mViewPager);

    mIndicator.setClipPadding(-10);//from  w w w. j  a va  2s  .  c  o m
    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    mIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            try {
                currentFragment = position;
                //               PreferencesUtils.setCurrentFragment(context, currentFragment);

                TabFocusInterface frag = (TabFocusInterface) mSectionsPagerAdapter.getItem(position);
                frag.tabSetFocus();

                if (lastPosition != -1) {
                    frag = (TabFocusInterface) mSectionsPagerAdapter.getItem(lastPosition);
                    frag.tabLoseFocus();
                }

                lastPosition = position;
            } catch (Exception e) {
                Log.e(TAG, "onPageSelected " + e);
            }

        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }
    });

    LocalBroadcastManager.getInstance(this).registerReceiver(onBroadcastServiceStatusReceived,
            new IntentFilter(Constants.SERVICE_STATUS_MESSAGE));

    new SimpleEula(this).show();
}

From source file:com.frostwire.android.gui.activities.AudioPlayerActivity.java

/**
 * {@inheritDoc}//from ww w.j  a  va  2s  .  c  om
 */
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // 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);

    // Initialize the image fetcher/cache
    mImageFetcher = ImageFetcher.getInstance(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
    setTitle(R.string.now_playing);
    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowHomeEnabled(false);

    // Set the layout
    setContentView(R.layout.activity_player_base);

    // Cache all the items
    initPlaybackControls();

    initGestures();
    mPlayPauseButton.setOnLongClickListener(new StopListener(this));

    initSupportFrostWire();
}

From source file:edu.pitt.gis.uniapp.UniApp.java

/**
 * Called when the activity is first created.
 *
 * @param savedInstanceState/*from   www .ja  v a 2s  .  c o  m*/
 */
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
    //preferences = new PreferenceSet();

    LOG.d(TAG, "UniApp.onCreate()");
    super.onCreate(savedInstanceState);

    // Get some configs: fullscreen,
    if (this.getBooleanProperty("setFullscreen", false)) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    } else {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    }

    // Custom title for UniApp
    this.customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

    setContentView(R.layout.uni_app);
    this.root = (LinearLayout) findViewById(R.id.uniappLayout);

    // Setup the hardware volume controls to handle volume control
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    this.loadUrl(HOME_URL);
}

From source file:io.radio.streamer.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Allow keys to change volume without playing
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    audioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);

    // Initialize Remote Controls if SDK Version >=14
    initializeRemoteControls();//w  w  w . ja v  a 2  s  .  com

    initializeVariables();
    initializeSideBar();

    updateApiData();

    // first page in the menu (homepage) on first load
    if (savedInstanceState == null) {
        selectItem(0);
    }

    // Get the fxView
    fxView = (FXView) findViewById(R.id.audioFxView);

    apiTimer = new Timer();
    apiTimer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            try {
                updateApiData();
            } catch (Exception e) {
                Log.e("api", "exception", e);
            }
        }
    }, 0, 10000);

    progressTimer = new Timer();
    progressTimer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            try {
                Message m = new Message();
                m.what = Util.PROGRESSUPDATE;

                mMessenger.send(m);

            } catch (Exception e) {
                Log.e("api", "exception", e);
            }
        }
    }, 0, 1000);
}

From source file:com.android.music.MusicBrowserActivity.java

public void onCreateContinue(Bundle savedInstanceState) {
    MusicLogUtils.d(TAG, "onCreate");
    ActionBar actionBar = getActionBar();
    actionBar.hide();//from   w  w w. j  av a  2s.c  o m

    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    PDebug.Start("MusicBrowserActivity.bindToService()");
    mToken = MusicUtils.bindToService(this, this);
    PDebug.End("MusicBrowserActivity.bindToService()");

    mMusicPlugin = Extensions.getPluginObject(getApplicationContext());

    mHasMenukey = ViewConfiguration.get(this).hasPermanentMenuKey();
    PDebug.Start("MusicBrowserActivity.dispatchCreate()");
    mActivityManager = new LocalActivityManager(this, false);
    mActivityManager.dispatchCreate(savedInstanceState);
    PDebug.End("MusicBrowserActivity.dispatchCreate()");

    mTabHost = getTabHost();
    PDebug.Start("MusicBrowserActivity.initTab()");
    initTab();
    PDebug.End("MusicBrowserActivity.initTab()");

    PDebug.Start("MusicBrowserActivity.setCurrentTab()");
    mCurrentTab = MusicUtils.getIntPref(this, SAVE_TAB, ARTIST_INDEX);
    MusicLogUtils.d(TAG, "onCreate mCurrentTab: " + mCurrentTab);
    if ((mCurrentTab < 0) || (mCurrentTab >= mTabCount)) {
        mCurrentTab = ARTIST_INDEX;
    }
    /// M: reset the defalt tab value
    if (mCurrentTab == ARTIST_INDEX) {
        mTabHost.setCurrentTab(ALBUM_INDEX);
    }
    mTabHost.setOnTabChangedListener(this);
    PDebug.End("MusicBrowserActivity.setCurrentTab()");

    PDebug.Start("MusicBrowserActivity.initPager()");
    initPager();
    PDebug.End("MusicBrowserActivity.initPager()");

    PDebug.Start("MusicBrowserActivity.setAdapter()");
    mViewPager = (ViewPager) findViewById(R.id.viewpage);
    mViewPager.setAdapter(new MusicPagerAdapter());
    mViewPager.setOnPageChangeListener(this);
    //mViewPager.setOffscreenPageLimit(VIEW_PAGER_OFFSCREEN_PAGE_NUM);
    PDebug.End("MusicBrowserActivity.setAdapter()");

    IntentFilter f = new IntentFilter();
    f.addAction(MusicUtils.SDCARD_STATUS_UPDATE);
    registerReceiver(mSdcardstatustListener, f);
    createFakeMenu();
    /// M: Init search button click listener in nowplaying.
    initSearchButton();
    PDebug.End("MusicBrowserActivity.onCreate");
}

From source file:org.freelectron.leobel.testlwa.models.AVSAudioPlayer.java

public AVSAudioPlayer(AudioManager audioManager, AVSController controller) {
    this.audioManager = audioManager;
    this.controller = controller;
    resLoader = Thread.currentThread().getContextClassLoader();
    timer = new AudioPlayerTimer();
    waitForPlaybackFinished = false;//from  w  ww  . ja v  a 2s  .c  o  m
    playQueue = new LinkedList<Stream>();
    speakQueue = new LinkedList<SpeakItem>();
    streamUrls = new HashSet<String>();
    attemptedUrls = new HashSet<String>();
    cachedAudioFiles = new HashMap<String, String>();
    setupAudioPlayer();

    currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    VOLUME_SCALAR = maxVolume / VOLUME_SCALAR;
    currentlyMuted = currentVolume == 0;

    audioPlayerStateMachine = new AudioPlayerStateMachine(this, controller);

    progressReporter = new AudioPlayerProgressReporter(
            new ProgressReportDelayEventRunnable(audioPlayerStateMachine),
            new ProgressReportIntervalEventRunnable(audioPlayerStateMachine), timer);

    listeners = new HashSet<>();
}

From source file:com.sourceauditor.sahomemonitor.MainActivity.java

private void playAudio() {
    if (audioPlayer == null) {
        audioPlayer = new MediaPlayer();
        audioPlayer.setOnPreparedListener(this);
        audioPlayer.setOnBufferingUpdateListener(this);
        audioPlayer.setOnErrorListener(this);
    } else {/*from ww w.  j  a  v a  2 s .  co  m*/
        audioPlayer.stop();
        audioPlayer.reset();
    }
    try {
        audioPlayer.setDataSource(this, getAudioUri());
        audioPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        int result = audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC,
                AudioManager.AUDIOFOCUS_GAIN);
        if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
            logAndDisplayError("Audio in use by another app");
        } else {
            pauseBeforePlaying = false;
            audioPlayer.prepareAsync();
        }
    } catch (IllegalArgumentException e) {
        logAndDisplayError("Illegal argument for audioPlayer");
    } catch (SecurityException e) {
        logAndDisplayError("Security error for audioPlayer");
    } catch (IllegalStateException e) {
        logAndDisplayError("Illegal state exception for audioPlayer");
    } catch (IOException e) {
        logAndDisplayError("IO Error for audio player: " + e.getMessage());
    }
}

From source file:com.bczm.widgetcollections.player.MusicPlayer.java

private void preparedMusic(int index) {
    if (mPLayMode == MusicPlayState.MPS_LIST_EMPTY || index < 0 || index >= getMusicListCount()) {
        return;/* ww w. j a  v  a  2s  .  c  om*/
    }

    mCurPlayIndex = index;

    mMediaPlayer.reset();
    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

    String dataSource = mMusicList.get(mCurPlayIndex).getUrl();
    try {
        mMediaPlayer.setDataSource(dataSource);
        mMediaPlayer.prepareAsync();
        mPlayState = MusicPlayState.MPS_PREPARED;
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:name.vdg.respi55.RespiStateManager.java

public void setAudioFocus(Activity a) {
    // Hardware buttons setting to adjust the media sound
    a.setVolumeControlStream(AudioManager.STREAM_MUSIC);
    // Request audio focus depending on sound mode & started state
    mRespiSound.updateSoundMode(mSoundMode);
}