コード例 #1
0
 /** Stops a playing ringtone. */
 public void stop() {
   if (mLocalPlayer != null) {
     destroyLocalPlayer();
   } else if (mAllowRemote && (mRemotePlayer != null)) {
     try {
       mRemotePlayer.stop(mRemoteToken);
     } catch (RemoteException e) {
       Log.w(TAG, "Problem stopping ringtone: " + e);
     }
   }
 }
コード例 #2
0
 /** @hide */
 public void setVolume(float volume) {
   if (mLocalPlayer != null) {
     mLocalPlayer.setVolume(volume);
   } else if (mAllowRemote && mRemotePlayer != null) {
     try {
       mRemotePlayer.setVolume(mRemoteToken, volume);
     } catch (RemoteException e) {
       Log.w(TAG, "Problem setting ringtone volume: " + e);
     }
   }
 }
コード例 #3
0
 /**
  * Whether this ringtone is currently playing.
  *
  * @return True if playing, false otherwise.
  */
 public boolean isPlaying() {
   if (mLocalPlayer != null) {
     return mLocalPlayer.isPlaying();
   } else if (mAllowRemote && (mRemotePlayer != null)) {
     try {
       return mRemotePlayer.isPlaying(mRemoteToken);
     } catch (RemoteException e) {
       Log.w(TAG, "Problem checking ringtone: " + e);
       return false;
     }
   } else {
     Log.w(TAG, "Neither local nor remote playback available");
     return false;
   }
 }
コード例 #4
0
 /** 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");
     }
   }
 }