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.android.music.AlbumBrowserFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    View view = inflater.inflate(R.layout.media_picker_activity, null);

    if (savedInstanceState != null) {
        mCurrentAlbumId = savedInstanceState.getString("selectedalbum");
        mArtistId = savedInstanceState.getString("artist");
    } else {/*from   ww w  .ja  va 2s  . c  o  m*/
        mArtistId = getActivity().getIntent().getStringExtra("artist");
    }

    //getActivity().requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    //requestWindowFeature(Window.FEATURE_NO_TITLE);
    getActivity().setVolumeControlStream(AudioManager.STREAM_MUSIC);
    mToken = MusicUtils.bindToService(getActivity(), this);

    IntentFilter f = new IntentFilter();
    f.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);
    f.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
    f.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    f.addDataScheme("file");
    getActivity().registerReceiver(mScanListener, f);

    lv = (ListView) view.findViewById(android.R.id.list);
    lv.setOnCreateContextMenuListener(this);
    lv.setTextFilterEnabled(true);
    lv.setOnItemClickListener(this);

    mAdapter = (AlbumListAdapter) getActivity().getLastNonConfigurationInstance();
    if (mAdapter == null) {
        //Log.i("@@@", "starting query");
        mAdapter = new AlbumListAdapter(getActivity().getApplication(), this, R.layout.track_list_item,
                mAlbumCursor, new String[] {}, new int[] {});
        lv.setAdapter(mAdapter);
        //getActivity().setTitle(R.string.working_albums);
        getAlbumCursor(mAdapter.getQueryHandler(), null);
    } else {
        mAdapter.setActivity(this);
        lv.setAdapter(mAdapter);
        mAlbumCursor = mAdapter.getCursor();
        if (mAlbumCursor != null) {
            init(mAlbumCursor);
        } else {
            getAlbumCursor(mAdapter.getQueryHandler(), null);
        }
    }

    return view;
}

From source file:com.example.linhdq.test.documents.viewing.single.DocumentActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    setContentView(R.layout.activity_document);
    ButterKnife.bind(this);
    if (!init(savedInstanceState)) {
        finish();/*from   ww  w.jav a2  s  .  co m*/
        return;
    }

    if (savedInstanceState == null && isStartedAfterAScan(getIntent())) {
        showResultDialog();
    }
    setDocumentFragmentType();
    initToolbar();
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    initBottomSheet();
}

From source file:com.andrew.apollo.ui.activities.BaseActivity.java

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

    // Initialze the theme resources
    mResources = new ThemeUtils(this);

    // Set the overflow style
    mResources.setOverflowStyle(this);

    // 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 broadcast receiver
    mPlaybackStatus = new PlaybackStatus(this);

    // Theme the action bar
    mResources.themeActionBar(getActionBar(), getString(R.string.app_name));

    // Set the layout
    setContentView(setContentView());

    // Initialze the bottom action bar
    initBottomActionBar();
}

From source file:com.lithiumli.fiction.FictionActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
}

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

/** Called when the activity is first created. */
@Override/*  www .java2s .  c  om*/
public void onCreate(Bundle icicle) {
    if (icicle != null) {
        mCurrentAlbumId = icicle.getString("selectedalbum");
        mArtistId = icicle.getString("artist");
    } else {
        mArtistId = getIntent().getStringExtra("artist");
    }
    super.onCreate(icicle);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    mToken = MusicUtils.bindToService(this, this);

    IntentFilter f = new IntentFilter();
    f.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);
    f.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
    f.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    f.addDataScheme("file");
    registerReceiver(mScanListener, f);

    setContentView(R.layout.media_picker_activity);
    MusicUtils.updateButtonBar(this, R.id.albumtab);
    ListView lv = getListView();
    lv.setOnCreateContextMenuListener(this);
    lv.setTextFilterEnabled(true);

    mAdapter = (AlbumListAdapter) getLastNonConfigurationInstance();
    if (mAdapter == null) {
        //Log.i("@@@", "starting query");
        mAdapter = new AlbumListAdapter(getApplication(), this, R.layout.track_list_item, mAlbumCursor,
                new String[] {}, new int[] {});
        setListAdapter(mAdapter);
        setTitle(R.string.working_albums);
        getAlbumCursor(mAdapter.getQueryHandler(), null);
    } else {
        mAdapter.setActivity(this);
        setListAdapter(mAdapter);
        mAlbumCursor = mAdapter.getCursor();
        if (mAlbumCursor != null) {
            init(mAlbumCursor);
        } else {
            getAlbumCursor(mAdapter.getQueryHandler(), null);
        }
    }

    badSymptoms = new BadSymptoms(this);
}

From source file:org.amahi.anywhere.service.AudioService.java

private void setUpAudioPlayer() {
    audioPlayer = new MediaPlayer();

    audioPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    audioPlayer.setWakeMode(this, PowerManager.PARTIAL_WAKE_LOCK);

    audioPlayer.setOnPreparedListener(this);
    audioPlayer.setOnCompletionListener(this);
    audioPlayer.setOnErrorListener(this);
}

