本文整理汇总了Java中android.media.MediaMetadataRetriever.getEmbeddedPicture方法的典型用法代码示例。如果您正苦于以下问题:Java MediaMetadataRetriever.getEmbeddedPicture方法的具体用法?Java MediaMetadataRetriever.getEmbeddedPicture怎么用?Java MediaMetadataRetriever.getEmbeddedPicture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.MediaMetadataRetriever
的用法示例。
在下文中一共展示了MediaMetadataRetriever.getEmbeddedPicture方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: 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;
}
}
示例3: 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;
}
示例4: 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;
}
示例5: extractAndSetCoverArt
import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
/**
* tries to read the cover art from the audio file and sets it as cover art.
*
* @param file audio file with potential cover art
*/
private void extractAndSetCoverArt(OCFile file) {
if (file.isAudio()) {
try {
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
mmr.setDataSource(file.getStoragePath());
byte[] data = mmr.getEmbeddedPicture();
if (data != null) {
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
mImagePreview.setImageBitmap(bitmap); //associated cover art in bitmap
} else {
mImagePreview.setImageResource(R.drawable.logo);
}
} catch (Throwable t) {
mImagePreview.setImageResource(R.drawable.logo);
}
}
}
示例6: 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;
}
示例7: 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;
}
示例8: openImageInputStream
import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
@Override
public InputStream openImageInputStream() {
if (playable.localFileAvailable()
&& playable.getLocalMediaUrl() != null) {
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
try {
mmr.setDataSource(playable.getLocalMediaUrl());
} catch (IllegalArgumentException e) {
e.printStackTrace();
return null;
}
byte[] imgData = mmr.getEmbeddedPicture();
if (imgData != null) {
return new PublicByteArrayInputStream(imgData);
}
}
return null;
}
示例9: loadData
import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
@Override public InputStream loadData(Priority priority) throws Exception {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
retriever.setDataSource(model.path);
byte[] picture = retriever.getEmbeddedPicture();
if (picture != null) {
return new ByteArrayInputStream(picture);
} else {
return fallback(model.path);
}
} finally {
retriever.release();
}
}
示例10: loadData
import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
@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();
}
}
示例11: doInBackground
import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
@Override
protected Void doInBackground(Void... params) {
Uri u= give.get(p).getSonguri();
MediaMetadataRetriever m= new MediaMetadataRetriever();
m.setDataSource(context,u);
byte[] a = m.getEmbeddedPicture();
if(a!=null)
bitmap = BitmapFactory.decodeByteArray(a,0,0);
return null;
}
示例12: parseAlbum
import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
public static Bitmap parseAlbum(File file) {
MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever();
try {
metadataRetriever.setDataSource(file.getAbsolutePath());
} catch (IllegalArgumentException e) {
Log.e(TAG, "parseAlbum: ", e);
}
byte[] albumData = metadataRetriever.getEmbeddedPicture();
if (albumData != null) {
return BitmapFactory.decodeByteArray(albumData, 0, albumData.length);
}
return null;
}
示例13: getView
import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
@Override
public View getView(int position, View view, ViewGroup viewGroup) {
View eltview = view;
if (view == null) {
eltview = inflater.inflate(R.layout.playlist_element,null);
ImageView thumbnail = (ImageView) eltview.findViewById(R.id.thumbnail);
TextView title = (TextView) eltview.findViewById(R.id.elementTitle);
TextView artist = (TextView) eltview.findViewById(R.id.elementArtist);
MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever();
metadataRetriever.setDataSource(mData.get(position).get("filepath"));
try {
byte[] bytearray = metadataRetriever.getEmbeddedPicture();
Bitmap albumArt = BitmapFactory.decodeByteArray(bytearray, 0, bytearray.length);
thumbnail.setImageBitmap(albumArt);
} catch (Exception e) {
thumbnail.setImageResource(R.drawable.play);
}
title.setText(mData.get(position).get("title"));
String artistString = "Artist : ";
if (mData.get(position).get("artist").isEmpty())
artistString += "Unknown";
else
artistString += mData.get(position).get("artist");
artist.setText(artistString);
}
return eltview;
}
示例14: doInBackground
import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
@Override
protected Bitmap doInBackground(VKApiAudio... params) {
mVkApiAudio = params[0];
String songUrl = mVkApiAudio.url;
mediaMetadataRetriever = new MediaMetadataRetriever();
Bitmap bitmap = null;
try{
if (Build.VERSION.SDK_INT >= 14){
mediaMetadataRetriever.setDataSource(songUrl,
new HashMap<String, String>());
}
else{
mediaMetadataRetriever.setDataSource(songUrl);
}
}catch (Exception e){
Log.e(LOG_TAG_GetCoverTask, "getCover() can't set data source: " + songUrl);
e.printStackTrace();
mediaMetadataRetriever.release();
return null;
}
byte[] artBytes = mediaMetadataRetriever.getEmbeddedPicture();
if(artBytes != null) {
InputStream is = new ByteArrayInputStream(mediaMetadataRetriever.getEmbeddedPicture());
bitmap = BitmapFactory.decodeStream(is);
}
mediaMetadataRetriever.release();
return bitmap;
}
示例15: showEmbeddedPicture
import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
@TargetApi( Build.VERSION_CODES.GINGERBREAD_MR1 )
private void showEmbeddedPicture( MediaMetadataRetriever metaData, int viewResourceID ) {
ImageView view = (ImageView) findViewById( viewResourceID );
if( view != null ) {
byte [] rawArtwork = metaData.getEmbeddedPicture();
if( rawArtwork != null ) {
Bitmap artwork = BitmapFactory.decodeByteArray( rawArtwork, 0, rawArtwork.length );
view.setImageBitmap( artwork );
}
}
}