本文整理匯總了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 );
}
}
}