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:it.unicaradio.android.activities.MainActivity.java

/**
 * {@inheritDoc}/*from  w ww .jav  a2  s.  com*/
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_layout);

    initGcm();
    initView();

    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    preferences = getPreferences(Context.MODE_PRIVATE);
    if (isFirstRun()) {
        PreferenceManager.setDefaultValues(this, R.xml.prefs, true);
    }
    if (hasBeenUpdated()) {
        showUpdatesDialog();
    }

    setupUpdatesChecker();
}

From source file:com.kentli.cycletrack.RecordingService.java

@Override
public void onCreate() {
    super.onCreate();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        AudioAttributes attributes = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_GAME)
                .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build();

        soundpool = new SoundPool.Builder().setAudioAttributes(attributes).build();
    } else {//w w  w  .  ja v a 2s . c  o m
        soundpool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
    }
    soundpool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
        @Override
        public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
            soundPool.play(sampleId, 1.0f, 1.0f, 0, 0, 1.0f);
        }
    });
    bikebell = soundpool.load(this.getBaseContext(), R.raw.bikebell, 1);
}

From source file:com.wikitude.example.ARBrowserActivity.java

/** Called when the activity is first created. */
@Override//from   w  ww .j a va  2 s . c om
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // let the application be fullscreen
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    // check if the device fulfills the SDK'S minimum requirements
    if (!ArchitectView.isDeviceSupported(this)) {
        Toast.makeText(this, "minimum requirements not fulfilled", Toast.LENGTH_LONG).show();
        this.finish();
        return;
    }
    setContentView(R.layout.main);

    // set the devices' volume control to music to be able to change the
    // volume of possible soundfiles to play
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
    this.architectView = (ArchitectView) this.findViewById(R.id.architectView);
    // onCreate method for setting the license key for the SDK
    architectView.onCreate(apiKey);

    // in order to inform the ARchitect framework about the user's location
    // Androids LocationManager is used in this case
    // NOT USED IN THIS EXAMPLE
    // locManager =
    // (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    // locManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0,
    // 0, this);

    // Getting LocationManager object from System Service LOCATION_SERVICE
    LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

    // Creating a criteria object to retrieve provider
    Criteria criteria = new Criteria();

    // Getting the name of the best provider
    String provider = locationManager.getBestProvider(criteria, true);

    // Getting Current Location
    Location location = locationManager.getLastKnownLocation(provider);

    locationManager.requestLocationUpdates(provider, 20000, 0, this);

    // Getting latitude of the current location
    fLat = location.getLatitude();

    // Getting longitude of the current location
    fLng = location.getLongitude();

}

From source file:com.google.sample.aaudio.echo.MainActivity.java

@Override
protected void onStart() {
    super.onStart();
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
}

From source file:com.stillnojetpacks.huffr.activities.MainActivity.java

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

    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    initializeToolbar();/*from www.j  a  v a2s . c  o m*/

    initializeSprayButton();

    sensorsInitialized = false;
}

From source file:org.chirpradio.mobile.PlaybackService.java

@Override
public void onCreate() {
    Debug.log(this, "created");
    mediaPlayer = new MediaPlayer();
    mediaPlayer.setOnPreparedListener(this);
    mediaPlayer.setOnErrorListener(this);
    mediaPlayer.setOnCompletionListener(this);

    String playbackUrl;//from   w w w . ja v  a 2s.com
    playbackUrl = STREAM_URL;

    try {
        mediaPlayer.setDataSource(playbackUrl);
    } catch (IOException e) {
        e.printStackTrace();
    }
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    setupTelephonyHooks();

    // the headphone action gets called every time we get a start
    // message, i guess so i know the headphone state all the time.
    // so, i can assume there are no headphones plugged in, and the
    // broadcast receiver will set it to true if there are when
    // it gets notified the first time
    headphonesInUse = false;
}

From source file:com.android.music.ArtistAlbumBrowserFragment.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_expanding, null);
    getActivity().setVolumeControlStream(AudioManager.STREAM_MUSIC);
    mToken = MusicUtils.bindToService(getActivity(), this);

    if (savedInstanceState != null) {
        mCurrentAlbumId = savedInstanceState.getString("selectedalbum");
        mCurrentAlbumName = savedInstanceState.getString("selectedalbumname");
        mCurrentArtistId = savedInstanceState.getString("selectedartist");
        mCurrentArtistName = savedInstanceState.getString("selectedartistname");
    }/* www .  j  av  a  2  s .  c  o m*/

    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 = (ExpandableListView) view.findViewById(android.R.id.list);

    mAdapter = (ArtistAlbumListAdapter) getActivity().getLastNonConfigurationInstance();
    if (mAdapter == null) {
        //Log.i("@@@", "starting query");
        mAdapter = new ArtistAlbumListAdapter(getActivity().getApplication(), this, null, // cursor
                R.layout.track_list_item_group, new String[] {}, new int[] {}, R.layout.track_list_item_child,
                new String[] {}, new int[] {});
        lv.setAdapter(mAdapter);
        getArtistCursor(mAdapter.getQueryHandler(), null);
    } else {
        mAdapter.setActivity(this);
        lv.setAdapter(mAdapter);
        mArtistCursor = mAdapter.getCursor();
        if (mArtistCursor != null) {
            init(mArtistCursor);
        } else {
            getArtistCursor(mAdapter.getQueryHandler(), null);
        }
    }

    lv.setOnCreateContextMenuListener(this);
    lv.setOnChildClickListener(this);
    lv.setTextFilterEnabled(true);

    return view;
}

