Android - Multiple appWidgets playing different sounds
Tag : java , By : firebasket
Date : March 29 2020, 07:55 AM
Hope that helps I'm writing an android soundboard wich allow the user to create multiple desktop widgets, one for each sound. I'm using an activity for the user to choose wich sound he wants to create the widget for. For each widget created i store a shared preference in the form of , I had the same problem and solved it like this: Intent intent = new Intent(context, YourActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
PendingIntent pi = PendingIntent.getActivity(context, appWidgetId, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
int currentWidgetId = this.getIntent().getIntExtra(
AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
private void updateWidgetView() {
views = new RemoteViews(YourWidget.class.getPackage().getName(),
R.layout.main_widget);
mgr = AppWidgetManager.getInstance(this);
views.setTextViewText(R.id.some_text_view, someText);
// Tell the AppWidgetManager to perform an update on the current App Widget
mgr.updateAppWidget(currentWidgetId, views);
}
|
Android - Playing multiple sounds sequencially
Date : March 29 2020, 07:55 AM
it fixes the issue SoundPool is commonly used to play multiple short sounds. You could load up all your sounds in onCreate(), storing their positions in a HashMap. Creating SoundPool public static final int SOUND_1 = 1;
public static final int SOUND_2 = 2;
SoundPool mSoundPool;
HashMap<Integer, Integer> mHashMap;
@Override
public void onCreate(Bundle savedInstanceState){
mSoundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 100);
mSoundMap = new HashMap<Integer, Integer>();
if(mSoundPool != null){
mSoundMap.put(SOUND_1, mSoundPool.load(this, R.raw.sound1, 1));
mSoundMap.put(SOUND_2, mSoundPool.load(this, R.raw.sound2, 1));
}
}
/*
*Call this function from code with the sound you want e.g. playSound(SOUND_1);
*/
public void playSound(int sound) {
AudioManager mgr = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
float volume = streamVolumeCurrent / streamVolumeMax;
if(mSoundPool != null){
mSoundPool.play(mSoundMap.get(sound), volume, volume, 1, 0, 1.0f);
}
}
|
swift sprite kit - AVAudioPlayer not playing multiple sounds in same time simultaneously
Tag : ios , By : kangfoo2
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , There may be a more efficient way, but you can try this for each sound. I tried it out with a couple sounds and it worked. If you don't want the your sounds to interrupt music that the user may be listening to, then just change AVAdudioSessionCategoryPlayback to AVAdudioSessionCategoryAmbient. var audioPlayer = AVAudioPlayer()
func playSound() {
var dropSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("drop", ofType: "mp3")!)
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil)
AVAudioSession.sharedInstance().setActive(true, error: nil)
var error: NSError?
audioPlayer = AVAudioPlayer(contentsOfURL: dropSound, error: &error)
audioPlayer.prepareToPlay()
}
audioPlayer.play()
|
Playing 2 sounds together at same time
Tag : chash , By : billputer
Date : March 29 2020, 07:55 AM
|
Playing sounds sequentially on android's google chrome (given the new restrictions on playing sound)
Tag : android , By : usingtechnology
Date : March 29 2020, 07:55 AM
like below fixes the issue To start with, Google Chrome on Android has been having the limitation of not allowing applications to play HTML audio(s) without an explicit action by the user. However, it is different than how stock browser(s), in most cases, handles it.
|