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.ecoplayer.beta.MusicService.java
private boolean initMediaPlayer() { startForeground(NOTIFICATION_ID, notiBuilder.getNotification()); AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE); int result = audioManager.requestAudioFocus(audioFocusChangeList, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { mMediaPlayer = new MediaPlayer(); // initialize it here mMediaPlayer.setOnPreparedListener(this); mMediaPlayer.setOnCompletionListener(onCompletion); mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); // prevent CPU from going to sleep mMediaPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK); return true; } else {/*from w w w . j a v a2s . com*/ Log.w(LOG_TAG, "The service hasn't got the audio focus"); } return false; }
From source file:com.android.music.PlaylistBrowserFragment.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); final Intent intent = getActivity().getIntent(); final String action = intent.getAction(); if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) { mCreateShortcut = true;/* w w w .j av a 2s. c o m*/ } getActivity().setVolumeControlStream(AudioManager.STREAM_MUSIC); mToken = MusicUtils.bindToService(getActivity(), new ServiceConnection() { public void onServiceConnected(ComponentName classname, IBinder obj) { if (Intent.ACTION_VIEW.equals(action)) { Bundle b = intent.getExtras(); if (b == null) { Log.w(TAG, "Unexpected:getExtras() returns null."); } else { try { long id = Long.parseLong(b.getString("playlist")); if (id == RECENTLY_ADDED_PLAYLIST) { playRecentlyAdded(); } else if (id == PODCASTS_PLAYLIST) { playPodcasts(); } else if (id == ALL_SONGS_PLAYLIST) { long[] list = MusicUtils.getAllSongs(getActivity()); if (list != null) { MusicUtils.playAll(getActivity(), list, 0); } } else { MusicUtils.playPlaylist(getActivity(), id); } } catch (NumberFormatException e) { Log.w(TAG, "Playlist id missing or broken"); } } getActivity().finish(); return; } MusicUtils.updateNowPlaying(getActivity()); } public void onServiceDisconnected(ComponentName classname) { } }); 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(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub if (mCreateShortcut) { final Intent shortcut = new Intent(); shortcut.setAction(Intent.ACTION_VIEW); shortcut.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/playlist"); shortcut.putExtra("playlist", String.valueOf(id)); final Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcut); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, ((TextView) view.findViewById(R.id.line1)).getText()); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(getActivity(), R.drawable.ic_launcher_shortcut_music_playlist)); getActivity().setResult(getActivity().RESULT_OK, intent); getActivity().finish(); return; } if (id == RECENTLY_ADDED_PLAYLIST) { Intent intent = new Intent(Intent.ACTION_PICK); intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track"); intent.putExtra("playlist", "recentlyadded"); startActivity(intent); } else if (id == PODCASTS_PLAYLIST) { Intent intent = new Intent(Intent.ACTION_PICK); intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track"); intent.putExtra("playlist", "podcasts"); startActivity(intent); } else { Intent intent = new Intent(Intent.ACTION_EDIT); intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track"); intent.putExtra("playlist", Long.valueOf(id).toString()); startActivity(intent); } } }); mAdapter = (PlaylistListAdapter) getActivity().getLastNonConfigurationInstance(); if (mAdapter == null) { //Log.i("@@@", "starting query"); mAdapter = new PlaylistListAdapter(getActivity().getApplication(), this, R.layout.track_list_item, mPlaylistCursor, new String[] { MediaStore.Audio.Playlists.NAME }, new int[] { android.R.id.text1 }); lv.setAdapter(mAdapter); //setTitle(R.string.working_playlists); getPlaylistCursor(mAdapter.getQueryHandler(), null); } else { mAdapter.setActivity(this); lv.setAdapter(mAdapter); mPlaylistCursor = mAdapter.getCursor(); // If mPlaylistCursor is null, this can be because it doesn't have // a cursor yet (because the initial query that sets its cursor // is still in progress), or because the query failed. // In order to not flash the error dialog at the user for the // first case, simply retry the query when the cursor is null. // Worst case, we end up doing the same query twice. if (mPlaylistCursor != null) { init(mPlaylistCursor); } else { //setTitle(R.string.working_playlists); getPlaylistCursor(mAdapter.getQueryHandler(), null); } } return view; }
From source file:com.google.android.car.kitchensink.volume.VolumeTestFragment.java
private static String streamToName(int stream) { switch (stream) { case AudioManager.STREAM_ALARM: return "Alarm"; case AudioManager.STREAM_MUSIC: return "Music"; case AudioManager.STREAM_NOTIFICATION: return "Notification"; case AudioManager.STREAM_RING: return "Ring"; case AudioManager.STREAM_VOICE_CALL: return "Call"; case AudioManager.STREAM_SYSTEM: return "System"; default://from w w w . jav a 2s.com return "Unknown"; } }
From source file:com.cyanogenmod.eleven.ui.activities.BaseActivity.java
/** * {@inheritDoc}//from www . j a va2 s. 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 broadcast receiver mPlaybackStatus = new PlaybackStatus(this); // Calculate ActionBar height TypedValue value = new TypedValue(); if (getTheme().resolveAttribute(android.R.attr.actionBarSize, value, true)) { mActionBarHeight = TypedValue.complexToDimensionPixelSize(value.data, getResources().getDisplayMetrics()); } // Set the layout setContentView(setContentView()); mToolBar = (Toolbar) findViewById(R.id.toolbar); setActionBar(mToolBar); getActionBar().setTitle(getString(R.string.app_name).toUpperCase()); // set the background on the root view getWindow().getDecorView().getRootView() .setBackgroundColor(getResources().getColor(R.color.background_color)); // Initialze the bottom action bar initBottomActionBar(); // listen to changes to the cache status ImageFetcher.getInstance(this).addCacheListener(this); }
From source file:com.example.controller.cast.CastRemoteDisplayActivity.java
/** * Initialization of the Activity after it is first created. Must at least * call {@link android.app.Activity#setContentView setContentView()} to * describe what is to be displayed in the screen. */// ww w. j a va 2 s . c om @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Set the hardware buttons to control the music this.setVolumeControlStream(AudioManager.STREAM_MUSIC); setContentView(R.layout.acitivity_cast_remote_display); setFullScreen(); setupActionBar(); Bundle extras = getIntent().getExtras(); listView = (ListView) findViewById(R.id.list_view); final Button button = (Button) findViewById(R.id.start_button); final ImageView imageView = (ImageView) findViewById(R.id.image_view); String[] steps = null; int drawableResId = R.drawable.hold_up; if (extras != null) { experiment = extras.getInt(EXTRA_EXPERIMENT); } if (experiment == 0 && isRemoteDisplaying()) { experiment = getCurrentService().getCurrentPresentationMode(); } switch (experiment) { case CastServiceController.MODE_3D_VIEWER: button.setText(R.string.start); steps = getResources().getStringArray(R.array.steps_3d_viewer); break; case CastServiceController.MODE_MATCH_GAME: steps = getResources().getStringArray(R.array.steps_match); break; case CastServiceController.MODE_LASER_GAME: drawableResId = R.drawable.hold_remotes; steps = getResources().getStringArray(R.array.steps_laser); break; } listView.setAdapter(new StepsAdapter(this, steps)); Glide.with(this).load(drawableResId).placeholder(R.drawable.hero_placeholder).fitCenter().crossFade() .into(imageView); // Local UI final View overlay = findViewById(R.id.overlay); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Change the remote display animation color when the button is clicked CastServiceController presentationService = getCurrentService(); if (presentationService != null) { presentationService.startPresentation(); } } }); overlay.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Change the remote display animation color when the button is clicked CastServiceController presentationService = getCurrentService(); if (presentationService != null) { presentationService.onSecondaryButton(); } } }); mMediaRouter = MediaRouter.getInstance(getApplicationContext()); mMediaRouteSelector = new MediaRouteSelector.Builder() .addControlCategory(CastMediaControlIntent.categoryForCast(getString(R.string.app_id))).build(); if (isRemoteDisplaying()) { // The Activity has been recreated and we have an active remote display session, // so we need to set the selected device instance CastDevice castDevice = CastDevice.getFromBundle(mMediaRouter.getSelectedRoute().getExtras()); mCastDevice = castDevice; } else { if (extras != null) { mCastDevice = extras.getParcelable(MainActivity.INTENT_EXTRA_CAST_DEVICE); } } }
From source file:com.n0n3m4.q3e.Q3ECallbackObj.java
public void init(int size) { if (mAudioTrack != null) return;//from ww w . j ava2 s .c o m if ((Q3EUtils.q3ei.isQ3) || (Q3EUtils.q3ei.isRTCW) || (Q3EUtils.q3ei.isQ1) || (Q3EUtils.q3ei.isQ2)) size /= 8; mAudioData = new byte[size]; int sampleFreq = 44100; /* _.---"'"""""'`--.._ _,.-' `-._ _,." -. .-"" ___...---------.._ `. `---'"" `-. `. `. \ `. \ \ \ . \ | . | | _________ | | _,.-'" `"'-.._ : | _,-' `-._.' | _.' OUYA `. ' _.-. _,+......__ `. . .' `-"' `"-.,-""--._ \ / / ,' | __ \ \ / ` .. +" ) \ \ / `.' \ ,-"`-.. | | \ / / " | .' \ '. _.' .' |,.."--"""--..| " | `""`. | ," `-._ | | | .' `-._+ | | / `. / | | ` ' | / | `-.....--.__ | | / | `./ "| / `-.........--.- ' | ,' ' /| || `.' ,' .' |_,-+ / / ' '.`. _,' ,' `. | ' _,.. / / `. `"'"'""'" _,^--------"`. | `.'_ _/ /... _.`:.________,.' `._,.-..| "' `.__.' `._ / "' */ int bufferSize = Math.max((Q3EUtils.isOuya) ? 0 : 3 * size, AudioTrack.getMinBufferSize(sampleFreq, AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT)); mAudioTrack = new Q3EAudioTrack(AudioManager.STREAM_MUSIC, sampleFreq, AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT, bufferSize, AudioTrack.MODE_STREAM); mAudioTrack.play(); long sleeptime = (size * 1000000000l) / (2 * 2 * sampleFreq); ScheduledThreadPoolExecutor stpe = new ScheduledThreadPoolExecutor(5); stpe.scheduleAtFixedRate(new Runnable() { @Override public void run() { if (reqThreadrunning) { Q3EJNI.requestAudioData(); } } }, 0, sleeptime, TimeUnit.NANOSECONDS); }
From source file:com.wikitude.example.CopyOfSimpleARBrowserActivity.java
/** Called when the activity is first created. */ @Override// w ww. j a v a 2 s .co m 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); }
From source file:fi.mikuz.boarder.gui.internet.Uploads.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTitle("Internet Uploads"); setContentView(R.layout.internet_uploads_list); this.setVolumeControlStream(AudioManager.STREAM_MUSIC); mList = new ArrayList<InternetFullBoard>(); mListView = (ListView) findViewById(android.R.id.list); mMaxResults = 40;/*from w w w .ja va 2 s .co m*/ mWaitDialog = new TimeoutProgressDialog(Uploads.this, "Waiting for response", TAG, true); Bundle extras = getIntent().getExtras(); @SuppressWarnings("unchecked") HashMap<String, String> lastSession = (HashMap<String, String>) extras .getSerializable(InternetMenu.LOGIN_KEY); try { mUserId = lastSession.get(InternetMenu.USER_ID_KEY); mSessionToken = lastSession.get(InternetMenu.SESSION_TOKEN_KEY); refreshList(); getListView().setOnScrollListener(this); } catch (NullPointerException e) { Toast.makeText(Uploads.this, "Please login", Toast.LENGTH_LONG).show(); Uploads.this.finish(); } }
From source file:de.htw.ar.treasurehuntar.AbstractArchitectActivity.java
/** * Called when the activity is first created. */// w w w . ja v a 2 s . c om @SuppressLint("NewApi") @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); // pressing volume up/down should cause music volume changes this.setVolumeControlStream(AudioManager.STREAM_MUSIC); this.setContentView(this.getContentViewId()); this.setTitle(this.getActivityTitle()); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); Log.i("architect", "create"); mGestureDetector = createGestureDetector(this); // // this enables remote debugging of a WebView on Android 4.4+ when debugging = true in AndroidManifest.xml // If you get a compile time error here, ensure to have SDK 19+ used in your ADT/Eclipse. // You may even delete this block in case you don't need remote debugging or don't have an Android 4.4+ device in place. // Details: https://developers.google.com/chrome-developer-tools/docs/remote-debugging // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) { WebView.setWebContentsDebuggingEnabled(true); } } // set AR-view for life-cycle notifications etc. this.architectView = (ArchitectView) this.findViewById(this.getArchitectViewId()); // pass SDK key if you have one, this one is only valid for this package identifier and must not be used somewhere else final ArchitectConfig config = new ArchitectConfig(this.getWikitudeSDKLicenseKey()); try { // first mandatory life-cycle notification this.architectView.onCreate(config); } 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()); } // listener passed over to locationProvider, any location update is handled here this.locationListener = new LocationListener() { @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } @Override public void onLocationChanged(final Location location) { // forward location updates fired by LocationProvider to architectView, you can set lat/lon from any location-strategy if (location != null) { Log.i("location", location.toString()); // sore last location as member, in case it is needed somewhere (in e.g. your adjusted project) AbstractArchitectActivity.this.lastKnownLocation = location; if (AbstractArchitectActivity.this.architectView != null) { // check if location has altitude at certain accuracy level & call right architect method (the one with altitude information) if (location.hasAltitude() && location.hasAccuracy() && location.getAccuracy() < 7) { AbstractArchitectActivity.this.architectView.setLocation(location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getAccuracy()); } else { AbstractArchitectActivity.this.architectView.setLocation(location.getLatitude(), location.getLongitude(), location.hasAccuracy() ? location.getAccuracy() : 1000); } } } } }; // locationProvider used to fetch user position this.locationProvider = new LocationProvider(this, this.locationListener); }
From source file:com.intel.xdk.player.Player.java
@Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); //get convenience reference to activity activity = cordova.getActivity();/*from w ww . ja v a 2 s.c o m*/ //get the current url final CordovaWebView wv = webView; activity.runOnUiThread(new Runnable() { public void run() { currentUrl = wv.getUrl(); } }); //turn on remote debugging // activity.runOnUiThread(new Runnable() { // public void run() { // if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // try { // Method m = WebView.class.getMethod("setWebContentsDebuggingEnabled", boolean.class); // m.invoke(WebView.class, true); // } catch (Exception e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // } // } // }); soundPool = new SoundPool(30, AudioManager.STREAM_MUSIC, 100); soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() { public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { soundLoaded(sampleId, status); } }); hasLoadSoundCallback = true; }