From source file:fi.mikuz.boarder.gui.internet.DownloadBoardComments.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.internet_download_comments_list);
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
    registerForContextMenu(getListView());

    Bundle extras = getIntent().getExtras();
    XStream xstream = new XStream();
    mBoard = (InternetFullBoard) xstream.fromXML(extras.getString(DownloadBoard.BOARD_KEY));
    mLoggedIn = extras.getBoolean(DownloadBoardList.LOGGED_IN_KEY);

    if (mLoggedIn) {
        mUserId = extras.getString(InternetMenu.USER_ID_KEY);
        mSessionToken = extras.getString(InternetMenu.SESSION_TOKEN_KEY);
    }/*from  www.  ja  v a  2s  .c  om*/

    this.setTitle(mBoard.getUploaderUsername() + " - " + mBoard.getBoardName());

    mListView = (ListView) findViewById(android.R.id.list);
    mList = new ArrayList<Comment>();
    mMaxResults = 40;
    refreshList();

    Button sendComment = (Button) findViewById(R.id.sendComment);
    final EditText commentInput = (EditText) findViewById(R.id.commentInput);

    if (mLoggedIn) {
        sendComment.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                if (commentInput.getText().toString().length() > 0) {
                    mWaitDialog = new TimeoutProgressDialog(DownloadBoardComments.this, "Waiting for response",
                            TAG, false);
                    HashMap<String, String> sendList = new HashMap<String, String>();
                    sendList.put(InternetMenu.BOARD_ID_KEY, Integer.toString(mBoard.getBoardId()));
                    sendList.put(InternetMenu.SESSION_TOKEN_KEY, mSessionToken);
                    sendList.put(InternetMenu.USER_ID_KEY, mUserId);
                    sendList.put(InternetMenu.COMMENT_KEY, commentInput.getText().toString());
                    commentInput.setText("");
                    new ConnectionManager(DownloadBoardComments.this, InternetMenu.mCommentURL, sendList);
                } else {
                    Toast.makeText(DownloadBoardComments.this, "Type your comment...", Toast.LENGTH_LONG)
                            .show();
                }
            }
        });
    } else {
        commentInput.setHint("Login to comment");
        commentInput.setFocusable(false);
    }

    getListView().setOnScrollListener(this);
}

From source file:com.xamoom.android.xamoomcontentblocks.ViewHolders.ContentBlock1ViewHolder.java

private void setupMusicPlayer(final Uri fileUrl) {
    if (mMediaPlayer == null) {
        mMediaPlayer = new MediaPlayer();

        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        try {/*from  w ww  .  j a  v  a  2s.  c  o  m*/
            mMediaPlayer.setDataSource(mFragment.getActivity(), fileUrl);
            mMediaPlayer.prepareAsync();
        } catch (IOException e) {
            e.printStackTrace();
        }

        mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                mSongProgressBar.setMax(mMediaPlayer.getDuration());
                mRemainingSongTimeTextView.setText(getTimeString(mMediaPlayer.getDuration()));

                mPlayPauseButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (mMediaPlayer.isPlaying()) {
                            mMediaPlayer.pause();
                            mPlayPauseButton.setBackgroundResource(R.drawable.ic_play);
                        } else {
                            mMediaPlayer.start();
                            mPlayPauseButton.setBackgroundResource(R.drawable.ic_pause);
                            startUpdatingProgress();
                        }
                    }
                });

                mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                    @Override
                    public void onCompletion(MediaPlayer mp) {
                        stopUpdatingProgress();
                        if (mFragment.getActivity() != null) {
                            setupMusicPlayer(fileUrl);
                        }
                    }
                });
            }
        });
    }
}

From source file:nl.vincentketelaars.mexen.activities.RollDice.java

/** Called when the activity is first created. */
@Override// w  w  w.j  av a2s .c o  m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Make title bar icon clickable, and go home
    getActionBar().setDisplayHomeAsUpEnabled(true);

    setVolumeControlStream(AudioManager.STREAM_MUSIC); // User can modify music volume
    soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
    soundMap = new SparseIntArray();
    soundMap.put(R.raw.roll, soundPool.load(this, R.raw.roll, 1)); // Note: If load returns 0 it failed

    activity = this;

    currentGame = new Game(currentMode);

    MGDbHelper = new MexGameDbHelper(this);

    sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

    getActionBar().setTitle(String.format(getResources().getString(R.string.roll_activity_name), numDice()));
}