Java Code Examples for android.media.MediaMetadataRetriever#release()
The following examples show how to use
android.media.MediaMetadataRetriever#release() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MediaPlayerService.java From io2014-codelabs with Apache License 2.0 | 6 votes |
public PlaylistEntry (int resourceId) { MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever(); AssetFileDescriptor song = getResources().openRawResourceFd(resourceId); metadataRetriever.setDataSource(song.getFileDescriptor(), song.getStartOffset(), song.getDeclaredLength()); this.resourceId = resourceId; artist = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST); title = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE); if (artist == null) { artist = "unknown artist"; } if (title == null) { title = "unknown title"; } metadataRetriever.release(); }
Example 2
Source File: Synchronizer.java From AudioAnchor with GNU General Public License v3.0 | 6 votes |
private boolean insertAudioFile(String title, String albumDirName, long albumId) { ContentValues values = new ContentValues(); values.put(AnchorContract.AudioEntry.COLUMN_TITLE, title); values.put(AnchorContract.AudioEntry.COLUMN_ALBUM, albumId); // Retrieve audio duration from Metadata. MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever(); try { String audioFilePath = mDirectory + File.separator + albumDirName + File.separator + title; metaRetriever.setDataSource(audioFilePath); String duration = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); values.put(AnchorContract.AudioEntry.COLUMN_TIME, Long.parseLong(duration)); metaRetriever.release(); // Insert the row into the database table mContext.getContentResolver().insert(AnchorContract.AudioEntry.CONTENT_URI, values); } catch (java.lang.RuntimeException e) { return false; } return true; }
Example 3
Source File: UploadVideoActivity.java From patrol-android with GNU General Public License v3.0 | 6 votes |
private boolean checkIsHaveMetaData(Uri fileUri) { try { MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever(); metadataRetriever.setDataSource(this, fileUri); contentData = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DATE); contentLocation = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_LOCATION); metadataRetriever.release(); parsMetaLocation(); SimpleDateFormat metaDateFormat = new SimpleDateFormat(Constants.VIDEO_META_DATE_MASK); violationDate = metaDateFormat.parse(contentData); return true; } catch (Exception e) { e.printStackTrace(); contentNotReady(); return false; } }
Example 4
Source File: FileCreator.java From Saiy-PS with GNU Affero General Public License v3.0 | 6 votes |
/** * Used to get information about the written file */ private void getFileMeta() { if (absolutePath != null) { try { final MediaMetadataRetriever mmr = new MediaMetadataRetriever(); mmr.setDataSource(absolutePath); final String duration = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); mmr.release(); if (DEBUG) { MyLog.i(CLS_NAME, "recording duration: " + duration); } } catch (final RuntimeException e) { if (DEBUG) { MyLog.w(CLS_NAME, "RuntimeException: completeFileWrite"); e.printStackTrace(); } } } }
Example 5
Source File: FillModeCustomActivity.java From Mp4Composer-android with MIT License | 6 votes |
public Size getVideoResolution(String path) { MediaMetadataRetriever retriever = new MediaMetadataRetriever(); retriever.setDataSource(path); int width = Integer.valueOf( retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH) ); int height = Integer.valueOf( retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT) ); retriever.release(); int rotation = getVideoRotation(path); if (rotation == 90 || rotation == 270) { return new Size(height, width); } return new Size(width, height); }
Example 6
Source File: Util.java From audioview with Boost Software License 1.0 | 6 votes |
public static String getTrackTitle(Context context, Object source) { MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever(); try { if (source instanceof String) metaRetriever.setDataSource((String) source); if (source instanceof Uri) metaRetriever.setDataSource(context, (Uri) source); if (source instanceof FileDescriptor) metaRetriever.setDataSource((FileDescriptor) source); } catch (IllegalArgumentException ignored) { } String artist = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST); String title = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE); metaRetriever.release(); if (artist != null && !TextUtils.isEmpty(artist) && title != null && !TextUtils.isEmpty(title)) return artist + " - " + title; if ((artist == null || TextUtils.isEmpty(artist)) && title != null && !TextUtils.isEmpty(title)) return title; if (artist == null || TextUtils.isEmpty(artist)) return context.getString(R.string.no_title); return artist; }
Example 7
Source File: MicroPlayer.java From J2ME-Loader with Apache License 2.0 | 6 votes |
@Override public synchronized void prefetch() throws MediaException { checkClosed(); if (state == UNREALIZED) { realize(); } if (state == REALIZED) { try { MediaMetadataRetriever retriever = new MediaMetadataRetriever(); retriever.setDataSource(source.getLocator()); metadata.updateMetaData(retriever); retriever.release(); } catch (Exception e) { e.printStackTrace(); } state = PREFETCHED; } }
Example 8
Source File: AudioFileCoverFetcher.java From MusicPlayer with GNU General Public License v3.0 | 6 votes |
@Override public void loadData(@NonNull Priority priority, @NonNull DataCallback<? super InputStream> callback) { MediaMetadataRetriever retriever = new MediaMetadataRetriever(); try { retriever.setDataSource(model.filePath); byte[] picture = retriever.getEmbeddedPicture(); if (picture != null) { callback.onDataReady(new ByteArrayInputStream(picture)); } else { try { callback.onDataReady(fallback(model.filePath)); } catch (FileNotFoundException e) { callback.onLoadFailed(e); } } } finally { retriever.release(); } }
Example 9
Source File: FrameCacheManager.java From DMusic with Apache License 2.0 | 5 votes |
@RequiresApi(api = Build.VERSION_CODES.GINGERBREAD_MR1) @Override protected void absLoad(Context context, String url, CacheListener<FrameBean> listener) { // Also can use ThumbnailUtils.createVideoThumbnail(url, MediaStore.Images.Thumbnails.MINI_KIND); MediaMetadataRetriever mmr = new MediaMetadataRetriever(); try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && url.contains("://")) { HashMap<String, String> headers = new HashMap<String, String>(); headers.put("User-Agent", "Mozilla/5.0 (Linux; U; Android 4.4.2; zh-CN;" + " MW-KW-001 Build/JRO03C) AppleWebKit/533.1 (KHTML, like Gecko) " + "Version/4.0 UCBrowser/1.0.0.001 U4/0.8.0 Mobile Safari/533.1"); mmr.setDataSource(url, headers); } else { mmr.setDataSource(context, Uri.parse(url)); } // Get the first frame picture Bitmap bitmap = mmr.getFrameAtTime(); // Get duration(milliseconds) long duration = Long.parseLong(mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)); FrameBean frameBean = new FrameBean(); frameBean.drawable = Util.bitmapToDrawableByBD(bitmap); frameBean.duration = duration; // Save to disk putDisk(url, frameBean); success(url, frameBean, listener); } catch (Throwable e) { Log.e("Cache", e.toString()); e.printStackTrace(); error(url, e, listener); } finally { if (mmr != null) { mmr.release(); } } }
Example 10
Source File: VideoBuilder.java From EZFilter with MIT License | 5 votes |
@Override public float getAspectRatio(IFitView view) { MediaMetadataRetriever metadata = new MediaMetadataRetriever(); try { String scheme = mVideo.getScheme(); if (scheme != null && (scheme.equals("http") || scheme.equals("https"))) { // 在线视频 metadata.setDataSource(mVideo.toString(), new HashMap<>()); } else { // 本地视频(SD卡或Assets目录) metadata.setDataSource(view.getContext(), mVideo); } String width = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH); String height = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT); String rotation = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION); if ((NumberUtil.parseInt(rotation) / 90) % 2 != 0) { return NumberUtil.parseInt(height) * 1.0f / NumberUtil.parseInt(width); } else { return NumberUtil.parseInt(width) * 1.0f / NumberUtil.parseInt(height); } } catch (Exception e) { e.printStackTrace(); return 1; } finally { metadata.release(); } }
Example 11
Source File: MediaUtil.java From EZFilter with MIT License | 5 votes |
/** * 解析多媒体文件元数据 * * @param input * @return */ public static Metadata getMetadata(String input) { MediaMetadataRetriever retriever = new MediaMetadataRetriever(); try { retriever.setDataSource(input); String duration = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); String width = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH); String height = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT); String bitrate = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE); String mimeType = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_MIMETYPE); String rotation = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION); String tracks = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_NUM_TRACKS); Metadata metadata = new Metadata(); metadata.duration = NumberUtil.parseLong(duration); metadata.width = NumberUtil.parseInt(width); metadata.height = NumberUtil.parseInt(height); metadata.bitrate = NumberUtil.parseInt(bitrate, 1); metadata.rotation = NumberUtil.parseInt(rotation); metadata.tracks = NumberUtil.parseInt(tracks); metadata.mimeType = mimeType; return metadata; } catch (RuntimeException e) { e.printStackTrace(); } finally { retriever.release(); } return new Metadata(); }
Example 12
Source File: AudioFileCoverFetcher.java From Orin with GNU General Public License v3.0 | 5 votes |
@Override public InputStream loadData(Priority priority) throws Exception { MediaMetadataRetriever retriever = new MediaMetadataRetriever(); try { retriever.setDataSource(model.filePath); byte[] picture = retriever.getEmbeddedPicture(); if (picture != null) { return new ByteArrayInputStream(picture); } else { return fallback(model.filePath); } } finally { retriever.release(); } }
Example 13
Source File: FileBackend.java From Conversations with GNU General Public License v3.0 | 5 votes |
private Bitmap getVideoPreview(final File file, final int size) { final MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever(); Bitmap frame; try { metadataRetriever.setDataSource(file.getAbsolutePath()); frame = metadataRetriever.getFrameAtTime(0); metadataRetriever.release(); frame = resize(frame, size); } catch (IOException | RuntimeException e) { frame = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); frame.eraseColor(0xff000000); } drawOverlay(frame, paintOverlayBlack(frame) ? R.drawable.play_video_black : R.drawable.play_video_white, 0.75f); return frame; }
Example 14
Source File: MediaUtil.java From deltachat-android with GNU General Public License v3.0 | 5 votes |
public static boolean createVideoThumbnailIfNeeded(Context context, Uri dataUri, Uri thumbnailUri, ThumbnailSize retWh) { boolean success = false; try { File thumbnailFile = new File(thumbnailUri.getPath()); File dataFile = new File(dataUri.getPath()); if (!thumbnailFile.exists() || dataFile.lastModified()>thumbnailFile.lastModified()) { Bitmap bitmap = null; MediaMetadataRetriever retriever = new MediaMetadataRetriever(); retriever.setDataSource(context, dataUri); bitmap = retriever.getFrameAtTime(-1); if (retWh!=null) { retWh.width = bitmap.getWidth(); retWh.height = bitmap.getHeight(); } retriever.release(); if (bitmap != null) { FileOutputStream out = new FileOutputStream(thumbnailFile); bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); success = true; } } } catch (Exception e) { e.printStackTrace(); } return success; }
Example 15
Source File: VideoFilterAddAction.java From SimpleVideoEditor with Apache License 2.0 | 5 votes |
private boolean checkRational() { if (mInputFile != null && mInputFile.exists() && mInputFile.isFile() && mOutputFile != null && mFromMs >= 0 && mDurationMs >= 0) { MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever(); mediaMetadataRetriever.setDataSource(mInputFile.getAbsolutePath()); long duration = Long.valueOf(mediaMetadataRetriever. extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)); mediaMetadataRetriever.release(); if (mFromMs + mDurationMs > duration) { Logger.e(TAG, "Video selected section of out of duration!"); return false; } if (mOutputFile.exists()) { Logger.w(TAG, "WARNING: Output file: " + mOutputFile + " already exists, we will override it!"); } return true; } return false; }
Example 16
Source File: MediaController.java From Telegram with GNU General Public License v2.0 | 5 votes |
public static int getVideoBitrate(String path) { MediaMetadataRetriever retriever = new MediaMetadataRetriever(); int bitrate = 0; try { retriever.setDataSource(path); bitrate = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE)); } catch (Exception e) { FileLog.e(e); } retriever.release(); return bitrate; }
Example 17
Source File: GLWallpaperService.java From alynx-live-wallpaper with Apache License 2.0 | 5 votes |
private void getVideoMetadata() throws IOException { final MediaMetadataRetriever mmr = new MediaMetadataRetriever(); switch (wallpaperCard.getType()) { case INTERNAL: final AssetFileDescriptor afd = getAssets().openFd(wallpaperCard.getPath()); mmr.setDataSource( afd.getFileDescriptor(), afd.getStartOffset(), afd.getDeclaredLength() ); afd.close(); break; case EXTERNAL: mmr.setDataSource(context, wallpaperCard.getUri()); break; } final String rotation = mmr.extractMetadata( MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION ); final String width = mmr.extractMetadata( MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH ); final String height = mmr.extractMetadata( MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT ); mmr.release(); videoRotation = Integer.parseInt(rotation); videoWidth = Integer.parseInt(width); videoHeight = Integer.parseInt(height); }
Example 18
Source File: MainActivity.java From android-video-transcoder with The Unlicense | 4 votes |
private void doConvert(String fromFile, String toFile){ final ProgressDialog progress=new ProgressDialog(this); progress.setTitle("Compressing video"); progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progress.setCancelable(false); progress.setButton(ProgressDialog.BUTTON_POSITIVE, "Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { videoConverter.cancel(); progress.dismiss(); } }); progress.show(); VideoConverter.Callback callback=new VideoConverter.Callback() { @Override public void onProgressUpdated(final int done, final int total) { runOnUiThread(new Runnable() { @Override public void run() { progress.setMax(total); progress.setProgress(done); } }); } @Override public void onConversionCompleted() { runOnUiThread(new Runnable() { @Override public void run() { progress.dismiss(); videoConverter=null; Toast.makeText(MainActivity.this, "Done!", Toast.LENGTH_SHORT).show(); } }); } @Override public void onConversionFailed(final String error) { runOnUiThread(new Runnable() { @Override public void run() { progress.dismiss(); new AlertDialog.Builder(MainActivity.this) .setTitle("Error") .setMessage(error) .setPositiveButton("OK", null) .show(); } }); } @Override public void onReady() { videoConverter.start(); } }; int scalingFactor=scalingFactorSlider.getProgress()+1; MediaMetadataRetriever mmr=new MediaMetadataRetriever(); mmr.setDataSource(this, Uri.parse(fromFile)); int vw=Integer.parseInt(mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)); int vh=Integer.parseInt(mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)); mmr.release(); videoConverter=new VideoConverter(fromFile, toFile, videoBitrateSlider.getProgress(), audioBitrateSlider.getProgress(), Math.max(vw, vh)/scalingFactor, callback, this); }
Example 19
Source File: InfoUtils.java From Gallery-example with GNU General Public License v3.0 | 4 votes |
static String fileResolution(String url, int which) { String[] VIDEO_EXTENSIONS = {"mp4", "avi", "mpg", "mkv", "webm", "flv", "wmv", "mov", "qt", "m4p", "m4v", "mpeg", "mp2", "m2v", "3gp", "3g2", "f4v", "f4p", "f4a", "f4b"}; String resolution = ""; if (stringContainsItemFromList(url, VIDEO_EXTENSIONS)) { MediaMetadataRetriever retriever = new MediaMetadataRetriever(); retriever.setDataSource(url); int videoWidth = Integer.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)); int videoHeight = Integer.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)); switch (which) { case 0: resolution = String.valueOf(videoWidth); break; case 1: resolution = String.valueOf(videoHeight); break; } retriever.release(); } else { Uri uri = Uri.parse(url); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(new File(uri.getPath()).getAbsolutePath(), options); int imageHeight = options.outHeight; int imageWidth = options.outWidth; switch (which) { case 0: resolution = String.valueOf(imageWidth); break; case 1: resolution = String.valueOf(imageHeight); break; } } return resolution; }
Example 20
Source File: StartMenuActivity.java From VIA-AI with MIT License | 4 votes |
private Bundle checkVideoInformation(VIACamera.MODE cameraMode, String framePath, boolean notShowInfo) { Bundle bundle = new Bundle(); Resources resources = getResources(); switch(cameraMode) { case Camera: case Camera2: case Native: bundle.putSerializable(resources.getString(R.string.key_camera_permutation), CameraPermutation.Camera1_In_Frame); bundle.putInt(resources.getString(R.string.key_frame_width), -1); bundle.putInt(resources.getString(R.string.key_frame_height), -1); break; case FakeCameraGPU: { MediaMetadataRetriever retriever = new MediaMetadataRetriever(); CameraPermutation permutation = Preferences.getInstance().getFrameSourceData().getCameraPermutation(); int prefFrameWidth = Preferences.getInstance().getFrameSourceData().getCameraSourceWidth(); int prefFrameHeight = Preferences.getInstance().getFrameSourceData().getCameraSourceHeight(); try { retriever.setDataSource(framePath); int width = Integer.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)); int height = Integer.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)); boolean isValid = false; switch(permutation) { case Camera1_In_Frame: isValid = true; break; case Camera2_In_Frame_1x2: if ((width == 2048 && height == 576) || (width == 2560 && height == 720)) { isValid = true; } break; case Camera3_In_Frame_1x3: if ((width == 3072 && height == 576) || (width == 3840 && height == 720)) { isValid = true; } break; case Camera4_In_Frame_2x2: if ((width == 2048 && height == 1152) || (width == 2560 && height == 1440)) { isValid = true; } break; case Camera4_In_Frame_1x4: if ((width == 5120 && height == 720) || (width == 4096 && height == 576)) { isValid = true; } break; } if(isValid) { bundle.putSerializable(resources.getString(R.string.key_camera_permutation), permutation); bundle.putInt(resources.getString(R.string.key_frame_width), width); bundle.putInt(resources.getString(R.string.key_frame_height), height); } else { bundle = null; if(!notShowInfo) { final String html_space4 = " "; Spanned dialogText; String str = "<b>Unsupported camera permutation in this video. </b><br>" + html_space4 + "Video Resolution [ " + width + "x" + height + " ]<br>" + "<br>" + html_space4 + "Setting Required Permutation : <br> [ " + permutation.toString() + " ]"; dialogText = Html.fromHtml(str); AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(mContext, R.style.AlertDialogStyle_Error); dialogBuilder.setTitle("Error"); dialogBuilder.setMessage(dialogText); dialogBuilder.setPositiveButton("OK", null); AlertDialog alertDialog = dialogBuilder.create(); alertDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE); alertDialog.show(); Helper helper = new Helper(); helper.setupAutoHideSystemUI(alertDialog.getWindow()); } } retriever.release(); } catch (IllegalArgumentException e) { Log.e("checkCameraPermutation", "IllegalArgumentException " + e.getMessage()); } } break; } return bundle; }