@Override public void run() { try { String line; while ((line = reader.readLine()) != null) { Matcher matcher = Pattern.compile(MediaInfo.INPUT_PATTERN).matcher(line); if (matcher.find()) { currentMediaInfo = new MediaInfo(); mediaInfos.add(currentMediaInfo); continue; } matcher = Pattern.compile(MediaInfo.DURATION_PATTERN).matcher(line); if (matcher.find()) { currentMediaInfo.setDuration(matcher.group(1)); currentMediaInfo.setBitrate(matcher.group(4)); continue; } matcher = Pattern.compile(VideoStreamInfo.PATTERN).matcher(line); if (matcher.find()) { VideoStreamInfo videoStreamInfo = new VideoStreamInfo(); videoStreamInfo.setId(matcher.group(1)); videoStreamInfo.setLanguage(matcher.group(3)); videoStreamInfo.setEncoder(matcher.group(4)); videoStreamInfo.setResolution(matcher.group(6)); videoStreamInfo.setDefaultStream(matcher.group(8) != null); currentMediaInfo.getVideoStreams().add(videoStreamInfo); continue; } matcher = Pattern.compile(AudioStreamInfo.PATTERN).matcher(line); if (matcher.find()) { AudioStreamInfo audioStreamInfo = new AudioStreamInfo(); audioStreamInfo.setId(matcher.group(1)); audioStreamInfo.setLanguage(matcher.group(3)); audioStreamInfo.setEncoder(matcher.group(4)); audioStreamInfo.setFrequency(matcher.group(6)); audioStreamInfo.setChannels(matcher.group(7)); audioStreamInfo.setDefaultStream(matcher.group(8) != null); currentMediaInfo.getAudioStreams().add(audioStreamInfo); } } } catch (Exception e) { /* ignore */ } finally { try { reader.close(); } catch (IOException e) { /* ignore */ } } }
private void updateMissionLog(final MediaInfo mediaInfo) { if (!TextUtils.isEmpty(mediaInfo.toString())) { boolean bLogColors = preferences.getBoolean("logColorsPreference", true); StringBuilder timeText = new StringBuilder(); StringBuilder actionText = new StringBuilder(); // Display log in colors (if preference is set to true) // Note: Some parts are now bold, regardless of the color settings // (Time, Unconfirmed, Serious - like the printed cards) if ((mediaInfo.getTimeColor() == null) || (bLogColors == false)) { timeText.append("<b>" + stopWatch.toString() + "</b>"); } else { timeText.append( "<b><font color=\"" + mediaInfo.getTimeColor() + "\">" + StopWatch.formatTime(mediaInfo.getStartTimeNanos()) + "</b></font>"); } if ((mediaInfo.getTimeColor() == null) || (bLogColors == false)) { actionText.append(mediaInfo.toString()); } else { actionText.append( "<font color=\"" + mediaInfo.getTextColor() + "\">" + mediaInfo.toString() + "</font>"); } missionLog.add( new MissionLog(Html.fromHtml(actionText.toString()), Html.fromHtml(timeText.toString()))); missionActivity.updateMissionLog(missionLog.size() - 1); } }
/** get audios form {@link MediaStore.Audio.Media.EXTERNAL_CONTENT_URI} */ public List<MediaInfo> getAudioInfo() { List<MediaInfo> list = new ArrayList<MediaInfo>(); Cursor cursor = context .getContentResolver() .query( DreamConstant.AUDIO_URI, null, null, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER); if (null == cursor) { } else { if (cursor.moveToFirst()) { MediaInfo mediaInfo = null; do { mediaInfo = new MediaInfo(); long id = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media._ID)); // 音乐id String title = cursor.getString((cursor.getColumnIndex(MediaStore.Audio.Media.TITLE))); // 音乐标题 // Log.d("Yuri", title); String artist = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST)); // 艺术家 String album = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM)); // 专辑 long albumId = cursor.getInt(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID)); long duration = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media.DURATION)); // 时长 long size = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media.SIZE)); // 文件大小 String url = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA)); // 文件路径 int isMusic = cursor.getInt(cursor.getColumnIndex(MediaStore.Audio.Media.IS_MUSIC)); // 是否为音乐 if (isMusic != 0) { // 只把音乐添加到集合当中 mediaInfo.setId(id); mediaInfo.setDisplayName(title); mediaInfo.setArtist(artist); mediaInfo.setAlbum(album); mediaInfo.setAlbumId(albumId); mediaInfo.setDuration(duration); mediaInfo.setSize(size); mediaInfo.setUrl(url); list.add(mediaInfo); } } while (cursor.moveToNext()); } cursor.close(); } return list; }
private synchronized void playNextAudio() { if (activeMediaPlayer != null) { // TODO reuse player activeMediaPlayer.release(); } final MediaInfo mediaInfo = mediaPlayerList.get(playerIndex); activeMediaPlayer = MediaPlayer.create(missionActivity, mediaInfo.getResUri()); updateMissionLog(mediaInfo); if (mediaInfo.isLoopUntilNext() && playerIndex + 1 < mediaPlayerList.size()) { activeMediaPlayer.setLooping(true); planNextAudioTask(); } else { activeMediaPlayer.setOnCompletionListener( new MediaPlayer.OnCompletionListener() { // @Override public void onCompletion(MediaPlayer mp) { activeMediaPlayer.stop(); activeMediaPlayer.release(); activeMediaPlayer = null; if (!stopped) { planNextAudioTask(); } } }); } if (!paused && !stopped) { try { activeMediaPlayer.start(); } catch (IllegalStateException e) { Toast.makeText(missionActivity, R.string.media_failed, Toast.LENGTH_LONG).show(); stop(); } } }
public ArrayList<ElementInfo> gettimeandorderForEncode( ArrayList<ElementInfo> elementInfo, ArrayList<MediaInfo> mMediaInfo, Script mScript) { ArrayList<ElementInfo> mFileOrder = new ArrayList<ElementInfo>(); int ElementCount = elementInfo.size(); // now we need start to put order // the textureId ==> 1:movie, 2-11:bitmap, 12-21:videoBitmap for (int i = 0; i < ElementCount; i++) { ElementInfo eInfo = new ElementInfo(); ElementInfo oldEInfo = elementInfo.get(i); int infoId = elementInfo.get(i).InfoId; for (int j = 0; j < mMediaInfo.size(); j++) { if (mMediaInfo.get(j).CountId == infoId) { MediaInfo tmp = mMediaInfo.get(j); if (tmp.getType() == MediaInfo.MEDIA_TYPE_IMAGE) { if (oldEInfo.Type == MediaInfo.MEDIA_TYPE_IMAGE) { eInfo.height = tmp.getImage().getHeight(); eInfo.width = tmp.getImage().getWidth(); if (tmp.mGeoInfo != null) eInfo.mLocation = tmp.mGeoInfo.getLocation(); } eInfo.Type = MediaInfo.MEDIA_TYPE_IMAGE; eInfo.mFaceCount = tmp.mFaceCount; eInfo.mFBorder = tmp.mFBorder; eInfo.InfoId = tmp.CountId; eInfo.mDate = tmp.getDate(); eInfo.mFaceRect = tmp.mFaceRect; } else if (tmp.getType() == MediaInfo.MEDIA_TYPE_VIDEO) { eInfo.Type = MediaInfo.MEDIA_TYPE_VIDEO; eInfo.TextureId = tmp.TextureId; eInfo.Videopart = oldEInfo.Videopart; eInfo.InfoId = tmp.CountId; eInfo.mDate = tmp.getDate(); } break; } } if (eInfo.Type == -1) eInfo.Type = oldEInfo.Type; mFileOrder.add(eInfo); } return mFileOrder; }
/** get videos form {@link MediaStore.Video.Media.EXTERNAL_CONTENT_URI} */ public List<MediaInfo> getVideoInfo() { List<MediaInfo> list = new ArrayList<MediaInfo>(); ContentResolver contentResolver = context.getContentResolver(); Cursor cursor = contentResolver.query( DreamConstant.VIDEO_URI, null, null, null, MediaStore.Video.Media.DEFAULT_SORT_ORDER); if (null == cursor) { } else { if (cursor.moveToFirst()) { MediaInfo mediaInfo = null; do { mediaInfo = new MediaInfo(); long id = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media._ID)); long duration = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media.DURATION)); // 时长 long size = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media.SIZE)); // 文件大小 String url = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DATA)); // 文件路径 String displayName = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DISPLAY_NAME)); if (new File(url).exists()) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inDither = false; options.inPreferredConfig = Bitmap.Config.ARGB_8888; // get video thumbail Bitmap bitmap = MediaStore.Video.Thumbnails.getThumbnail( contentResolver, id, Images.Thumbnails.MICRO_KIND, options); mediaInfo.setId(id); mediaInfo.setDuration(duration); mediaInfo.setSize(size); mediaInfo.setUrl(url); mediaInfo.setDisplayName(displayName); mediaInfo.setIcon(bitmap); list.add(mediaInfo); } } while (cursor.moveToNext()); } cursor.close(); } return list; }
/** * Retrieve media meta-data information * * @return true if get media meta-data successfully. */ public MediaInfo getMediaInfo() { Parcel p = getParcelParameter(KEY_PARAMETER_MEDIA_INFO); MediaInfo info = new MediaInfo(); if (p.readInt() != 0) { // have video info info.duration = p.readInt(); info.videoHeight = p.readInt(); info.videoWidth = p.readInt(); info.videoCodecId = p.readInt(); info.videoCodecName = p.readString(); info.videoCodecProfile = p.readString(); info.videoFrameRate = p.readFloat(); info.fpaType = p.readInt(); } if (p.readInt() != 0) { // have audio info info.audioCodecId = p.readInt(); info.audioCodecName = p.readString(); info.audioSampleRate = p.readInt(); } p.recycle(); return info; }
public ArrayList<ElementInfo> gettimeandorder( ProcessGL processGL, ArrayList<MediaInfo> mMediaInfo, Script mScript, boolean IsShuffle) { ArrayList<ElementInfo> mFileOrder = new ArrayList<ElementInfo>(); ArrayList<Integer> mFileBucket = new ArrayList<Integer>(); ArrayList<Integer> mRandomBucket = new ArrayList<Integer>(); ArrayList<Integer> mSpaceBucket = new ArrayList<Integer>(); Random mRandom = new Random(System.currentTimeMillis()); int mFileTotalCount = mMediaInfo.size(); // means remove fake file size int mEffectCount = mScript.geteffectsize(); int mNoItemCount = mScript.getNoItemSize(); int mNoCountSize = mScript.getNoCountSize(); int mScriptId = mScript.GetScriptId(); int mRunCount = 0; int mCenterCount = 0; int mStartCount = 0; int mEndCount = 0; int mFHalfCount = 0; int mLHalfCount = 0; int mAvgCount = 1; boolean mPastVideo = false; int[] mOrder = new int[mEffectCount]; /* here we have several thing to do, * 1.Do not let vedeo play after another video * 2.First one not video */ // remove the fake info Log.e(TAG, "mMediaInfo.size():" + mMediaInfo.size()); for (int i = 0; i < mMediaInfo.size(); i++) { mFileBucket.add(i); mRandomBucket.add(i); } int[] ElementCount = new int[mMediaInfo.size()]; for (int i = 0; i < ElementCount.length; i++) ElementCount[i] = 0; mRunCount = mEffectCount - mNoItemCount - mNoCountSize; // if file count can't fill into head and tile we random it if (!IsShuffle) { if (mFileTotalCount < mRunCount / 2) { IsShuffle = true; } else { mStartCount = (int) Math.floor(mRunCount / 6); mEndCount = (int) Math.floor(mRunCount / 6); mCenterCount = (int) Math.floor(mRunCount / 6); mFHalfCount = (int) Math.floor((mRunCount - mStartCount - mEndCount - mCenterCount) / 2); mLHalfCount = mRunCount - mCenterCount - mFHalfCount - mStartCount - mEndCount; int sortcount = mStartCount + mEndCount + mCenterCount; int recount = mFileBucket.size() - sortcount; for (int i = 0; i < (int) Math.floor(recount / 2); i++) { mFileBucket.remove(mStartCount); recount--; } for (int i = 0; i < recount; i++) { mFileBucket.remove(mStartCount + mCenterCount); } } } mAvgCount = (int) (Math.ceil((float) (mEffectCount - mNoItemCount - mNoCountSize) / mFileTotalCount)) - 1; Log.e( TAG, "mFileTotalCount:" + mFileTotalCount + ", mStartCount:" + mStartCount + ", mFHalfCount:" + mFHalfCount + ", mCenterCount:" + mCenterCount + ", mLHalfCount:" + mLHalfCount + ", mEndCount:" + mEndCount + ", mRunCount:" + mRunCount + ", IsShuffle:" + IsShuffle); // now we need start to put order // Default order is sort by date for (int i = 0; i < mEffectCount; i++) { ElementInfo eInfo = new ElementInfo(); MediaInfo info = null; if (mScript.CheckNoItem(i)) { eInfo.Type = MediaInfo.MEDIA_TYPE_IMAGE; eInfo.height = processGL.ScreenHeight; eInfo.width = processGL.ScreenWidth; mOrder[i] = -1; } else if (!mScript.CheckInCount(i)) { // Random and push in... info = mMediaInfo.get(mRandom.nextInt(mMediaInfo.size())); eInfo.Type = MediaInfo.MEDIA_TYPE_IMAGE; eInfo.height = info.getImage().getHeight(); eInfo.width = info.getImage().getWidth(); eInfo.mFaceCount = info.mFaceCount; eInfo.mFBorder = info.mFBorder; eInfo.InfoId = info.CountId; eInfo.mDate = info.getDate(); eInfo.mFaceRect = info.mFaceRect; mOrder[i] = info.CountId; } else { if (!IsShuffle) { if (mOrderList[mScriptId] == null) { if (mFileTotalCount >= mEffectCount) { info = mMediaInfo.get(i); } else { if (mFileBucket.size() > 0 && (mStartCount > 0 || (mFHalfCount == 0 && mCenterCount > 0) || (mLHalfCount == 0 && mEndCount > 0))) { info = mMediaInfo.get(mFileBucket.get(0)); mFileBucket.remove(0); if (mStartCount > 0) mStartCount--; else if (mFHalfCount == 0 && mCenterCount > 0) mCenterCount--; else if (mLHalfCount == 0 && mEndCount > 0) mEndCount--; } else { mSpaceBucket.clear(); int count = 0; for (int j = i - 1; j >= 0; j--) { if (count == mRange) break; if (mFileOrder.get(j).InfoId != -1) { mSpaceBucket.add(mFileOrder.get(j).InfoId); count++; } } int mPos = 0; if (mFHalfCount > 0) { if (mFHalfCount - 1 < mRange) { mPos = mRange - (mFHalfCount - 1); } if (mCenterCount < mPos) { mPos = mCenterCount; } } else { if (mLHalfCount - 1 < mRange) { mPos = mRange - (mLHalfCount - 1); } if (mEndCount < mPos) { mPos = mEndCount; } } for (int j = 0; j < mPos; j++) { mSpaceBucket.add(mMediaInfo.get(mFileBucket.get(j)).CountId); } int tmp; do { tmp = mRandom.nextInt(mRandomBucket.size()); info = mMediaInfo.get(mRandomBucket.get(tmp)); } while (mSpaceBucket.contains(info.CountId) && mFileTotalCount > mSpacing); if (ElementCount[info.CountId] >= mAvgCount) { mRandomBucket.remove(tmp); } if (mFHalfCount > 0) mFHalfCount--; else if (mLHalfCount > 0) mLHalfCount--; } } } else { info = mMediaInfo.get(mOrderList[mScriptId][i]); eInfo.centerX = mCenterX[mScriptId][i]; eInfo.centerY = mCenterY[mScriptId][i]; eInfo.mIsRestore = true; } } else { if (mSpaceBucket.size() > mSpacing) { mSpaceBucket.remove(0); } int tmp; do { tmp = mRandom.nextInt(mRandomBucket.size()); info = mMediaInfo.get(mRandomBucket.get(tmp)); } while (mSpaceBucket.contains(info.CountId) && mFileTotalCount > mSpacing); if (ElementCount[info.CountId] >= mAvgCount) { mRandomBucket.remove(tmp); } mSpaceBucket.add(info.CountId); } if (info.getType() == MediaInfo.MEDIA_TYPE_IMAGE) { eInfo.Type = MediaInfo.MEDIA_TYPE_IMAGE; eInfo.height = info.getImage().getHeight(); eInfo.width = info.getImage().getWidth(); eInfo.mFaceCount = info.mFaceCount; eInfo.mFBorder = info.mFBorder; eInfo.InfoId = info.CountId; eInfo.mDate = info.getDate(); eInfo.mFaceRect = info.mFaceRect; if (info.mGeoInfo != null) eInfo.mLocation = info.mGeoInfo.getLocation(); mPastVideo = false; } ElementCount[info.CountId]++; mOrder[i] = info.CountId; info = null; } mFileOrder.add(eInfo); } // for(int i=0; i<ElementCount.length; i++) Log.e(TAG, "i:" + i + ": " + ElementCount[i]); mOrderList[mScriptId] = mOrder; return mFileOrder; }