/** Plays the ringtone. */ @DSGenerator( tool_name = "Doppelganger", tool_version = "2.0", generated_on = "2013-12-30 12:28:26.977 -0500", hash_original_method = "F9F3FD902406E9F982D2A30CB15B8CC4", hash_generated_method = "D19C91221B1080DB646063B49CD92AD8") public void play() { if (mAudio == null) { try { openMediaPlayer(); } catch (Exception ex) { Log.e(TAG, "play() caught ", ex); mAudio = null; } } if (mAudio != null) { // do not ringtones if stream volume is 0 // (typically because ringer mode is silent). if (mAudioManager.getStreamVolume(mStreamType) != 0) { mAudio.start(); } } }
/** Plays the ringtone. */ public void play() { if (mLocalPlayer != null) { // do not play ringtones if stream volume is 0 // (typically because ringer mode is silent). if (mAudioManager.getStreamVolume(AudioAttributes.toLegacyStreamType(mAudioAttributes)) != 0) { mLocalPlayer.start(); } } else if (mAllowRemote && (mRemotePlayer != null)) { final Uri canonicalUri = mUri.getCanonicalUri(); try { mRemotePlayer.play(mRemoteToken, canonicalUri, mAudioAttributes); } catch (RemoteException e) { if (!playFallbackRingtone()) { Log.w(TAG, "Problem playing ringtone: " + e); } } } else { if (!playFallbackRingtone()) { Log.w(TAG, "Neither local nor remote playback available"); } } }
private boolean playFallbackRingtone() { if (mAudioManager.getStreamVolume(AudioAttributes.toLegacyStreamType(mAudioAttributes)) != 0) { int subId = RingtoneManager.getDefaultRingtoneSubIdByUri(mUri); if (subId != -1 && RingtoneManager.getActualRingtoneUriBySubId(mContext, subId) != null) { // Default ringtone, try fallback ringtone. try { AssetFileDescriptor afd = mContext.getResources().openRawResourceFd(com.android.internal.R.raw.fallbackring); if (afd != null) { mLocalPlayer = new MediaPlayer(); if (afd.getDeclaredLength() < 0) { mLocalPlayer.setDataSource(afd.getFileDescriptor()); } else { mLocalPlayer.setDataSource( afd.getFileDescriptor(), afd.getStartOffset(), afd.getDeclaredLength()); } mLocalPlayer.setAudioAttributes(mAudioAttributes); mLocalPlayer.prepare(); mLocalPlayer.start(); afd.close(); return true; } else { Log.e(TAG, "Could not load fallback ringtone"); } } catch (IOException ioe) { destroyLocalPlayer(); Log.e(TAG, "Failed to open fallback ringtone"); } catch (NotFoundException nfe) { Log.e(TAG, "Fallback ringtone does not exist"); } } else { Log.w(TAG, "not playing fallback for " + mUri); } } return false; }