Exemplo n.º 1
0
  private void init(Media media) {
    mType = TYPE_ALL;

    if (media != null) {
      if (media.isParsed()) {
        mLength = media.getDuration();

        for (int i = 0; i < media.getTrackCount(); ++i) {
          final Media.Track track = media.getTrack(i);
          if (track == null) continue;
          if (track.type == Media.Track.Type.Video) {
            final Media.VideoTrack videoTrack = (VideoTrack) track;
            mType = TYPE_VIDEO;
            mWidth = videoTrack.width;
            mHeight = videoTrack.height;
          } else if (mType == TYPE_ALL && track.type == Media.Track.Type.Audio) {
            mType = TYPE_AUDIO;
          }
        }
      }
      updateMeta(media);
      if (mType == TYPE_ALL && media.getType() == Media.Type.Directory) mType = TYPE_DIR;
    }

    if (mType == TYPE_ALL) {
      final String location = mUri.toString();
      int dotIndex = location.lastIndexOf(".");
      if (dotIndex != -1) {
        String fileExt = location.substring(dotIndex).toLowerCase(Locale.ENGLISH);
        if (Extensions.VIDEO.contains(fileExt)) {
          mType = TYPE_VIDEO;
        } else if (Extensions.AUDIO.contains(fileExt)) {
          mType = TYPE_AUDIO;
        } else if (Extensions.SUBTITLES.contains(fileExt)) {
          mType = TYPE_SUBTITLE;
        } else if (Extensions.PLAYLIST.contains(fileExt)) {
          mType = TYPE_PLAYLIST;
        }
      }
    }
  }
Exemplo n.º 2
0
 public void updateMeta(MediaPlayer mediaPlayer) {
   final Media media = mediaPlayer.getMedia();
   if (media == null) return;
   updateMeta(media);
   media.release();
 }