本文整理汇总了Java中android.media.MediaMetadataRetriever类的典型用法代码示例。如果您正苦于以下问题:Java MediaMetadataRetriever类的具体用法?Java MediaMetadataRetriever怎么用?Java MediaMetadataRetriever使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MediaMetadataRetriever类属于android.media包,在下文中一共展示了MediaMetadataRetriever类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createBitmaps
import android.media.MediaMetadataRetriever; //导入依赖的package包/类
public List<Bitmap> createBitmaps(String path)
{
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
mmr.setDataSource(path);
double inc = US_OF_S / fps;
for (double i = begin * US_OF_S; i < end * US_OF_S; i += inc)
{
Bitmap frame = mmr.getFrameAtTime((long) i, MediaMetadataRetriever.OPTION_CLOSEST);
if (frame != null)
{
bitmaps.add(scale(frame));
}
}
return bitmaps;
}
示例2: 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);
}
示例3: getAlbumArtFromMP3File
import android.media.MediaMetadataRetriever; //导入依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.GINGERBREAD_MR1)
public static Bitmap getAlbumArtFromMP3File(String path) {
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
try {
mmr.setDataSource(path);
} catch (IllegalArgumentException e) {
e.printStackTrace();
return null;
}
byte[] bytes = mmr.getEmbeddedPicture();
if (null != bytes) {
return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
} else {
return mmr.getFrameAtTime();
}
}
示例4: onClientMetadataUpdate
import android.media.MediaMetadataRetriever; //导入依赖的package包/类
@Override
public void onClientMetadataUpdate(RemoteController.MetadataEditor data) {
mMetadata.trackTitle = data.getString(MediaMetadataRetriever.METADATA_KEY_TITLE,
mMetadata.trackTitle);
mMetadata.bitmap = data.getBitmap(MediaMetadataEditor.BITMAP_KEY_ARTWORK,
mMetadata.bitmap);
mClientIdLost = false;
if ((mMetadata.trackTitle != null
&& !mMetadata.trackTitle.equals(mCurrentTrack))
|| (mMetadata.bitmap != null && !mMetadata.bitmap.sameAs(mCurrentBitmap))) {
mCurrentTrack = mMetadata.trackTitle;
mCurrentBitmap = mMetadata.bitmap;
refreshState();
if (DEBUG) log(getKey() + ": onClientMetadataUpdate");
}
}
示例5: 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();
}
}
}
}
示例6: 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;
}
示例7: formatFileDuration
import android.media.MediaMetadataRetriever; //导入依赖的package包/类
private String formatFileDuration(String path) {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(path);
// 取得视频的长度(单位为毫秒)
String time = retriever
.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
// 取得视频的长度(单位为秒)
int totalS = Integer.valueOf(time) / 1000;
DecimalFormat df = new DecimalFormat("#.00");
String totalDuration = "";
if (totalS < 60) {
totalDuration = df.format((double) totalS) + "秒";
} else if (totalS < 3600) {
totalDuration = df.format((double) totalS / 60) + "分";
} else if (totalS < 3600*24) {
totalDuration = df.format((double) totalS / 3600) + "时";
}
return totalDuration;
}
示例8: initThumbs
import android.media.MediaMetadataRetriever; //导入依赖的package包/类
/**
* 初始化缩略图
*/
private void initThumbs(){
final int frame = 15;
final int frameTime = videoDuration/frame*1000;
int thumbnailWidth = ll_thumbnail.getWidth()/frame;
for (int x=0; x<frame; x++){
ImageView imageView = new ImageView(this);
imageView.setLayoutParams(new ViewGroup.LayoutParams(thumbnailWidth, ViewGroup.LayoutParams.MATCH_PARENT));
imageView.setBackgroundColor(Color.parseColor("#666666"));
imageView.setScaleType(ImageView.ScaleType.CENTER);
ll_thumbnail.addView(imageView);
}
new AsyncTask<Void, Void, Boolean>() {
@Override
protected Boolean doInBackground(Void... params) {
MediaMetadataRetriever mediaMetadata= new MediaMetadataRetriever();
mediaMetadata.setDataSource(mContext, Uri.parse(path));
for (int x=0; x<frame; x++){
Bitmap bitmap = mediaMetadata.getFrameAtTime(frameTime*x, MediaMetadataRetriever.OPTION_CLOSEST_SYNC);
Message msg = myHandler.obtainMessage();
msg.obj = bitmap;
msg.arg1 = x;
myHandler.sendMessage(msg);
}
mediaMetadata.release();
return true;
}
@Override
protected void onPostExecute(Boolean result) {
}
}.execute();
}
示例9: generateVideoThumbnail
import android.media.MediaMetadataRetriever; //导入依赖的package包/类
private ThumbnailData generateVideoThumbnail(MasterSecret masterSecret, AttachmentId attachmentId) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
Log.w(TAG, "Video thumbnails not supported...");
return null;
}
File mediaFile = getAttachmentDataFile(attachmentId, DATA);
if (mediaFile == null) {
Log.w(TAG, "No data file found for video thumbnail...");
return null;
}
EncryptedMediaDataSource dataSource = new EncryptedMediaDataSource(masterSecret, mediaFile);
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(dataSource);
Bitmap bitmap = retriever.getFrameAtTime(1000);
Log.w(TAG, "Generated video thumbnail...");
return new ThumbnailData(bitmap);
}
示例10: setVideoFromAssets
import android.media.MediaMetadataRetriever; //导入依赖的package包/类
public void setVideoFromAssets(String assetsFileName) {
reset();
try {
AssetFileDescriptor assetFileDescriptor = getContext().getAssets().openFd(assetsFileName);
mediaPlayer.setDataSource(assetFileDescriptor.getFileDescriptor(), assetFileDescriptor.getStartOffset(), assetFileDescriptor.getLength());
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(assetFileDescriptor.getFileDescriptor(), assetFileDescriptor.getStartOffset(), assetFileDescriptor.getLength());
onDataSourceSet(retriever);
} catch (IOException e) {
Log.e(TAG, e.getMessage(), e);
}
}
示例11: 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());
}
}
示例12: 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;
}
}
示例13: getVideoInfor
import android.media.MediaMetadataRetriever; //导入依赖的package包/类
/** 获取视频时长 **/
public static void getVideoInfor(int index) {
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
VideoInfo vInfo = videosInfo.get(index);
mmr.setDataSource(vInfo.videoPath);
String videoTime = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); // 播放时长单位为毫秒
String width = mmr.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
String height = mmr.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
String rotation = mmr.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);
if (rotation.equals("90") || rotation.equals("270")) {
width = mmr.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
height = mmr.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
}
vInfo.rotation = Integer.parseInt(rotation);
vInfo.videoTime = Integer.parseInt(videoTime);
vInfo.totalVideoTime = Integer.parseInt(videoTime);
vInfo.endVideoTime = Integer.parseInt(videoTime);
vInfo.width = Integer.parseInt(width);
vInfo.height = Integer.parseInt(height);
}
示例14: albumdetailadapter
import android.media.MediaMetadataRetriever; //导入依赖的package包/类
public albumdetailadapter(Context context,ArrayList<Songs> songwithalbum) {
MediaMetadataRetriever data = new MediaMetadataRetriever();
songs = songwithalbum;
for(int i=0;i<songs.size() ;i++)
{
try {
song.add(songs.get(i).gettitle());
artist.add(songs.get(i).getartist());
}
catch (Exception e)
{
song.add("Unknown title");
artist.add("Unknown artist");
}
}
this.context = context;
}
示例15: 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;
}