From source file:com.shinymayhem.radiopresets.FragmentPlayer.java

public void updateSlider() {
    SeekBar volumeSlider = (SeekBar) this.getView().findViewById(R.id.volume_slider);
    AudioManager audio = (AudioManager) this.getActivity().getSystemService(Context.AUDIO_SERVICE);
    volumeSlider.setProgress(audio.getStreamVolume(AudioManager.STREAM_MUSIC));
}

From source file:com.mylovemhz.simplay.MusicService.java

private void initialize() {
    trackQueue = new ArrayList<>();

    mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnCompletionListener(this);
    mediaPlayer.setOnErrorListener(this);
    mediaPlayer.setOnPreparedListener(this);
    mediaPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
    wifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL,
            "music lock");

    ComponentName receiver = new ComponentName(getPackageName(), MediaButtonEventReceiver.class.getName());
    mediaSession = new MediaSessionCompat(this, TAG_MUSIC_SERVICE, receiver, null);
    mediaSession.setFlags(//from  w  ww .  ja  v  a2s. c o  m
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mediaSession.setCallback(new SimpleSessionCallback(this));

    currentState = State.IDLE;
    mediaSession.setActive(true);

    isInitialized = true;
    Log.d(TAG_MUSIC_SERVICE, "Initialized...");
}

From source file:org.mariotaku.harmony.activity.MusicBrowserActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    mImageLoader = HarmonyApplication.getInstance(this).getImageLoaderWrapper();
    mActionBar = getActionBar();//from w w w  .j  a v a 2 s . c om
    mActionBar.setDisplayShowTitleEnabled(false);
    //mActionBar.setDisplayShowHomeEnabled(false);
    mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    mPrefs = new PreferencesEditor(this);

    final String mount_state = Environment.getExternalStorageState();

    if (!Environment.MEDIA_MOUNTED.equals(mount_state)
            && !Environment.MEDIA_MOUNTED_READ_ONLY.equals(mount_state)) {
        startActivity(new Intent(this, ScanningProgress.class));
        finish();
    }

    setContentView(R.layout.music_browser);
    mSpinnerAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, android.R.id.text1);
    mSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mActionBar.setDisplayShowCustomEnabled(true);
    //mActionBar.setDisplayShowHomeEnabled(true);
    //mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    //mActionBar.setListNavigationCallbacks(mSpinnerAdapter, this);
    mActionBar.setCustomView(R.layout.music_browser_control_bar);
    mControlContainer = mActionBar.getCustomView();
    //mViewPager.setEnabled(false);
    mAlbumArt = (AlbumArtView) mControlContainer.findViewById(R.id.album_art);
    mTrackName = (TextView) mControlContainer.findViewById(R.id.track_name);
    mTrackDetail = (TextView) mControlContainer.findViewById(R.id.track_detail);
    mPlayPauseButton = (ImageButton) mControlContainer.findViewById(R.id.play_pause);
    mNextButton = (ImageButton) mControlContainer.findViewById(R.id.next);
    mTabsAdapter = new TabsAdapter(this);
    mViewPager.setOnPageChangeListener(this);
    mViewPager.setOffscreenPageLimit(3);
    mViewPager.setAdapter(mTabsAdapter);
    mPlayPauseButton.setOnClickListener(this);
    mNextButton.setOnClickListener(this);
    configureTabs(!mViewPager.isEnabled());
    final int currenttab = mPrefs.getIntState(STATE_KEY_PAGE_POSITION_BROWSER, 0);
    mActionBar.setSelectedNavigationItem(currenttab);
}

From source file:com.aniruddhc.acemusic.player.AsyncTasks.AsyncGetGooglePlayMusicMetadataTask.java

@Override
protected String doInBackground(String... params) {

    //Check if any music is playing and fade it out.
    am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
    if (mApp.isServiceRunning()) {

        if (mApp.getService().isPlayingMusic()) {
            targetVolume = 0;//from w ww. j  a  v a2  s .co m
            currentVolume = am.getStreamVolume(AudioManager.STREAM_MUSIC);
            while (currentVolume > targetVolume) {
                am.setStreamVolume(AudioManager.STREAM_MUSIC, (currentVolume - stepDownValue), 0);
                currentVolume = am.getStreamVolume(AudioManager.STREAM_MUSIC);

            }

            mContext.stopService(new Intent(mContext, AudioPlaybackService.class));

        }

    }

    //Check if the Google Play Music app is installed.
    PackageManager pm = mContext.getPackageManager();
    boolean installed = false;
    try {
        pm.getPackageInfo("com.google.android.music", PackageManager.GET_ACTIVITIES);
        installed = true;
    } catch (NameNotFoundException e1) {
        //The app isn't installed.
        installed = false;
    }

    String result = "GENERIC_EXCEPTION";
    if (installed == false) {
        //Can't do anything here anymore. Quit.
        mApp.getSharedPreferences().edit().putBoolean("GOOGLE_PLAY_MUSIC_ENABLED", false).commit();
        return null;
    } else {
        //Grab music metadata from Google Play Music's public content mApp.
        result = getMetadataFromGooglePlayMusicApp();
    }
    return result;
}