List of usage examples for android.media MediaPlayer create
public static MediaPlayer create(Context context, int resid)
From source file:esolz.connexstudent.apprtc.ConnectActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //=============Power locker threadmanager = new Handler(); callRejectionThred = new Runnable() { @Override/*from www .ja va 2 s. c o m*/ public void run() { //======Missed Call and no answer SimpleDateFormat frmatr = new SimpleDateFormat("dd MMM,yyyy-HH:mm"); cDB.insertInLogTable(getIntent().getStringExtra("PHONE"), cDB.getUserNameFromPhone(getIntent().getStringExtra("PHONE")), cDB.getUserImage(getIntent().getStringExtra("PHONE")), "missed", frmatr.format(new Date(Calendar.getInstance().getTimeInMillis()))); fireMissedCall(cDB.getUserNameFromPhone(getIntent().getStringExtra("PHONE"))); //================================== Intent i = new Intent(getApplicationContext(), RingToneService.class); i.setAction(RingToneService.ACTION_KILL); startService(i); finish(); } }; powerManager = (PowerManager) getSystemService(POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "RingToneServiceLockerActivity"); wakeLock.acquire(); cDB = new ConnexDB(getApplicationContext()); // Get setting keys. PreferenceManager.setDefaultValues(this, R.xml.preferences, false); sharedPref = PreferenceManager.getDefaultSharedPreferences(this); keyprefVideoCallEnabled = getString(R.string.pref_videocall_key); keyprefResolution = getString(R.string.pref_resolution_key); keyprefFps = getString(R.string.pref_fps_key); keyprefCaptureQualitySlider = getString(R.string.pref_capturequalityslider_key); keyprefVideoBitrateType = getString(R.string.pref_startvideobitrate_key); keyprefVideoBitrateValue = getString(R.string.pref_startvideobitratevalue_key); keyprefVideoCodec = getString(R.string.pref_videocodec_key); keyprefHwCodecAcceleration = getString(R.string.pref_hwcodec_key); keyprefCaptureToTexture = getString(R.string.pref_capturetotexture_key); keyprefAudioBitrateType = getString(R.string.pref_startaudiobitrate_key); keyprefAudioBitrateValue = getString(R.string.pref_startaudiobitratevalue_key); keyprefAudioCodec = getString(R.string.pref_audiocodec_key); keyprefNoAudioProcessingPipeline = getString(R.string.pref_noaudioprocessing_key); keyprefAecDump = getString(R.string.pref_aecdump_key); keyprefOpenSLES = getString(R.string.pref_opensles_key); keyprefDisplayHud = getString(R.string.pref_displayhud_key); keyprefTracing = getString(R.string.pref_tracing_key); keyprefRoomServerUrl = getString(R.string.pref_room_server_url_key); keyprefRoom = getString(R.string.pref_room_key); keyprefRoomList = getString(R.string.pref_room_list_key); setContentView(R.layout.activity_connect); getWindow().setFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON, WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); getWindow().setFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED, WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); //=============permission management findViewById(R.id.notifoicatio).setVisibility(View.GONE); permissionChk(); findViewById(R.id.rcv_call).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //======Missed Call and no answer threadmanager.removeCallbacks(callRejectionThred); SimpleDateFormat frmatr = new SimpleDateFormat("dd MMM,yyyy-HH:mm"); cDB.insertInLogTable(getIntent().getStringExtra("PHONE"), cDB.getUserNameFromPhone(getIntent().getStringExtra("PHONE")), cDB.getUserImage(getIntent().getStringExtra("PHONE")), "received", frmatr.format(new Date(Calendar.getInstance().getTimeInMillis()))); //================================== Intent i = new Intent(getApplicationContext(), RingToneService.class); i.setAction(RingToneService.ACTION_KILL_WITH_NOTHING); startService(i); ROOM_NAME = getIntent().getStringExtra("ROOM_NAME"); pushHelperDhoperUrlAcceptence(); } }); findViewById(R.id.end_call).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (getIntent().getAction().equals(ACTION_APP)) { try { if (mPlayer.isPlaying()) { mPlayer.stop(); mPlayer.release(); } finish(); } catch (Exception e) { e.printStackTrace(); } dialoerRejection(ConnexConstante.DOMAIN_URL + "push_send?roomId=000000&sender_id=" + ConnexApplication.getInstance().getUserID() + "&receiver_id=" + RECEIVER_ID + "&mod=callEnded&pem_mod=prod"); } else { //======Missed Call and Rejected by You //======Missed Call and no answer threadmanager.removeCallbacks(callRejectionThred); SimpleDateFormat frmatr = new SimpleDateFormat("dd MMM,yyyy-HH:mm"); cDB.insertInLogTable(getIntent().getStringExtra("PHONE"), cDB.getUserNameFromPhone(getIntent().getStringExtra("PHONE")), cDB.getUserImage(getIntent().getStringExtra("PHONE")), "missed", frmatr.format(new Date(Calendar.getInstance().getTimeInMillis()))); fireMissedCall(cDB.getUserNameFromPhone(getIntent().getStringExtra("PHONE"))); //================================== //================================== Intent i = new Intent(getApplicationContext(), RingToneService.class); i.setAction(RingToneService.ACTION_KILL); startService(i); } finish(); } }); if (mPlayer == null) { mPlayer = MediaPlayer.create(ConnectActivity.this, R.raw.dialing); } }
From source file:com.eyetools.pediatrics.pediatricfixation.MainFixationFragment.java
private void reloadSound() { if (soundPlayer != null) { try {// www . j a v a2 s .co m if (soundPlayer.isPlaying()) { soundPlayer.stop(); } soundPlayer.release(); soundPlayer = MediaPlayer.create(mainAct, ((Anim) mViewTypes.get(mMajorViewType).get(mViewIndex)).resId); soundPlayer.setLooping(true); if (mSound) { soundPlayer.start(); } } catch (Exception e) { Log.d(TAG, "error nextImage"); } } }
From source file:com.android.returncandidate.activities.SdmScannerActivity.java
/** * Initialize screen layout/*www . j ava 2 s. c o m*/ * * @param state {@link Bundle} */ @Override public void onCreate(Bundle state) { LogManager.i(TAG, Message.TAG_SCANNER_ACTIVITY + Message.MESSAGE_ACTIVITY_START); super.onCreate(state); setContentView(R.layout.activity_sdm_scanner); // Load user info Bundle bundle = getIntent().getExtras(); if (bundle != null) { userID = bundle.getString(Constants.COLUMN_USER_ID); shopID = bundle.getString(Constants.COLUMN_SHOP_ID); serverName = bundle.getString(Constants.COLUMN_SERVER_NAME); license = bundle.getString(Constants.COLUMN_LICENSE); hashMapArrBook = (HashMap<String, LinkedList<String[]>>) bundle .getSerializable(Constants.COLUMN_INFOR_LIST_SCAN); } Log.d("LINCONGPVScan", license); //Set default start app flagSettingNew = new FlagSettingNew(); flagSettingOld = new FlagSettingOld(); common = new Common(); // UI init Users user = new UserModel().getUserInfo(); TextView tvUserName = (TextView) findViewById(R.id.txv_user_name); tvUserName.setText(user.getName()); lvBook = (ListView) findViewById(R.id.list_book); arrBookInlist = new LinkedList<>(); if (hashMapArrBook != null) { arrBookInlist = new LinkedList<>(hashMapArrBook.get(Constants.COLUMN_INFOR_LIST_SCAN)); } mBookModel = new BookModel(); maxYearRankModel = new MaxYearRankModel(); DatabaseManager.initializeInstance(new DatabaseHelper(getApplicationContext())); //Default flag setting new ArrayList<String> arrPublisherCd = new ArrayList<>(); ArrayList<String> arrPublisherName = new ArrayList<>(); ArrayList<String> arrGroup1Cd = new ArrayList<>(); ArrayList<String> arrGroup1Name = new ArrayList<>(); ArrayList<String> arrGroup2Cd = new ArrayList<>(); ArrayList<String> arrGroup2Name = new ArrayList<>(); arrPublisherCd.add(Constants.ID_ROW_ALL); arrPublisherName.add(Constants.ROW_ALL); arrGroup1Cd.add(Constants.ID_ROW_ALL); arrGroup1Name.add(Constants.ROW_ALL); arrGroup2Cd.add(Constants.ID_ROW_ALL); arrGroup2Name.add(Constants.ROW_ALL); maxYearRank = maxYearRankModel.getMaxYearRank(); //Get list default group1 cd List<CLP> listDefaultGroup1 = mBookModel.getInfoGroupCd1(); List<CLP> listDefaultGroup2 = mBookModel.getInfoGroupCd2(Constants.ID_ROW_ALL); for (int i = 0; i < listDefaultGroup1.size(); i++) { arrGroup1Cd.add(listDefaultGroup1.get(i).getId()); arrGroup1Name.add(listDefaultGroup1.get(i).getName()); } for (int i = 0; i < listDefaultGroup2.size(); i++) { arrGroup2Cd.add(listDefaultGroup2.get(i).getId()); arrGroup2Name.add(listDefaultGroup2.get(i).getName()); } flagSettingNew.setFlagClassificationGroup1Cd(arrGroup1Cd); flagSettingNew.setFlagClassificationGroup1Name(arrGroup1Name); flagSettingNew.setFlagClassificationGroup2Cd(arrGroup2Cd); flagSettingNew.setFlagClassificationGroup2Name(arrGroup2Name); flagSettingNew.setFlagPublisher(arrPublisherCd); flagSettingNew.setFlagPublisherShowScreen(arrPublisherName); flagSettingNew.setFlagReleaseDate(Constants.FLAG_DEFAULT); flagSettingNew.setFlagReleaseDateShowScreen(Constants.FLAG_DEFAULT_RELEASE_DATE_SHOW); flagSettingNew.setFlagUndisturbed(Constants.FLAG_DEFAULT); flagSettingNew.setFlagUndisturbedShowScreen(Constants.FLAG_DEFAULT_UNDISTURBED_SHOW); flagSettingNew.setFlagNumberOfStocks(Constants.FLAG_DEFAULT); flagSettingNew.setFlagNumberOfStocksShowScreen(Constants.FLAG_DEFAULT_NUMBER_OF_STOCKS_SHOW); flagSettingNew.setFlagStockPercent(Constants.FLAG_DEFAULT); flagSettingNew.setFlagStockPercentShowScreen(Constants.FLAG_DEFAULT_STOCKS_PERCENT_SHOW); flagSettingNew.setFlagJoubi(Constants.VALUE_YES_STANDING); // Default flag setting old flagSettingOld.setFlagClassificationGroup1Cd(arrGroup1Cd); flagSettingOld.setFlagClassificationGroup1Name(arrGroup1Name); flagSettingOld.setFlagClassificationGroup2Cd(arrGroup2Cd); flagSettingOld.setFlagClassificationGroup2Name(arrGroup2Name); flagSettingOld.setFlagPublisher(arrPublisherCd); flagSettingOld.setFlagPublisherShowScreen(arrPublisherName); flagSettingOld.setFlagReleaseDate(Constants.FLAG_DEFAULT); flagSettingOld.setFlagReleaseDateShowScreen(Constants.FLAG_DEFAULT_RELEASE_DATE_SHOW); flagSettingOld.setFlagUndisturbed(Constants.FLAG_DEFAULT); flagSettingOld.setFlagUndisturbedShowScreen(Constants.FLAG_DEFAULT_UNDISTURBED_SHOW); flagSettingOld.setFlagNumberOfStocks(Constants.FLAG_DEFAULT); flagSettingOld.setFlagNumberOfStocksShowScreen(Constants.FLAG_DEFAULT_NUMBER_OF_STOCKS_SHOW); flagSettingOld.setFlagStockPercent(Constants.FLAG_DEFAULT); flagSettingOld.setFlagStockPercentShowScreen(Constants.FLAG_DEFAULT_STOCKS_PERCENT_SHOW); flagSettingOld.setFlagJoubi(Constants.VALUE_YES_STANDING); //Flag disable OCR flagSwitchOCR = Constants.FLAG_0; flagFilterSubmit = true; // Init process loading screen progress = new ProgressDialog(this); progress.setMessage(Message.MESSAGE_UPLPOAD_LOG_SCREEN); progress.setCancelable(false); // Activate HSM license Log.d("LINCONGPVScanACTIVE1", license); ActivationResult activationResult = ActivationManager.activate(this, license); Toast.makeText(this, "Activation result: " + activationResult, Toast.LENGTH_LONG).show(); decCom = (HSMDecodeComponent) findViewById(R.id.hsm_decodeComponent); // HSM init hsmDecoder = HSMDecoder.getInstance(this); // Declare symbology hsmDecoder.enableSymbology(Symbology.EAN13); // Declare HSM component UI hsmDecoder.enableFlashOnDecode(false); hsmDecoder.enableSound(false); hsmDecoder.enableAimer(false); hsmDecoder.setWindowMode(WindowMode.CENTERING); hsmDecoder.setWindow(18, 42, 0, 100); // Assign listener hsmDecoder.addResultListener(this); // Sound init normalSound = MediaPlayer.create(this, R.raw.pingpong_main); // sound is inside res/raw/mysound noReturnSound = MediaPlayer.create(this, R.raw.wrong_main); // sound is inside res/raw/mysound // Button init btnLogout = (Button) findViewById(R.id.btn_logout); btnCancel = (Button) findViewById(R.id.btn_cancel); imbFilter = (ImageButton) findViewById(R.id.imb_filter); aSwitchOCR = (Switch) findViewById(R.id.switch_OCR); btnLogout.setOnClickListener(this); btnCancel.setOnClickListener(this); imbFilter.setOnClickListener(this); aSwitchOCR.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (aSwitchOCR.isChecked()) { flagSwitchOCR = Constants.FLAG_1; hsmDecoder.enableSymbology(Symbology.OCR); //hsmDecoder.enableSymbology(Symbology.EAN13_ISBN); hsmDecoder.setOCRActiveTemplate(OCRActiveTemplate.ISBN); hsmDecoder.disableSymbology(Symbology.EAN13); } else { flagSwitchOCR = Constants.FLAG_0; hsmDecoder.enableSymbology(Symbology.EAN13); //hsmDecoder.setOCRActiveTemplate(OCRActiveTemplate.ISBN); hsmDecoder.disableSymbology(Symbology.OCR); } } }); //Check if arr list books not null if (arrBookInlist != null) { // Set data adapter to list view ListViewScanAdapter adapterBook = new ListViewScanAdapter(this, arrBookInlist); lvBook.setAdapter(adapterBook); } }
From source file:com.gm.goldencity.util.Utils.java
/** * Play a sound// w w w . j av a 2 s . c o m * * @param context Application context * @param rawID Raw integer id in resource */ public static void playSound(Context context, int rawID) { MediaPlayer mp = MediaPlayer.create(context, rawID); mp.start(); }
From source file:com.lemon.lime.MainActivity.java
private void init() { mPlayer = MediaPlayer.create(this, R.raw.summer); mPlayer.setLooping(true);//from www . j a v a2s. com if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) { getvoicemission(); } else { mVisualizerView = (VisualizerView) findViewById(R.id.visualizerView); mVisualizerView.link(mPlayer); } }
From source file:flex.android.magiccube.activity.ActivityBattleMode.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mode_battle); btMoveBack = (ImageButton) findViewById(R.id.bt_battle_moveback); btMoveForward = (ImageButton) findViewById(R.id.bt_battle_moveforward); btStartOb = (ImageButton) findViewById(R.id.bt_battle_startob); clock = (ImageView) findViewById(R.id.img_battle_clock); txtTime = (TextView) findViewById(R.id.txt_battle_time); txtNStep = (TextView) findViewById(R.id.txt_battle_nStep); img_nstep = (ImageView) findViewById(R.id.img_battle_nstep); progress = (SeekBar) findViewById(R.id.sbar_battle_timer); /*//from www .j a v a 2 s .c o m * clock.setVisibility(View.VISIBLE); * btMoveForward.setVisibility(View.VISIBLE); * btMoveBack.setVisibility(View.VISIBLE); */ glView = (ViewBattleMode) findViewById(R.id.game_view_battle); glView.SetOnTimerListener(this); // glView.setOnStateListener(this); glView.SetOnStepListener(this); glView.SetMessageSender(this); glView.SetDrawCube(false); glView.setOnStateListener(this); glView2 = (ViewBattleMode) findViewById(R.id.game_view_battle2); glView2.SetCanMove(false); btMoveBack.setOnClickListener(buttonListener); btMoveForward.setOnClickListener(buttonListener); btStartOb.setOnClickListener(buttonListener); float fontsize = 25.f; Typeface typeFace = Typeface.createFromAsset(getAssets(), "fonts/Angies New House.ttf"); txtTime.setTypeface(typeFace); txtTime.setTextColor(Color.GRAY); txtTime.setTextSize(fontsize); txtNStep.setTypeface(typeFace); txtNStep.setTextColor(Color.GRAY); txtNStep.setTextSize(fontsize); State = OnStateListener.NONE; BgVolume = MagiccubePreference.GetPreference(MagiccubePreference.BgVolume, this); LinearBgVolume = MusicPlayThread.GetLinearVolume(BgVolume); GamingbgmPlayer = MediaPlayer.create(this, R.raw.bg2); ObservingbgmPlayer = MediaPlayer.create(this, R.raw.bg); FinishbgmPlayer = MediaPlayer.create(this, R.raw.finish); GamingbgmPlayer.setVolume(LinearBgVolume, LinearBgVolume); ObservingbgmPlayer.setVolume(LinearBgVolume, LinearBgVolume); FinishbgmPlayer.setVolume(LinearBgVolume, LinearBgVolume); Init(); // Get local Bluetooth adapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); // If the adapter is null, then Bluetooth is not supported if (mBluetoothAdapter == null) { Toast.makeText(this, "...", Toast.LENGTH_LONG).show(); finish(); return; } WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); width = wm.getDefaultDisplay().getWidth(); height = wm.getDefaultDisplay().getHeight(); layout_moveforward = (LinearLayout) findViewById(R.id.layout_battle_moveforward); layout_moveback = (LinearLayout) findViewById(R.id.layout_battle_moveback); int buttonwidth = width / 5; int buttonheight = height / 13; LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(buttonwidth, buttonheight); btMoveForward.setLayoutParams(parms); btMoveBack.setLayoutParams(parms); layout_moveforward.setPadding(width / 2 - buttonwidth / 2, height - buttonheight, 0, 0); layout_moveback.setPadding(width / 15, height - buttonheight, 0, 0); }
From source file:com.example.administrator.myapplication2._2_exercise._2_Status_heart.fragments.LeftFragment.java
public void warning() { alertCount++;/*w ww . ja va2 s . c om*/ if (playBool == true && (alertCount % 5 == 0)) { MediaPlayer ss1; ss1 = MediaPlayer.create(getActivity(), R.raw.alertsound2); // ss1.setLooping(true); ss1.start(); Vibrator vibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(2000); android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder( getActivity(), R.style.AppCompatAlertDialogStyle); builder.setTitle("?? "); builder.setMessage( " ? \nMAXIMUM ?\n" + "5 ?? ??.\n" + "? \n?? ."); builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { playBool = true; } }); builder.show(); playBool = false; } }
From source file:com.mobileman.moments.android.frontend.activity.IncomingCallActivity.java
private void playRingtone() { AudioManager audioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE); if ((audioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) || (audioManager.getStreamVolume(AudioManager.STREAM_RING) == 0)) { vibrate();/*w w w . j a v a 2 s .c o m*/ delayHandler = new Handler(); delayHandler.postDelayed(new Runnable() { public void run() { sendNotificationAndFinish(); } }, MAXIMUM_CALL_NOTIFICATION_DURATION); } else if (audioManager.getRingerMode() != AudioManager.RINGER_MODE_SILENT) { if (mPlayer == null) { mPlayer = MediaPlayer.create(getApplicationContext(), R.raw.moments_30s); // mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mediaPlayer) { sendNotificationAndFinish(); } }); mPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() { @Override public boolean onError(MediaPlayer mediaPlayer, int i, int i2) { sendNotificationAndFinish(); return false; } }); mPlayer.start(); } } }
From source file:org.gearvrf.keyboard.util.Util.java
public static void loadAudioClipAndPlay(Context context, int idResource) { MediaPlayer mediaPlayer = MediaPlayer.create(context, idResource); mediaPlayer.start();//from w w w . ja v a2s . c o m }
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();// ww w .jav a2s . c o m } } 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); }