本文整理汇总了Java中android.media.MediaMetadataRetriever.release方法的典型用法代码示例。如果您正苦于以下问题:Java MediaMetadataRetriever.release方法的具体用法?Java MediaMetadataRetriever.release怎么用?Java MediaMetadataRetriever.release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.MediaMetadataRetriever
的用法示例。
在下文中一共展示了MediaMetadataRetriever.release方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseMP3File
import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.GINGERBREAD_MR1)
public static MusicBean parseMP3File(String path) {
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
String name = null;
String singer = null;
String album = null;
long duration = 0;
try {
mmr.setDataSource(path);
name = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
singer = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
album = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
duration = Long.valueOf(mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
mmr.release();
} catch (Exception e) {
e.printStackTrace();
return null;
}
return new MusicBean(name, singer, album, duration, path);
}
示例2: getFileMeta
import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
/**
* 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();
}
}
}
}
示例3: getVideoDuration
import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
/**
* 从视频文件中读取视频长度
*/
public static long getVideoDuration(Context context, String videoFile) {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
//use one of overloaded setDataSource() functions to set your data source
String time;
try {
retriever.setDataSource(context, Uri.fromFile(new File(videoFile)));
time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
int width = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));
int height = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
} finally {
try {
retriever.release();
} catch (Exception ex) {
// Ignore failures while cleaning up.
}
}
long timeInMillisec = Long.parseLong(time);
return timeInMillisec;
}
示例4: MoviePlayer
import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
public MoviePlayer(File sourceFile, Surface outputSurface)
throws IOException {
// Pop the file open and pull out the video characteristics.
// TODO: consider leaving the extractor open. Should be able to just seek back to
// the start after each iteration of play. Need to rearrange the API a bit --
// currently play() is taking an all-in-one open+work+release approach.
try {
Log.d(TAG, sourceFile.toString());
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(sourceFile.toString());
mVideoDuration = Long.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
Log.d(TAG, "Duration: " + mVideoDuration);
retriever.release();
mVideoDecoder = new VideoDecoder(this, sourceFile);
mVideoDecoder.setOutputSurface(outputSurface);
mAudioDecoder = new AudioDecoder(this, sourceFile);
mVideoDecoder.prepare();
mAudioDecoder.prepare();
} catch (Exception ex) {
release();
throw new IOException(ex.getMessage());
}
}
示例5: getMusicThumb
import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
/**
* 获取音乐thumb
*
* @param filePath 文件路径
* @return 对应的缩略图
*/
public static Bitmap getMusicThumb(String filePath) {
Bitmap bitmap = null;
try {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(filePath);
byte[] art = retriever.getEmbeddedPicture();
if (art != null) {
bitmap = BitmapFactory.decodeByteArray(art, 0, art.length);
}
retriever.release();
return bitmap;
} catch (Exception e) {
if (bitmap != null && !bitmap.isRecycled()) {
bitmap.recycle();
}
System.gc();
return null;
} catch (OutOfMemoryError o) {
System.gc();
return null;
}
}
示例6: createAlbumArt
import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
/**
* get audio cover
* @param filePath
* @return
*/
public static Bitmap createAlbumArt(String filePath) {
Bitmap bitmap = null;
//能够获取多媒体文件元数据的类
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
retriever.setDataSource(filePath); //设置数据源
byte[] bytes = retriever.getEmbeddedPicture(); //得到字节型数据
if(bytes!=null){
bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); //转换为图片
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
retriever.release();
} catch (Exception e2) {
e2.printStackTrace();
}
}
return bitmap;
}
示例7: createAlbumArt
import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
/**
* @Description 获取专辑封面
* @return 专辑封面bitmap
*/
public static Bitmap createAlbumArt(String path) {
if (TextUtils.isEmpty(path)) {
return null;
}
Bitmap bitmap = null;
//能够获取多媒体文件元数据的类
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
retriever.setDataSource(path); //设置数据源
byte[] embedPic = retriever.getEmbeddedPicture(); //得到字节型数据
if (embedPic != null) {
bitmap = BitmapFactory.decodeByteArray(embedPic, 0, embedPic.length); //转换为图片
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
retriever.release();
} catch (Exception e2) {
e2.printStackTrace();
}
}
Log.d("zbj1101", "createAlbumArt:bitmap: " + bitmap + ",music: "+path);
return bitmap;
}
示例8: needToCrop
import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
public static boolean needToCrop(String originMediaPath) {
MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
mediaMetadataRetriever.setDataSource(originMediaPath);
int videoWidth =
Integer.parseInt(mediaMetadataRetriever
.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
int videoHeight =
Integer.parseInt(mediaMetadataRetriever
.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));
int rotation = getRotation(mediaMetadataRetriever);
mediaMetadataRetriever.release();
if (rotation == 0 || rotation == 180) {
return videoHeight != videoWidth * 3 / 4;
} else if (rotation == 90 || rotation == 270) {
return videoWidth != videoHeight * 3 / 4;
}
return true;
}
示例9: getVideoCover
import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
public static String getVideoCover(String videoPath, String coverName) {
coverName = TextUtils.isEmpty(coverName) ? COVER_NAME : coverName;
String parentPath = new File(videoPath).getParent();
String coverPath = parentPath.endsWith(File.separator) ? parentPath
+ coverName : parentPath + File.separator + coverName;
if (new File(coverPath).isFile()) {
return coverPath;
}
MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
mediaMetadataRetriever.setDataSource(videoPath);
Bitmap bitmap = mediaMetadataRetriever.getFrameAtTime(1);
mediaMetadataRetriever.release();
if (bitmap != null) {
return FileUtils.saveBitmapToFile(bitmap, new File(videoPath).getParent(), coverName,
FILTER_COVER_NAME.equals(coverName) ? 10 : 100);
}
return "";
}
示例10: loadData
import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
@Override
public InputStream loadData(Priority priority) throws Exception {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
Log.d("VideoThumbnailFetcher", "model.path= " + model.path);
retriever.setDataSource(model.path, new HashMap<String, String>());
Bitmap bitmap = retriever.getFrameAtTime();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] picture = stream.toByteArray();
if (picture != null) {
return new ByteArrayInputStream(picture);
} else {
return fallback(model.path);
}
} finally {
retriever.release();
}
}
示例11: checkIsHaveMetaData
import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
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;
}
}
示例12: verifyLocationInFile
import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
private void verifyLocationInFile(String fileName) {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(fileName);
String location = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_LOCATION);
assertNotNull("No location information found in file " + fileName, location);
// parsing String location and recover the location inforamtion in floats
// Make sure the tolerance is very small - due to rounding errors.
// Get the position of the -/+ sign in location String, which indicates
// the beginning of the longtitude.
int index = location.lastIndexOf('-');
if (index == -1) {
index = location.lastIndexOf('+');
}
assertTrue("+ or - is not found", index != -1);
assertTrue("+ or - is only found at the beginning", index != 0);
float latitude = Float.parseFloat(location.substring(0, index - 1));
float longitude = Float.parseFloat(location.substring(index));
assertTrue("Incorrect latitude: " + latitude,
Math.abs(latitude - LATITUDE) <= TOLERANCE);
assertTrue("Incorrect longitude: " + longitude,
Math.abs(longitude - LONGITUDE) <= TOLERANCE);
retriever.release();
}
示例13: loadVideoThumbnail
import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
/**
* Loads the thumbnail of a video.
*
* @param path The path to the video file.
* @return {@code null} if the loading failed.
*/
public static Bitmap loadVideoThumbnail(String path) {
Bitmap bitmap = null;
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
retriever.setDataSource(path);
byte[] data = retriever.getEmbeddedPicture();
if (data != null) {
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
}
if (bitmap == null) {
bitmap = retriever.getFrameAtTime();
}
} catch (IllegalArgumentException e) {
Log.e(TAG, "MediaMetadataRetriever.setDataSource() fail:" + e.getMessage());
}
retriever.release();
return bitmap;
}
示例14: doInBackground
import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
@Override
protected Bitmap doInBackground(Void... v) {
if (isCancelled() || !isUsing()) {
return null;
}
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
Bitmap bitmap = null;
try {
retriever.setDataSource(mPath);
byte[] data = retriever.getEmbeddedPicture();
if (!isCancelled() && isUsing()) {
if (data != null) {
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
}
if (bitmap == null) {
bitmap = retriever.getFrameAtTime();
}
}
} catch (IllegalArgumentException e) {
Log.e(TAG, "MediaMetadataRetriever.setDataSource() fail:"
+ e.getMessage());
}
retriever.release();
return bitmap;
}
示例15: getRotation
import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
public int getRotation()
{
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
if (this.path != null)
retriever.setDataSource(this.path);
else if (this.fileDescriptor != null)
retriever.setDataSource(this.fileDescriptor);
else if (this.uri != null)
retriever.setDataSource(this.context, android.net.Uri.parse(this.uri.getString()));
else {
throw new IllegalStateException("File not set");
}
String rotation = retriever.extractMetadata(24);
retriever.release();
return Integer.parseInt(rotation);
}