当前位置: 首页>>代码示例>>Java>>正文


Java MediaMetadataRetriever类代码示例

本文整理汇总了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;
   }
 
开发者ID:stytooldex,项目名称:stynico,代码行数:18,代码来源:BitmapExtractor.java

示例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);
}
 
开发者ID:piyell,项目名称:NeteaseCloudMusic,代码行数:24,代码来源:MP3Util.java

示例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();
    }
}
 
开发者ID:piyell,项目名称:NeteaseCloudMusic,代码行数:17,代码来源:MP3Util.java

示例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");
    }
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:17,代码来源:MusicTile.java

示例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();
            }
        }
    }
}
 
开发者ID:brandall76,项目名称:Saiy-PS,代码行数:27,代码来源:FileCreator.java

示例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;
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:25,代码来源:ImageGridActivity.java

示例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;
}
 
开发者ID:dxjia,项目名称:GifAssistant,代码行数:22,代码来源:VideosInfo.java

示例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();
}
 
开发者ID:Zhaoss,项目名称:WeiXinRecordedDemo,代码行数:38,代码来源:CutTimeActivity.java

示例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);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:23,代码来源:AttachmentDatabase.java

示例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);
    }
}
 
开发者ID:pavelsemak,项目名称:alpha-movie,代码行数:17,代码来源:AlphaMovieView.java

示例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());
    }
}
 
开发者ID:Tai-Kimura,项目名称:VideoApplication,代码行数:25,代码来源:MoviePlayer.java

示例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;
    }
}
 
开发者ID:WeiMei-Tian,项目名称:editor-sql,代码行数:32,代码来源:FeThumbUtils.java

示例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);
}
 
开发者ID:smartbeng,项目名称:PaoMovie,代码行数:24,代码来源:StaticMethod.java

示例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;

}
 
开发者ID:mdnafiskhan,项目名称:Mp3Player,代码行数:20,代码来源:albumdetailadapter.java

示例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;
}
 
开发者ID:jiajunhui,项目名称:XDisplay,代码行数:27,代码来源:AudioCoverUtil.java


注:本文中的android.media.MediaMetadataRetriever类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。