private void LoadContent() { audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); ((Activity) context).setVolumeControlStream(AudioManager.STREAM_MUSIC); soundPool = new SoundPool(20, AudioManager.STREAM_RING, 100); curVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC); maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); leftVolume = (curVolume / maxVolume); rightVolume = (curVolume / maxVolume); soundPoolMap[0] = soundPool.load(context, R.raw.coin_collect, 1); aff = soundPool.load(context, R.raw.coin_collect, 1); soundPoolMap[1] = soundPool.load(context, R.raw.cheer1, 1); soundPoolMap[2] = soundPool.load(context, R.raw.sound_bird, 1); soundPoolMap[3] = soundPool.load(context, R.raw.sound_shark, 1); soundPoolMap[4] = soundPool.load(context, R.raw.sound_splash, 1); soundPoolMap[5] = soundPool.load(context, R.raw.sound_swoosh, 1); soundPoolMap[6] = soundPool.load(context, R.raw.noluck, 1); soundPoolMap[7] = soundPool.load(context, R.raw.luck, 1); soundPoolMap[8] = soundPool.load(context, R.raw.start_boat, 1); priority = 1; no_loop = 0; normal_playback_rate = 1f; themePlay = MediaPlayer.create(this.context, R.raw.theme); themePlay.setLooping(true); themePlay.start(); wavePlay = MediaPlayer.create(this.context, R.raw.wave_sound); wavePlay.setLooping(true); wavePlay.setVolume(leftVolume / 5, rightVolume / 5); wavePlay.start(); }
synchronized void updatePrefs() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); playBeep = shouldBeep(prefs, activity); vibrate = prefs.getBoolean(PreferencesActivity.KEY_VIBRATE, false); if (playBeep && mediaPlayer == null) { // The volume on STREAM_SYSTEM is not adjustable, and users found it too loud, // so we now play on the music stream. activity.setVolumeControlStream(AudioManager.STREAM_MUSIC); mediaPlayer = buildMediaPlayer(activity); } }
private void initVideoView(Context ctx) { mContext = ctx; mVideoWidth = 0; mVideoHeight = 0; getHolder().addCallback(mSHCallback); setFocusable(true); setFocusableInTouchMode(true); requestFocus(); mCurrentState = STATE_IDLE; mTargetState = STATE_IDLE; if (ctx instanceof Activity) ((Activity) ctx).setVolumeControlStream(AudioManager.STREAM_MUSIC); }
public OFAndroid(String packageName, Activity ofActivity) { ofActivity.setVolumeControlStream(AudioManager.STREAM_MUSIC); // Log.i("OF","external files dir: "+ // ofActivity.getApplicationContext().getExternalFilesDir(null)); OFAndroid.packageName = packageName; OFAndroidObject.setActivity(ofActivity); try { // try to find if R.raw class exists will throw // an exception if not Class<?> raw = Class.forName(packageName + ".R$raw"); // if it exists copy all the raw resources // to a folder in the sdcard Field[] files = raw.getDeclaredFields(); boolean copydata = false; SharedPreferences preferences = ofActivity.getPreferences(Context.MODE_PRIVATE); long lastInstalled = preferences.getLong("installed", 0); PackageManager pm = ofActivity.getPackageManager(); ApplicationInfo appInfo = pm.getApplicationInfo(packageName, 0); String appFile = appInfo.sourceDir; long installed = new File(appFile).lastModified(); if (installed > lastInstalled) { Editor editor = preferences.edit(); editor.putLong("installed", installed); editor.commit(); copydata = true; } dataPath = ""; try { // dataPath = Environment.getExternalStorageDirectory().getAbsolutePath(); dataPath = getRealExternalStorageDirectory(); dataPath += "/" + packageName; Log.i("OF", "creating app directory: " + dataPath); try { File dir = new File(dataPath); if (!dir.exists() && dir.mkdir() != true) throw new Exception(); } catch (Exception e) { Log.e("OF", "error creating dir " + dataPath, e); } if (copydata) { for (int i = 0; i < files.length; i++) { int fileId; String fileName = ""; InputStream from = null; File toFile = null; FileOutputStream to = null; try { fileId = files[i].getInt(null); String resName = ofActivity.getResources().getText(fileId).toString(); fileName = resName.substring(resName.lastIndexOf("/")); from = ofActivity.getResources().openRawResource(fileId); // toFile = new File(Environment.getExternalStorageDirectory() + "/" + appName + "/" // +fileName); Log.i("OF", "copying file " + fileName + " to " + dataPath); toFile = new File(dataPath + "/" + fileName); to = new FileOutputStream(toFile); byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = from.read(buffer)) != -1) to.write(buffer, 0, bytesRead); // write } catch (Exception e) { Log.e("OF", "error copying file", e); } finally { if (from != null) try { from.close(); } catch (IOException e) { } if (to != null) try { to.close(); } catch (IOException e) { } } } } } catch (Exception e) { Log.e("OF", "couldn't move app resources to data directory " + dataPath); e.printStackTrace(); } String app_name = ""; try { int app_name_id = Class.forName(packageName + ".R$string").getField("app_name").getInt(null); app_name = ofActivity.getResources().getText(app_name_id).toString(); Log.i("OF", "app name: " + app_name); } catch (Exception e) { // TODO Auto-generated catch block Log.e("OF", "error retrieving app name", e); } OFAndroid.setAppDataDir(dataPath, app_name); } catch (ClassNotFoundException e1) { } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } OFAndroid.ofActivity = ofActivity; gestureListener = new OFGestureListener(ofActivity); try { Log.v("OF", "trying to find class: " + packageName + ".R$layout"); Class<?> layout = Class.forName(packageName + ".R$layout"); View view = ofActivity.getLayoutInflater().inflate(layout.getField("main_layout").getInt(null), null); ofActivity.setContentView(view); Class<?> id = Class.forName(packageName + ".R$id"); mGLView = (OFGLSurfaceView) ofActivity.findViewById(id.getField("of_gl_surface").getInt(null)); enableTouchEvents(); } catch (Exception e) { Log.e("OF", "couldn't create view from layout falling back to GL only", e); mGLView = new OFGLSurfaceView(ofActivity); ofActivity.setContentView(mGLView); enableTouchEvents(); } // android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO); }
public AndroidAudio(Activity activity) { activity.setVolumeControlStream(AudioManager.STREAM_MUSIC); this.assets = activity.getAssets(); this.soundPool = new SoundPool(20, AudioManager.STREAM_MUSIC, 0); }
public static void initVolumeType(Activity activity) { activity.setVolumeControlStream(AudioManager.STREAM_MUSIC); }
public void setUp() { context.setVolumeControlStream(AudioManager.STREAM_MUSIC); }