List of usage examples for android.media MediaPlayer create
public static MediaPlayer create(Context context, int resid)
From source file:com.quwu.xinwo.release.Release_Activity.java
/** * // w ww . j ava2 s. c o m * */ private void isPlayRecording() { MediaPlayer mPlayer = null; long duration = 0; mPlayer = new MediaPlayer(); MediaPlayer mp = MediaPlayer.create(Release_Activity.this, Uri.parse(path)); if (mp != null) { duration = mp.getDuration() / 1000; } try { mPlayer.setDataSource(path); mPlayer.prepare(); mPlayer.start(); } catch (IOException e) { } String str = duration % 60 + ""; playerBtn.setText(str + "s"); }
From source file:com.quwu.xinwo.release.Release_Activity.java
private long isRecordingTime() { long duration = 0; MediaPlayer mp = MediaPlayer.create(Release_Activity.this, Uri.parse(path)); if (mp != null) { duration = mp.getDuration() / 1000; }// w ww .java2s . c o m String str = duration % 60 + ""; long l = Long.valueOf(str) * 1000; return l; }
From source file:org.telegram.ui.ChatActivity.java
public void processSendingVideo(final String videoPath) { if (videoPath == null) { return;/* w ww.ja v a2 s . c o m*/ } Bitmap thumb = ThumbnailUtils.createVideoThumbnail(videoPath, MediaStore.Video.Thumbnails.MINI_KIND); TLRPC.PhotoSize size = FileLoader.scaleAndSaveImage(thumb, 90, 90, 55, currentEncryptedChat != null); if (size == null) { return; } size.type = "s"; TLRPC.TL_video video = new TLRPC.TL_video(); video.thumb = size; video.caption = ""; video.id = 0; video.path = videoPath; File temp = new File(videoPath); if (temp != null && temp.exists()) { video.size = (int) temp.length(); } UserConfig.lastLocalId--; UserConfig.saveConfig(false); MediaPlayer mp = MediaPlayer.create(ApplicationLoader.applicationContext, Uri.fromFile(new File(videoPath))); if (mp == null) { return; } video.duration = (int) Math.ceil(mp.getDuration() / 1000.0f); video.w = mp.getVideoWidth(); video.h = mp.getVideoHeight(); mp.release(); MediaStore.Video.Media media = new MediaStore.Video.Media(); MessagesController.Instance.sendMessage(video, dialog_id); if (chatListView != null) { chatListView.setSelection(messages.size() + 1); } scrollToTopOnResume = true; }
From source file:keyboard.ecloga.com.eclogakeyboard.EclogaKeyboard.java
private void playClick() { stopPlaying();//from w w w .j a v a 2 s. c o m if (Preferences.getDefaults("sound_c", getApplicationContext()).equals("click")) { mp = MediaPlayer.create(this, R.raw.click); mp.start(); } else if (Preferences.getDefaults("sound_c", getApplicationContext()).equals("swoosh")) { mp = MediaPlayer.create(this, R.raw.swoosh); mp.start(); } else if (Preferences.getDefaults("sound_c", getApplicationContext()).equals("bubble")) { mp = MediaPlayer.create(this, R.raw.bubble); mp.start(); } else if (Preferences.getDefaults("sound_c", getApplicationContext()).equals("metal")) { mp = MediaPlayer.create(this, R.raw.metal); mp.start(); } else if (Preferences.getDefaults("sound_c", getApplicationContext()).equals("plastic")) { mp = MediaPlayer.create(this, R.raw.plastic); mp.start(); } else if (Preferences.getDefaults("sound_c", getApplicationContext()).equals("water")) { mp = MediaPlayer.create(this, R.raw.water); mp.start(); } else if (Preferences.getDefaults("sound_c", getApplicationContext()).equals("balls")) { mp = MediaPlayer.create(this, R.raw.balls); mp.start(); } else if (Preferences.getDefaults("sound_c", getApplicationContext()).equals("none")) { mp = MediaPlayer.create(this, R.raw.balls); mp.setVolume(0, 0); mp.start(); } }
From source file:keyboard.ecloga.com.eclogakeyboard.EclogaKeyboard.java
private void playSwipeH() { stopPlaying();/* ww w. j a v a2s. c o m*/ if (Preferences.getDefaults("sound_h", getApplicationContext()).equals("click")) { mp = MediaPlayer.create(this, R.raw.click); mp.start(); } else if (Preferences.getDefaults("sound_h", getApplicationContext()).equals("swoosh")) { mp = MediaPlayer.create(this, R.raw.swoosh); mp.start(); } else if (Preferences.getDefaults("sound_h", getApplicationContext()).equals("bubble")) { mp = MediaPlayer.create(this, R.raw.bubble); mp.start(); } else if (Preferences.getDefaults("sound_h", getApplicationContext()).equals("metal")) { mp = MediaPlayer.create(this, R.raw.metal); mp.start(); } else if (Preferences.getDefaults("sound_h", getApplicationContext()).equals("plastic")) { mp = MediaPlayer.create(this, R.raw.plastic); mp.start(); } else if (Preferences.getDefaults("sound_h", getApplicationContext()).equals("water")) { mp = MediaPlayer.create(this, R.raw.water); mp.start(); } else if (Preferences.getDefaults("sound_h", getApplicationContext()).equals("balls")) { mp = MediaPlayer.create(this, R.raw.balls); mp.start(); } else if (Preferences.getDefaults("sound_h", getApplicationContext()).equals("none")) { mp = MediaPlayer.create(this, R.raw.balls); mp.setVolume(0, 0); mp.start(); } }
From source file:keyboard.ecloga.com.eclogakeyboard.EclogaKeyboard.java
private void playSwipeV() { stopPlaying();//from w w w .j a v a 2s .co m if (Preferences.getDefaults("sound_v", getApplicationContext()).equals("click")) { mp = MediaPlayer.create(this, R.raw.click); mp.start(); } else if (Preferences.getDefaults("sound_v", getApplicationContext()).equals("swoosh")) { mp = MediaPlayer.create(this, R.raw.swoosh); mp.start(); } else if (Preferences.getDefaults("sound_v", getApplicationContext()).equals("bubble")) { mp = MediaPlayer.create(this, R.raw.bubble); mp.start(); } else if (Preferences.getDefaults("sound_v", getApplicationContext()).equals("metal")) { mp = MediaPlayer.create(this, R.raw.metal); mp.start(); } else if (Preferences.getDefaults("sound_v", getApplicationContext()).equals("plastic")) { mp = MediaPlayer.create(this, R.raw.plastic); mp.start(); } else if (Preferences.getDefaults("sound_v", getApplicationContext()).equals("water")) { mp = MediaPlayer.create(this, R.raw.water); mp.start(); } else if (Preferences.getDefaults("sound_v", getApplicationContext()).equals("balls")) { mp = MediaPlayer.create(this, R.raw.balls); mp.start(); } else if (Preferences.getDefaults("sound_v", getApplicationContext()).equals("none")) { mp = MediaPlayer.create(this, R.raw.balls); mp.setVolume(0, 0); mp.start(); } }
From source file:de.rosche.spectraTelemetry.SpectraTelemetry.java
public void readPrefs() { String valueTmp = ""; try {//from ww w . j a v a 2 s . c om voltage_speech_alert = mPrefs.getString("voltage_speech_alert", voltage_speech_alert); height_speech_alert = mPrefs.getString("height_speech_alert", height_speech_alert); current_speech_alert = mPrefs.getString("current_speech_alert", current_speech_alert); used_speech_alert = mPrefs.getString("used_speech_alert", used_speech_alert); temp_speech_alert = mPrefs.getString("temp_speech_alert", temp_speech_alert); rpm_speech_alert = mPrefs.getString("rpm_speech_alert", rpm_speech_alert); speed_speech_alert = mPrefs.getString("speed_speech_alert", speed_speech_alert); mVoltageAlarm = getDouble("voltage", mVoltageAlarm); mUsedCap = getDouble("used_cap", mUsedCap); mCurrentAlarm = getDouble("current", mCurrentAlarm); mPowerAlarm = getDouble("power", mPowerAlarm); mSpeedAlarm = tools.getInteger("speed", mSpeedAlarm, mPrefs); // mSpeedAlarm = getInteger("speed", mSpeedAlarm); mRpmAlarm = getInteger("rpm", mRpmAlarm); mAltitudeAlarm = getInteger("altitude", mAltitudeAlarm); mFuelAlarm = getInteger("fuel", mFuelAlarm); voltage_hysteresis = getInteger("voltage_hysteresis", voltage_hysteresis); current_hysteresis = getInteger("current_hysteresis", current_hysteresis); rpm_hysteresis = getInteger("rpm_hysteresis", rpm_hysteresis); temperature_hysteresis = getInteger("temperature_hysteresis", temperature_hysteresis); power_hysteresis = getInteger("power_hysteresis", power_hysteresis); mTemperatureAlarm = getInteger("temperature", mTemperatureAlarm); speech_volume = getInteger("speech_volume", speech_volume); AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); int sb2value = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); sb2value = sb2value * speech_volume / 100; am.setStreamVolume(AudioManager.STREAM_MUSIC, sb2value, 0); vibrate_on = mPrefs.getBoolean("vibrate_on", vibrate_on); metric = mPrefs.getBoolean("metric", metric); mpxData = mPrefs.getBoolean("mpx_data", mpxData); displayAlwaysOn = mPrefs.getBoolean("displayAlwaysOn", displayAlwaysOn); voltage_speech_ack = mPrefs.getBoolean("voltage_speech_ack", voltage_speech_ack); valueTmp = voltage_speech_label + ";" + voltage_speech_unit; valueTmp = mPrefs.getString("voltage_speech_text", valueTmp); if (!valueTmp.equals("") && valueTmp.contains(";")) { StringTokenizer tokens = new StringTokenizer(valueTmp, ";"); voltage_speech_label = tokens.nextToken().trim(); voltage_speech_unit = tokens.nextToken().trim(); } height_speech_ack = mPrefs.getBoolean("height_speech_ack", height_speech_ack); auto_connect = mPrefs.getBoolean("auto_connect", auto_connect); mpxData = mPrefs.getBoolean("mpx_data", mpxData); valueTmp = height_speech_label + ";" + height_speech_unit; valueTmp = mPrefs.getString("height_speech_text", valueTmp); if (!valueTmp.equals("") && valueTmp.contains(";")) { StringTokenizer tokens = new StringTokenizer(valueTmp, ";"); height_speech_label = tokens.nextToken().trim(); height_speech_unit = tokens.nextToken().trim(); } current_speech_ack = mPrefs.getBoolean("current_speech_ack", current_speech_ack); valueTmp = current_speech_label + ";" + current_speech_unit; valueTmp = mPrefs.getString("current_speech_text", valueTmp); if (!valueTmp.equals("") && valueTmp.contains(";")) { StringTokenizer tokens = new StringTokenizer(valueTmp, ";"); current_speech_label = tokens.nextToken().trim(); current_speech_unit = tokens.nextToken().trim(); } used_speech_ack = mPrefs.getBoolean("used_speech_ack", used_speech_ack); valueTmp = used_speech_label + ";" + used_speech_unit; valueTmp = mPrefs.getString("used_speech_text", valueTmp); if (!valueTmp.equals("") && valueTmp.contains(";")) { StringTokenizer tokens = new StringTokenizer(valueTmp, ";"); used_speech_label = tokens.nextToken().trim(); used_speech_unit = tokens.nextToken().trim(); } speed_speech_ack = mPrefs.getBoolean("speed_speech_ack", speed_speech_ack); valueTmp = speed_speech_label + ";" + speed_speech_unit; valueTmp = mPrefs.getString("speed_speech_text", valueTmp); if (!valueTmp.equals("") && valueTmp.contains(";")) { StringTokenizer tokens = new StringTokenizer(valueTmp, ";"); speed_speech_label = tokens.nextToken().trim(); speed_speech_unit = tokens.nextToken().trim(); } vario_delay = mPrefs.getString("vario_delay", vario_delay); rpm_speech_ack = mPrefs.getBoolean("rpm_speech_ack", rpm_speech_ack); valueTmp = rpm_speech_label + ";" + rpm_speech_unit; valueTmp = mPrefs.getString("rpm_speech_text", valueTmp); if (!valueTmp.equals("") && valueTmp.contains(";")) { StringTokenizer tokens = new StringTokenizer(valueTmp, ";"); rpm_speech_label = tokens.nextToken().trim(); rpm_speech_unit = tokens.nextToken().trim(); } temp_speech_ack = mPrefs.getBoolean("temp_speech_ack", temp_speech_ack); valueTmp = temp_speech_label + ";" + temp_speech_unit; valueTmp = mPrefs.getString("temp_speech_text", valueTmp); if (!valueTmp.equals("") && valueTmp.contains(";")) { StringTokenizer tokens = new StringTokenizer(valueTmp, ";"); temp_speech_label = tokens.nextToken().trim(); temp_speech_unit = tokens.nextToken().trim(); } } catch (Exception e) { } valueTmp = mPrefs.getString("log_file", log_file); if (valueTmp != "") { log_file = valueTmp; } valueTmp = mPrefs.getString("bluetooth_device", bluetooth_device); if (valueTmp != "") { bluetooth_device = valueTmp; } mSound_on = mPrefs.getBoolean("sound_on", mSound_on); speech_on = mPrefs.getBoolean("speech_on", speech_on); speech_intervall = mPrefs.getString("speech_intervall", speech_intervall); speech_alert_intervall = mPrefs.getString("speech_alert_intervall", speech_alert_intervall); mAlarm_on = mPrefs.getBoolean("alarm_on", mAlarm_on); mSpeak_on = mPrefs.getBoolean("speak_on", mSpeak_on); mlog_file = mPrefs.getBoolean("logging_on", mlog_file); alert_tone = mPrefs.getString("ringtone", alert_tone); label_rpm1 = mPrefs.getString("label_rpm1", label_rpm1); label_rpm2 = mPrefs.getString("label_rpm2", label_rpm2); label_temp1 = mPrefs.getString("label_temp1", label_temp1); label_temp2 = mPrefs.getString("label_temp2", label_temp2); unit_rpm1 = mPrefs.getString("unit_rpm1", unit_rpm1); unit_rpm2 = mPrefs.getString("unit_rpm2", unit_rpm2); unit_temp1 = mPrefs.getString("unit_temp1", unit_temp1); unit_temp2 = mPrefs.getString("unit_temp2", unit_temp2); current_sensor_type = mPrefs.getString("current_sensor_type", current_sensor_type); vario_delay = mPrefs.getString("vario_delay", vario_delay); alarm_voltage = mPrefs.getBoolean("alarm_voltage", alarm_voltage); alarm_used = mPrefs.getBoolean("alarm_used", alarm_used); alarm_current = mPrefs.getBoolean("alarm_current", alarm_current); alarm_speed = mPrefs.getBoolean("alarm_speed", alarm_speed); alarm_fuel = mPrefs.getBoolean("alarm_fuel", alarm_fuel); alarm_temperature = mPrefs.getBoolean("alarm_temperature", alarm_temperature); alarm_altitude = mPrefs.getBoolean("alarm_altitude", alarm_altitude); alarm_rpm = mPrefs.getBoolean("alarm_rpm", alarm_rpm); alarm_power = mPrefs.getBoolean("alarm_power", alarm_power); speak_voltage = mPrefs.getBoolean("speak_voltage", speak_voltage); speak_used = mPrefs.getBoolean("speak_used", speak_used); speak_current = mPrefs.getBoolean("speak_current", speak_current); speak_speed = mPrefs.getBoolean("speak_speed", speak_speed); speak_fuel = mPrefs.getBoolean("speak_fuel", speak_fuel); speak_temperature = mPrefs.getBoolean("speak_temperature", speak_temperature); speak_altitude = mPrefs.getBoolean("speak_altitude", speak_altitude); speak_rpm = mPrefs.getBoolean("speak_rpm", speak_rpm); speak_power = mPrefs.getBoolean("speak_power", speak_power); if (rpm1Label != null) rpm1Label.setText(label_rpm1); if (rpm2Label != null) rpm2Label.setText(label_rpm2); if (tempLabel != null) tempLabel.setText(label_temp1); if (temp2Label != null) temp2Label.setText(label_temp2); if (rpm1_unit != null) rpm1_unit.setText(unit_rpm1); if (rpm2_unit != null) rpm2_unit.setText(unit_rpm2); if (temp1_unit != null) temp1_unit.setText(unit_temp1); if (temp1_unit != null) temp1_unit.setText(unit_temp2); if (alert_tone.equals("")) { uri = null; } else { uri = Uri.parse(alert_tone); } if (mp != null) { mp.stop(); mp.release(); mp = null; if (uri != null && !uri.toString().equals("res/raw/alarm.mp3")) { mp = MediaPlayer.create(getApplicationContext(), uri); } else { mp = MediaPlayer.create(getApplicationContext(), R.raw.alarm); } } }
From source file:com.sentaroh.android.TaskAutomation.TaskExecutor.java
final static public void playBackMusic(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse taskResponse, ActionResponse ar, String action, String dlg_id, String fp, String vol_left, String vol_right) { ar.action_resp = ActionResponse.ACTION_SUCCESS; File lf = new File(fp); if (!lf.exists()) { ar.action_resp = ActionResponse.ACTION_ERROR; ar.resp_msg_text = String.format(taskMgrParms.teMsgs.msgs_thread_task_play_sound_notfound, fp); return;// w ww .ja v a 2 s . c o m } if (!isRingerModeNormal(envParms)) { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = taskMgrParms.teMsgs.msgs_thread_task_exec_ignore_sound_ringer_not_normal; return; } MediaPlayer player = MediaPlayer.create(taskMgrParms.context, Uri.parse(fp)); taskResponse.active_action_name = action; if (player != null) { int duration = player.getDuration(); TaskManager.showMessageDialog(taskMgrParms, envParms, util, taskResponse.active_group_name, taskResponse.active_task_name, taskResponse.active_action_name, taskResponse.active_dialog_id, MESSAGE_DIALOG_MESSAGE_TYPE_SOUND, fp); if (!vol_left.equals("-1") && !vol_left.equals("")) player.setVolume(Float.valueOf(vol_left) / 100, Float.valueOf(vol_right) / 100); player.start(); waitTimeTc(taskResponse, duration + 10); if (!taskResponse.active_thread_ctrl.isEnable()) { ar.action_resp = ActionResponse.ACTION_CANCELLED; ar.resp_msg_text = "Action was cancelled"; } player.stop(); player.release(); TaskManager.closeMessageDialog(taskMgrParms, envParms, util, taskResponse); } else { ar.action_resp = ActionResponse.ACTION_ERROR; ar.resp_msg_text = String.format(taskMgrParms.teMsgs.msgs_thread_task_play_sound_error, fp); } }
From source file:com.ruesga.timelinechart.TimelineChartView.java
private void setupSoundEffects() { if (mPlaySelectionSoundEffect && mSelectionSoundEffectSource != SYSTEM_SOUND_EFFECT) { if (mSoundEffectMP == null) { mSoundEffectMP = MediaPlayer.create(getContext(), mSelectionSoundEffectSource); mSoundEffectMP.setVolume(SOUND_EFFECT_VOLUME, SOUND_EFFECT_VOLUME); }// ww w .j ava2 s. co m } else if (mSoundEffectMP != null) { releaseSoundEffects(); } }
From source file:com.sentaroh.android.TaskAutomation.TaskExecutor.java
final static public void playBackRingtone(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse taskResponse, ActionResponse ar, String dlg_id, String rt, String rn, String rp, String vol_left, String vol_right) { ar.action_resp = ActionResponse.ACTION_SUCCESS; if (!isRingerModeNormal(envParms)) { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = taskMgrParms.teMsgs.msgs_thread_task_exec_ignore_sound_ringer_not_normal; return;//from w ww.java 2 s. c o m } MediaPlayer player = MediaPlayer.create(taskMgrParms.context, Uri.parse("content://media" + rp)); // taskResponse.active_action_name=action; if (player != null) { int duration = 0; if (!rt.equals(PROFILE_ACTION_RINGTONE_TYPE_NOTIFICATION)) duration = RINGTONE_PLAYBACK_TIME; else duration = player.getDuration(); if (duration >= 5000) { TaskManager.showMessageDialog(taskMgrParms, envParms, util, taskResponse.active_group_name, taskResponse.active_task_name, taskResponse.active_action_name, taskResponse.active_dialog_id, MESSAGE_DIALOG_MESSAGE_TYPE_SOUND, rt + " " + rn); } if (!vol_left.equals("-1") && !vol_left.equals("")) player.setVolume(Float.valueOf(vol_left) / 100, Float.valueOf(vol_right) / 100); player.start(); waitTimeTc(taskResponse, duration + 10); if (!taskResponse.active_thread_ctrl.isEnable()) { ar.action_resp = ActionResponse.ACTION_CANCELLED; ar.resp_msg_text = "Action was cancelled"; } player.stop(); player.release(); if (duration >= 5000) { TaskManager.closeMessageDialog(taskMgrParms, envParms, util, taskResponse); } } else { ar.action_resp = ActionResponse.ACTION_ERROR; ar.resp_msg_text = String.format(taskMgrParms.teMsgs.msgs_thread_task_play_sound_error, rp); } }