android-audiomanager

Change Media volume in Android?

橙三吉。 提交于 2019-11-26 17:30:55
问题 Can I change the media volume? and how? I used this so far: setVolumeControlStream(AudioManager.STREAM_MUSIC); But have a seekbar and want to change the media volume, not ring volume. So can someone show me how to just change the media volume at onCreate() and I fix the seekbar later. 回答1: The right method to use would be setStreamVolume on your AudioManager . It could looks like this AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE); audioManager

Android: How to generate a frequency?

帅比萌擦擦* 提交于 2019-11-26 16:37:28
问题 Is there a nice way in Android to generate and then play a frequency (eg. 1000hz, 245hz)? 回答1: Take a look at android.media.ToneGenerator. You can also try following Code. public class PlaySound extends Activity { // originally from http://marblemice.blogspot.com/2010/04/generate-and-play-tone-in-android.html // and modified by Steve Pomeroy <steve@staticfree.info> private final int duration = 3; // seconds private final int sampleRate = 8000; private final int numSamples = duration *

How to detect when a user plugs headset on android device? (Opposite of ACTION_AUDIO_BECOMING_NOISY)

谁说我不能喝 提交于 2019-11-26 16:08:40
I'm developing an application that has the following requisite: If there is a headset plugged in the device and the user removes it, I need to mute all streams. To do that I need to listen to the AudioManager.ACTION_AUDIO_BECOMING_NOISY Broadcast. This is ok! Not problem here. But when the user plugs the headset again , I need to un-mute the device. But there isn't a AudioManager.ACTION_AUDIO_BECOMING_NOISY opposite broadcast. I cannot know when the headset is plugged again. One solution is to periodically see if AudioManager.isWiredHeadsetOn() is true but this don't appear to be a good

Ringer mode change listener Broadcast receiver?

做~自己de王妃 提交于 2019-11-26 16:05:01
问题 AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE); switch (am.getRingerMode()) { case AudioManager.RINGER_MODE_SILENT: Log.i("MyApp","Silent mode"); break; case AudioManager.RINGER_MODE_VIBRATE: Log.i("MyApp","Vibrate mode"); break; case AudioManager.RINGER_MODE_NORMAL: Log.i("MyApp","Normal mode"); break; } From the code above I can get the ringer mode. What I would liek to do is listen the ringer mode changes and call a function. What I have been told is that I can

Android : Calling Activity from Fragment

冷暖自知 提交于 2019-11-26 13:20:51
问题 I am using fragments inside an activity. I am using MediaRecorder to for audio recording. I have two part of an activity. 1st itself the Activity which will list the recorded file. On it's right side the AudioRecording Activity is called when one select to record for a new file. When the any of the listed file is selected i am using AudioPlayer as to play the recorded file. I am here able to convert the Activity into fragment but when i press on Stop it is terminating the application. Please

Not able to achieve Gapless audio looping so far on Android

僤鯓⒐⒋嵵緔 提交于 2019-11-26 08:08:16
问题 I have tried almost every method but I\'ve failed to achieve gapless audio playback between looping a single track with a duration of 10-15 seconds. Steps I\'ve tried and failed : Different audio file formats .mp3 .wav .ogg using setLooping(true) : MediaPlayer mp1 = MediaPlayer.create(MainActivity.this, R.raw.track1); mp1.setLooping(true); mp1.start(); Creating two mediaplayers and looping one after another using setOnCompletionListener same failed to loop without gaps. Using

In Android 7 (API level 24) my app is not allowed to mute phone (set ringer mode to silent)

倾然丶 夕夏残阳落幕 提交于 2019-11-26 07:33:13
问题 I have an app that mutes the phone by using AudioManager and setting ringer mode to silent with this code: AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); try { audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT) } catch (Exception e) { e.printStackTrace(); } This works with Android 6, but now with Android 7, I get the following error: System.err: java.lang.SecurityException: Not allowed to change Do Not Disturb state System.err: at android

Using SeekBar to Control Volume in android?

那年仲夏 提交于 2019-11-26 05:22:25
问题 How can I accurately change the volume of my app using a seekbar without controlling the volume by the volume buttons on my android device? I have seperate function on the Volume keys on my android that\'s why I want to use a seekbar to control the volume. Can Anyone please help me? 回答1: Please look at below code . It solves your problem. import android.app.Activity; import android.content.Context; import android.media.AudioManager; import android.os.Bundle; import android.widget.SeekBar;

How to detect when a user plugs headset on android device? (Opposite of ACTION_AUDIO_BECOMING_NOISY)

╄→гoц情女王★ 提交于 2019-11-26 04:43:45
问题 I\'m developing an application that has the following requisite: If there is a headset plugged in the device and the user removes it, I need to mute all streams. To do that I need to listen to the AudioManager.ACTION_AUDIO_BECOMING_NOISY Broadcast. This is ok! Not problem here. But when the user plugs the headset again , I need to un-mute the device. But there isn\'t a AudioManager.ACTION_AUDIO_BECOMING_NOISY opposite broadcast. I cannot know when the headset is plugged again. One solution is