List of usage examples for android.media AudioManager STREAM_MUSIC
int STREAM_MUSIC
To view the source code for android.media AudioManager STREAM_MUSIC.
Click Source Link
From source file:com.google.android.apps.forscience.whistlepunk.metadata.TriggerHelper.java
public void doAudioAlert(Context context) { // Use a throttler to keep this from interrupting itself too much. if (System.currentTimeMillis() - mLastAudioMs < THROTTLE_LIMIT_MS) { return;/*from w w w . jav a2s . com*/ } mLastAudioMs = System.currentTimeMillis(); final MediaPlayer mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); try { mediaPlayer.setDataSource(context, mNotification); mediaPlayer.setOnPreparedListener(MEDIA_PLAYER_ON_PREPARED_LISTENER); mediaPlayer.setOnCompletionListener(MEDIA_PLAYER_COMPLETION_LISTENER); // Don't prepare the mediaplayer on the UI thread! That's asking for trouble. mediaPlayer.prepareAsync(); } catch (IOException e) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "error getting notification sound"); } } }
From source file:com.sinelead.car.club.map.NaviMarkerFragmentBottom.java
private void init() { getCurrentlatlng();//from w w w . j a v a 2 s. c om Bundle bundle = this.getArguments(); if (bundle != null) { PoiItem poiItem = (PoiItem) bundle.getParcelable("poiItem"); setValues(poiItem); } naviBotton = mView.findViewById(R.id.layout_nav); naviBotton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { getActivity().setVolumeControlStream(AudioManager.STREAM_MUSIC);// TTSController ttsManager = TTSController.getInstance(getActivity());// ttsManager.init(); AMapNavi aMapNavi = AMapNavi.getInstance(getActivity()); aMapNavi.setAMapNaviListener(ttsManager);// if (aMapNavi.calculateDriveRoute(getStartPoints(), getEndPoints(), null, AMapNavi.DrivingDefault)) { Intent naviIntent = new Intent(getActivity(), NaviCustomActivity.class); startActivity(naviIntent); } else { ToastUtils.show(getActivity(), "!"); } } }); }
From source file:fi.mikuz.boarder.gui.internet.Settings.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.internet_settings); this.setVolumeControlStream(AudioManager.STREAM_MUSIC); @SuppressWarnings("unchecked") HashMap<String, String> lastSession = (HashMap<String, String>) getIntent() .getSerializableExtra(InternetMenu.LOGIN_KEY); try {/*from w w w .j a v a 2s . c o m*/ mUserId = lastSession.get(InternetMenu.USER_ID_KEY); mSessionToken = lastSession.get(InternetMenu.SESSION_TOKEN_KEY); } catch (NullPointerException e) { Toast.makeText(Settings.this, "Please login", Toast.LENGTH_LONG).show(); Settings.this.finish(); } Button changePassword = (Button) findViewById(R.id.change_password); changePassword.setOnClickListener(new OnClickListener() { public void onClick(View v) { LayoutInflater inflater = (LayoutInflater) Settings.this.getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.internet_settings_alert_change_password, (ViewGroup) findViewById(R.id.alert_settings_root)); final EditText oldPasswordInput = (EditText) layout.findViewById(R.id.oldPasswordInput); final EditText newPassword1Input = (EditText) layout.findViewById(R.id.newPassword1Input); final EditText newPassword2Input = (EditText) layout.findViewById(R.id.newPassword2Input); Button submitButton = (Button) layout.findViewById(R.id.submitButton); AlertDialog.Builder builder = new AlertDialog.Builder(Settings.this); builder.setView(layout); builder.setTitle("Change password"); submitButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { String oldPasswordText = oldPasswordInput.getText().toString(); String newPassword1Text = newPassword1Input.getText().toString(); String newPassword2Text = newPassword2Input.getText().toString(); if (!newPassword1Text.equals(newPassword2Text)) { Toast.makeText(Settings.this, "New passwords don't match", Toast.LENGTH_LONG).show(); } else if (newPassword1Text.length() < 6) { Toast.makeText(Settings.this, "Password length must be at least 6 characters", Toast.LENGTH_LONG).show(); } else { try { mWaitDialog = new TimeoutProgressDialog(Settings.this, "Waiting for response", TAG, false); HashMap<String, String> sendList = new HashMap<String, String>(); sendList.put(InternetMenu.PASSWORD_KEY, Security.passwordHash(newPassword1Text)); sendList.put(InternetMenu.OLD_PASSWORD_KEY, Security.passwordHash(oldPasswordText)); sendList.put(InternetMenu.USER_ID_KEY, mUserId); sendList.put(InternetMenu.SESSION_TOKEN_KEY, mSessionToken); new ConnectionManager(Settings.this, InternetMenu.mChangePasswordURL, sendList); } catch (NoSuchAlgorithmException e) { mWaitDialog.dismiss(); String msg = "Couldn't make md5 hash"; Toast.makeText(Settings.this, msg, Toast.LENGTH_LONG).show(); Log.e(TAG, msg, e); } } } }); builder.show(); } }); Button changeEmail = (Button) findViewById(R.id.change_email); changeEmail.setOnClickListener(new OnClickListener() { public void onClick(View v) { LayoutInflater inflater = (LayoutInflater) Settings.this.getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.internet_settings_alert_change_email, (ViewGroup) findViewById(R.id.alert_settings_root)); final EditText passwordInput = (EditText) layout.findViewById(R.id.passwordInput); final EditText newEmailInput = (EditText) layout.findViewById(R.id.newEmailInput); Button submitButton = (Button) layout.findViewById(R.id.submitButton); AlertDialog.Builder builder = new AlertDialog.Builder(Settings.this); builder.setView(layout); builder.setTitle("Change email"); submitButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { String passwordText = passwordInput.getText().toString(); String newEmailText = newEmailInput.getText().toString(); try { mWaitDialog = new TimeoutProgressDialog(Settings.this, "Waiting for response", TAG, false); HashMap<String, String> sendList = new HashMap<String, String>(); sendList.put(InternetMenu.PASSWORD_KEY, Security.passwordHash(passwordText)); sendList.put(InternetMenu.EMAIL_KEY, newEmailText); sendList.put(InternetMenu.USER_ID_KEY, mUserId); sendList.put(InternetMenu.SESSION_TOKEN_KEY, mSessionToken); new ConnectionManager(Settings.this, InternetMenu.mChangeEmailURL, sendList); } catch (NoSuchAlgorithmException e) { mWaitDialog.dismiss(); String msg = "Couldn't make md5 hash"; Toast.makeText(Settings.this, msg, Toast.LENGTH_LONG).show(); Log.e(TAG, msg, e); } } }); builder.show(); } }); }
From source file:com.aps490.drdc.prototype.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* pressing volume up/down should cause music volume changes */ this.setVolumeControlStream(AudioManager.STREAM_MUSIC); initNativeLib(getApplicationContext()); setContentView(R.layout.activity_main); this.setTitle(getActivityTitle()); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*from w ww .jav a2 s . c o m*/ /** //Commenting out until we want on-screen button(s) FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); */ DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); try { // Architectview setup this.architectView = (ArchitectView) this.findViewById(getArchitectViewId()); this.architectView.onCreate(getWikitudeSDKLicenseKey()); } catch (RuntimeException rex) { this.architectView = null; Toast.makeText(getApplicationContext(), "can't create Architect View", Toast.LENGTH_SHORT).show(); Log.e(this.getClass().getName(), "Exception in ArchitectView.onCreate()", rex); } // set accuracy listener if implemented, you may e.g. show calibration prompt for compass using this listener this.sensorAccuracyListener = this.getSensorAccuracyListener(); // set urlListener, any calls made in JS like "document.location = 'architectsdk://foo?bar=123'" is forwarded to this listener, use this to interact between JS and native Android activity/fragment this.urlListener = this.getUrlListener(); // register valid urlListener in architectView, ensure this is set before content is loaded to not miss any event if (this.urlListener != null && this.architectView != null) { this.architectView.registerUrlListener(this.getUrlListener()); } }
From source file:com.darly.im.ui.CCPActivityBase.java
public void init(Context context, FragmentActivity activity) { mActionBarActivity = activity;/*from ww w .j av a 2 s . co m*/ onInit(); mAudioManager = AudioManagerTools.getInstance().getAudioManager(); mMusicMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); int layoutId = getLayoutId(); mLayoutInflater = LayoutInflater.from(mActionBarActivity); mBaseLayoutView = mLayoutInflater.inflate(R.layout.ccp_activity, null); mTransLayerView = mBaseLayoutView.findViewById(R.id.ccp_trans_layer); LinearLayout mRootView = (LinearLayout) mBaseLayoutView.findViewById(R.id.ccp_root_view); mContentFrameLayout = (FrameLayout) mBaseLayoutView.findViewById(R.id.ccp_content_fl); if (getTitleLayout() != -1) { mTopBarView = mLayoutInflater.inflate(getTitleLayout(), null); mRootView.addView(mTopBarView, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); } if (layoutId != -1) { mContentView = getContentLayoutView(); if (mContentView == null) { mContentView = mLayoutInflater.inflate(getLayoutId(), null); } mRootView.addView(mContentView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); } dealContentView(mBaseLayoutView); CCPLayoutListenerView listenerView = (CCPLayoutListenerView) mActionBarActivity .findViewById(R.id.ccp_content_fl); if (listenerView != null && mActionBarActivity.getWindow() .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) { listenerView.setOnSizeChangedListener(new CCPLayoutListenerView.OnCCPViewSizeChangedListener() { @Override public void onSizeChanged(int w, int h, int oldw, int oldh) { LogUtil.d(LogUtil.getLogUtilsTag(getClass()), "oldh - h = " + (oldh - h)); } }); } }
From source file:com.musiqueplayer.playlistequalizerandroidwear.activities.BaseActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mToken = MusicPlayer.bindToService(this, this); AppRater.app_launched(this); mPlaybackStatus = new PlaybackStatus(this); //make volume keys change multimedia volume even if music is not playing now setVolumeControlStream(AudioManager.STREAM_MUSIC); }
From source file:ca.rmen.android.palidamuerte.app.poem.list.PoemListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { Log.v(TAG, "onCreate"); super.onCreate(savedInstanceState); setContentView(R.layout.activity_poem_list); // Show the Up button in the action bar. getActionBar().setDisplayHomeAsUpEnabled(true); setVolumeControlStream(AudioManager.STREAM_MUSIC); if (findViewById(R.id.poem_detail_container) != null) { // The detail container view will be present only in the // large-screen layouts (res/values-large and // res/values-sw600dp). If this view is present, then the // activity should be in two-pane mode. mTwoPane = true;/* w w w. j a v a 2 s.c o m*/ // In two-pane mode, list items should be given the // 'activated' state when touched. ((PoemListFragment) getSupportFragmentManager().findFragmentById(R.id.poem_list)) .setActivateOnItemClick(true); } ActionBar.setCustomFont(this); }
From source file:com.morphoss.jumble.frontend.SettingsActivity.java
/** * This methods controls the audio/*from w ww. ja v a2 s.co m*/ */ private void initControls() { setVolumeControlStream(AudioManager.STREAM_MUSIC); setContentView(R.layout.activity_settings); try { volumeSeekbar = (SeekBar) findViewById(R.id.seekBar1); audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); volumeSeekbar.setMax(audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC)); volumeSeekbar.setProgress(audioManager.getStreamVolume(AudioManager.STREAM_MUSIC)); volumeSeekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar bar) { } @Override public void onStartTrackingTouch(SeekBar bar) { } @Override public void onProgressChanged(SeekBar bar, int paramInt, boolean paramBoolean) { audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, paramInt, 0); } }); btnreset = (Button) findViewById(R.id.reset); btnreset.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { deleteWords(); deleteKnownCategories(); } }); enFlag = (ImageView) findViewById(R.id.enFlag); enFlag.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setLanguage("en"); } }); frFlag = (ImageView) findViewById(R.id.frFlag); frFlag.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setLanguage("fr"); } }); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.chromium.tools.audio_focus_grabber.AudioFocusGrabberListenerService.java
void gainFocusAndPlay(int focusType) { int result = mAudioManager.requestAudioFocus(mOnAudioFocusChangeListener, AudioManager.STREAM_MUSIC, focusType);//from www . j av a2 s. co m if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { playSound(); } else { Log.i(TAG, "cannot request audio focus"); } }
From source file:com.billooms.harppedals.HarpPedalsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { // Log.d(TAG, "HarpPedalsActivity.onCreate"); super.onCreate(savedInstanceState); setVolumeControlStream(AudioManager.STREAM_MUSIC); dialogBuilder = new AlertDialog.Builder(this); dialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override// w w w . ja v a 2s . c o m public void onClick(DialogInterface dialog, int which) { // don't do anything except close the dialog } }); // This will be either the standard (small) layout or the large layout setContentView(R.layout.activity_main); // Check that the activity is using the standard (small) layout version with the 'fragment_container' FrameLayout if (findViewById(R.id.fragment_container) != null) { // Gesture Detector to detect horizontal swipes if (gDetector == null) { gDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() { @Override public boolean onFling(MotionEvent start, MotionEvent finish, float xVelocity, float yVelocity) { if ((finish == null) || (start == null)) { // not sure why, but the float dx = gives null pointer error sometimes return false; } Fragment swipeFragment = getSupportFragmentManager().findFragmentByTag(NO_SWIPE); if (swipeFragment == null) { // only process swipes in one-pane PedalFragments float dx = finish.getRawX() - start.getRawX(); float dy = finish.getRawY() - start.getRawY(); if (Math.abs(dy) < Math.abs(dx)) { // horizontal if (dx < 0) { // swipe toward the left for KeySignature launchKeyFragment(); } else { // swipe toward the right for Chord launchChordFragment(); } } return true; // gesture has been consumed } return false; // don't process swipes if we're not in a one-pane PedalFragment } }); } // If we're being restored from a previous state, // then we don't need to do anything and should return or else // we could end up with overlapping fragments. if (savedInstanceState != null) { return; } // Create a new PedalFragment to be placed in the activity layout PedalFragment pedalFragment = new PedalFragment(); // Add the fragment to the 'fragment_container' FrameLayout getSupportFragmentManager().beginTransaction() .add(R.id.fragment_container, pedalFragment, TAG_PEDAL_FRAG).commit(); } }