コード例 #1
0
 @DSComment("Private Method")
 @DSBan(DSCat.PRIVATE_METHOD)
 @DSGenerator(
     tool_name = "Doppelganger",
     tool_version = "2.0",
     generated_on = "2013-12-30 12:28:26.967 -0500",
     hash_original_method = "3D9FD67EE5212878A40EB00FDD255FB4",
     hash_generated_method = "64022A1AA54923F2F5BCB6D43B903CE2")
 private void openMediaPlayer() throws IOException {
   if (mAudio != null) {
     mAudio.release();
   }
   mAudio = new MediaPlayer();
   if (mUri != null) {
     mAudio.setDataSource(mContext, mUri);
   } else if (mFileDescriptor != null) {
     mAudio.setDataSource(mFileDescriptor);
   } else if (mAssetFileDescriptor != null) {
     // Note: using getDeclaredLength so that our behavior is the same
     // as previous versions when the content provider is returning
     // a full file.
     if (mAssetFileDescriptor.getDeclaredLength() < 0) {
       mAudio.setDataSource(mAssetFileDescriptor.getFileDescriptor());
     } else {
       mAudio.setDataSource(
           mAssetFileDescriptor.getFileDescriptor(),
           mAssetFileDescriptor.getStartOffset(),
           mAssetFileDescriptor.getDeclaredLength());
     }
   } else {
     throw new IOException("No data source set.");
   }
   mAudio.setAudioStreamType(mStreamType);
   mAudio.prepare();
 }
コード例 #2
0
  /**
   * Set {@link Uri} to be used for ringtone playback. Attempts to open locally, otherwise will
   * delegate playback to remote {@link IRingtonePlayer}.
   *
   * @hide
   */
  public void setUri(Uri uri) {
    destroyLocalPlayer();

    mUri = uri;
    if (mUri == null) {
      return;
    }

    // TODO: detect READ_EXTERNAL and specific content provider case, instead of relying on throwing

    if (isSoundCustomized()) {
      // instead of restore to default ringtone.
      restoreRingtoneIfNotExist(Settings.System.RINGTONE);
      restoreRingtoneIfNotExist(Settings.System.RINGTONE_2);
    }

    // try opening uri locally before delegating to remote player
    mLocalPlayer = new MediaPlayer();
    try {
      mLocalPlayer.setDataSource(mContext, mUri);
      mLocalPlayer.setAudioAttributes(mAudioAttributes);
      mLocalPlayer.prepare();

    } catch (SecurityException | IOException e) {
      destroyLocalPlayer();
      if (!mAllowRemote) {
        Log.w(TAG, "Remote playback not allowed: " + e);
      }
    }

    if (LOGD) {
      if (mLocalPlayer != null) {
        Log.d(TAG, "Successfully created local player");
      } else {
        Log.d(TAG, "Problem opening; delegating to remote player");
      }
    }
  }
コード例 #3
0
 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;
 }