List of usage examples for android.media MediaPlayer start
public void start() throws IllegalStateException
From source file:org.esupportail.nfctagdroid.NfcTacDroidActivity.java
@Override public void onTagDiscovered(final Tag tag) { if (localStorageDBHelper.getValue("readyToScan").equals("ok")) { localStorageDBHelper.updateValue("readyToScan", "ko"); synchronized (tag) { String toastText = ""; int rStatus = R.raw.fail; try { AuthResultBean authResult = auth(tag); toastText = authResult.getMsg(); if (authResult.isError()) { log.warn(getString(R.string.log_msg_tag_ko)); localStorageDBHelper.updateValue("readyToScan", "ok"); } else { rStatus = R.raw.success; log.info(getString(R.string.log_msg_tag_ok) + " : " + authResult.getMsg().replace("\n", " ")); }//ww w . j a v a 2 s.co m } catch (NfcTagDroidInvalidTagException e) { log.info(getString(R.string.log_msg_invalid_auth), e); toastText = getString(R.string.msg_tag_ko); runOnUiThread(ToastThread.getInstance(getApplicationContext(), rStatus, toastText)); } catch (NfcTagDroidPleaseRetryTagException e) { log.warn(getString(R.string.log_msg_retry_auth), e); toastText = getString(R.string.msg_retry); runOnUiThread(ToastThread.getInstance(getApplicationContext(), rStatus, toastText)); } catch (Exception e) { log.error(getString(R.string.log_msg_unknow_err), e); toastText = getString(R.string.msg_unknow_err); runOnUiThread(ToastThread.getInstance(getApplicationContext(), rStatus, toastText)); localStorageDBHelper.updateValue("readyToScan", "ok"); } MediaPlayer mp = MediaPlayer.create(getApplicationContext(), rStatus); mp.start(); } } else { log.warn("onTagDiscovered but localStorageDBHelper.getValue(\"readyToScan\") = " + localStorageDBHelper.getValue("readyToScan")); } }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.VoiceObj.java
@Override public void activate(final Context context, final SignedObj obj) { Runnable r = new Runnable() { @Override//from ww w .ja v a2s .c o m public void run() { byte[] bytes = obj.getRaw(); if (bytes == null) { Pair<JSONObject, byte[]> p = splitRaw(obj.getJson()); // content = p.first; bytes = p.second; } /*AudioTrack track = new AudioTrack(AudioManager.STREAM_MUSIC, RECORDER_SAMPLERATE, RECORDER_CHANNELS, RECORDER_AUDIO_ENCODING, bytes.length, AudioTrack.MODE_STATIC); track.write(bytes, 0, bytes.length); try { // TODO: hack. Thread.sleep(500); } catch (InterruptedException e) { } track.play(); */ /****/ File file = new File(getTempFilename()); try { OutputStream os = new FileOutputStream(file); BufferedOutputStream bos = new BufferedOutputStream(os); bos.write(bytes, 0, bytes.length); bos.flush(); bos.close(); copyWaveFile(getTempFilename(), getFilename()); deleteTempFile(); MediaPlayer mp = new MediaPlayer(); mp.setDataSource(getFilename()); mp.prepare(); mp.start(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }; if (context instanceof Activity) { ((Activity) context).runOnUiThread(r); } else { r.run(); } }
From source file:de.quadrillenschule.azocamsynca.job.JobProcessor.java
public void doTestShots(final TriggerPhotoSerie job) { final NikonIR camera = ((AzoTriggerServiceApplication) getActivity().getApplication()).getCamera(); final JobProcessor jobProcessor = ((AzoTriggerServiceApplication) getActivity().getApplication()) .getJobProcessor();// w ww . j a v a 2s . c o m final AlertDialog.Builder adb = new AlertDialog.Builder(getActivity(), R.style.dialog); job.setTriggerStatus(PhotoSerie.TriggerJobStatus.WAITFORUSER); adb.setTitle("Test Shots"); adb.setMessage("This series collects all images during preparation of the project\n" + job.getProject() + "\n" + "Camera controls time: " + camera.isExposureSetOnCamera(job.getExposure())); if (!job.isToggleIsOpen()) { adb.setPositiveButton("Finish", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { job.setTriggerStatus(PhotoSerie.TriggerJobStatus.FINISHED_TRIGGERING); jobProcessor.fireJobProgressEvent(job); processingLoop(); } }); } adb.setNegativeButton("Trigger", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { camera.trigger(); if (!camera.isExposureSetOnCamera(job.getExposure())) { job.setToggleIsOpen(!job.isToggleIsOpen()); if (!job.isToggleIsOpen()) { job.setNumber(job.getNumber() + 1); job.setTriggered(job.getTriggered() + 1); } } else { job.setNumber(job.getNumber() + 1); job.setTriggered(job.getTriggered() + 1); } doTestShots(job); } }); MediaPlayer mediaPlayer = MediaPlayer.create(activity, R.raw.oida_peda); mediaPlayer.start(); // adb.create().show(); adb.create(); alertDialog = adb.show(); }
From source file:edu.cmu.android.restaurant.MapFragment.java
/** * //w w w. java 2 s . c om * Shaking: - User shake the mobile to find the coupon of the restaurant in * the detail fragment page - After shaking, the mobile vibrates for 500 ms * * */ @Override public void onSensorChanged(SensorEvent event) { int sensorType = event.sensor.getType(); float[] values = event.values; if (sensorType == Sensor.TYPE_ACCELEROMETER) { if ((Math.abs(values[0]) > 15 || Math.abs(values[1]) > 15 || Math.abs(values[2]) > 15)) { Log.d("sensor ", "X- values[0] = " + values[0]); Log.d("sensor ", "Y- values[1] = " + values[1]); Log.d("sensor ", "Z- values[2] = " + values[2]); findDeal(); dealDisplay(); /* audio play */ MediaPlayer mp = MediaPlayer.create(getActivity(), R.raw.coupon_audio); mp.seekTo(0); mp.start(); } } }
From source file:edu.cmu.android.restaurant.MapFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { /* menu : camera */ case Menu.FIRST + 1: try {//from w w w . j a v a 2 s . co m Intent i = new Intent("android.media.action.IMAGE_CAPTURE"); startActivityForResult(i, Activity.DEFAULT_KEYS_DIALER); } catch (Exception e) { Log.d("Detail", "Cemara onClick error."); } finally { if (getActivity().getResources() .getConfiguration().orientation != Configuration.ORIENTATION_PORTRAIT) { getActivity().setRequestedOrientation(Configuration.ORIENTATION_PORTRAIT); } } break; /* menu : coupon */ case Menu.FIRST + 2: /* display the deal in a dialog */ findDeal(); dealDisplay(); /* audio play */ MediaPlayer mp = MediaPlayer.create(getActivity(), R.raw.coupon_audio); mp.seekTo(0); mp.start(); break; /* Menu : about */ case Menu.FIRST + 3: Builder builder3 = new AlertDialog.Builder(getActivity()); builder3.setTitle("About US"); builder3.setMessage(ABOUT_CONTENT); builder3.setPositiveButton("Return", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).show(); break; } return false; }
From source file:de.quadrillenschule.azocamsynca.job.JobProcessor.java
public void processingLoop() { if (getRequestStatus() == ProcessorStatus.PAUSED) { setStatus(ProcessorStatus.PAUSED); return;//ww w.ja v a 2 s .co m } setStatus(ProcessorStatus.PROCESSING); TriggerPhotoSerie currentJobT = null; for (TriggerPhotoSerie j : jobs) { if (j.getTriggerStatus() != TriggerPhotoSerie.TriggerJobStatus.FINISHED_TRIGGERING) { currentJobT = j; if ((j.getTriggerStatus() == PhotoSerie.TriggerJobStatus.WAITFORUSER) && ((alertDialog != null) && (alertDialog.isShowing()))) { return; } if ((j.getTriggerStatus() == PhotoSerie.TriggerJobStatus.WAITFORUSER)) { currentJobT.setTriggerStatus(PhotoSerie.TriggerJobStatus.NEW); } break; } } if (currentJobT == null) { setStatus(ProcessorStatus.PAUSED); return; } final TriggerPhotoSerie currentJob = currentJobT; final NikonIR camera = ((AzoTriggerServiceApplication) getActivity().getApplication()).getCamera(); if (currentJob.getTriggerStatus() == PhotoSerie.TriggerJobStatus.NEW) { currentJob.setTriggerStatus(PhotoSerie.TriggerJobStatus.WAITFORUSER); if (currentJob.getSeriesName().equals(PhotoSerie.TESTSHOTS)) { doTestShots(currentJob); return; } AlertDialog.Builder ad = new AlertDialog.Builder(getActivity(), R.style.dialog); ad.setTitle(currentJob.getProject() + ": " + currentJob.getSeriesName()); ad.setMessage( currentJob.getNumber() + " x " + (int) (currentJob.getExposure() / 1000) + "s\n\n" + "Delay after each exposure:" + currentJob.getDelayAfterEachExposure() / 1000 + "s\n" + "Camera controls time: " + camera.isExposureSetOnCamera(currentJob.getExposure()) + "\n" + "Total time: " + ((currentJob.getNumber() * (currentJob.getExposure() + currentJob.getDelayAfterEachExposure())) / 1000) + "s"); ad.setPositiveButton("Confirm", new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { currentJob.setTriggerStatus(PhotoSerie.TriggerJobStatus.PREPARED); processingLoop(); } }); ad.setNegativeButton("Pause", new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { currentJob.setTriggerStatus(PhotoSerie.TriggerJobStatus.NEW); pause(); } }); MediaPlayer mediaPlayer = MediaPlayer.create(activity, R.raw.oida_peda); mediaPlayer.start(); ad.create(); alertDialog = ad.show(); } final Handler handler = new Handler(); if ((currentJob.getTriggerStatus() == PhotoSerie.TriggerJobStatus.PREPARED || currentJob.getTriggerStatus() == PhotoSerie.TriggerJobStatus.RUNNING)) { handler.postDelayed(new Runnable() { public void run() { if ((((AzoTriggerServiceApplication) getActivity().getApplication()).getJobProcessor() .getStatus() == ProcessorStatus.PAUSED) && (!currentJob.isToggleIsOpen())) { return; } camera.trigger(); for (JobProgressListener j : jobProgressListeners) { j.jobProgressed(currentJob); } if (currentJob.getFirstTriggerTime() == 0) { currentJob.setFirstTriggerTime(System.currentTimeMillis()); } currentJob.setTriggerStatus(PhotoSerie.TriggerJobStatus.RUNNING); if (!camera.isExposureSetOnCamera(currentJob.getExposure())) { if (!currentJob.isToggleIsOpen()) { currentJob.setToggleIsOpen(!currentJob.isToggleIsOpen()); currentJob.setLastTriggerTime(System.currentTimeMillis()); } else { currentJob.setToggleIsOpen(!currentJob.isToggleIsOpen()); currentJob.setTriggered(currentJob.getTriggered() + 1); } } else { currentJob.setTriggered(currentJob.getTriggered() + 1); } if (currentJob.getTriggered() < currentJob.getNumber()) { long time; if (camera.isExposureSetOnCamera(currentJob.getExposure())) { time = currentJob.getExposure() + currentJob.getDelayAfterEachExposure(); } else { if (currentJob.isToggleIsOpen()) { time = currentJob.getExposure(); } else { time = currentJob.getDelayAfterEachExposure(); } } handler.postDelayed(this, time); } else { currentJob.setTriggerStatus(PhotoSerie.TriggerJobStatus.FINISHED_TRIGGERING); processingLoop(); } } }, currentJob.getInitialDelay()); } else { } }
From source file:me.tylerbwong.pokebase.gui.activities.PokemonProfileActivity.java
private void playAudio() { final MediaPlayer player = MediaPlayer.create(this, getResources().getIdentifier(AUDIO + pokemonId, RAW, getPackageName())); player.setOnCompletionListener(mediaPlayer -> player.release()); player.start(); Toast.makeText(this, getString(R.string.sound_played), Toast.LENGTH_SHORT).show(); }
From source file:fi.iki.murgo.irssinotifier.IrssiNotifierActivity.java
public void newMessage(IrcMessage msg) { if ((!preferences.isSpamFilterEnabled() || new Date().getTime() > IrcNotificationManager.getInstance().getLastSoundDate() + 60000L)) { Uri sound = preferences.getNotificationSound(); if (sound != null) { MediaPlayer mp = MediaPlayer.create(this, sound); if (mp != null) { mp.start(); }/*w w w . ja v a 2 s . c om*/ } if (preferences.isVibrationEnabled()) { Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); if (v != null) { v.vibrate(500); } } IrcNotificationManager.getInstance().setLastSoundDate(new Date().getTime()); } if (preferences.isFeedViewDefault()) { channelToView = FEED; } else { channelToView = msg.getLogicalChannel(); } startMainApp(false); }
From source file:com.jungle.base.utils.MiscUtils.java
public static void playSound(Context context, int soundResId) { final MediaPlayer player = MediaPlayer.create(context, soundResId); if (player == null) { return;//from www .j a v a 2 s .c o m } AudioManager manager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); int maxVolume = manager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); int currVolume = manager.getStreamVolume(AudioManager.STREAM_MUSIC); float volume = 1.0f; if (maxVolume > 0) { volume = (float) currVolume / (float) maxVolume; } player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { player.release(); } }); player.setVolume(volume, volume); player.start(); }
From source file:com.smedic.tubtub.BackgroundAudioService.java
@Override public void onPrepared(MediaPlayer mp) { isPrepared = true; mp.start(); }