當前位置: 首頁>>代碼示例>>Java>>正文


Java MediaMetadataRetriever.getEmbeddedPicture方法代碼示例

本文整理匯總了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();
    }
}
 
開發者ID:piyell,項目名稱:NeteaseCloudMusic,代碼行數:17,代碼來源:MP3Util.java

示例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;
    }
}
 
開發者ID:WeiMei-Tian,項目名稱:editor-sql,代碼行數:32,代碼來源:FeThumbUtils.java

示例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;
}
 
開發者ID:jiajunhui,項目名稱:XDisplay,代碼行數:27,代碼來源:AudioCoverUtil.java

示例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;
}
 
開發者ID:fendoudebb,項目名稱:PlayAndroid,代碼行數:30,代碼來源:LocalMusicLibrary.java

示例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);
        }
    }
}
 
開發者ID:skymania,項目名稱:Cirrus,代碼行數:23,代碼來源:PreviewMediaFragment.java

示例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;
}
 
開發者ID:jameliu,項目名稱:Camera2,代碼行數:25,代碼來源:LocalDataUtil.java

示例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;
}
 
開發者ID:asm-products,項目名稱:nexus-camera,代碼行數:26,代碼來源:LocalMediaData.java

示例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;
}
 
開發者ID:danieloeh,項目名稱:AntennaPodSP,代碼行數:20,代碼來源:Playable.java

示例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();
	}
}
 
開發者ID:TWiStErRob,項目名稱:glide-support,代碼行數:15,代碼來源:AudioCoverFetcher.java

示例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();
    }
}
 
開發者ID:aliumujib,項目名稱:Orin,代碼行數:16,代碼來源:AudioFileCoverFetcher.java

示例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;
}
 
開發者ID:mdnafiskhan,項目名稱:Mp3Player,代碼行數:11,代碼來源:artistdetailaddapter.java

示例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;
}
 
開發者ID:xxczaki,項目名稱:music-player,代碼行數:14,代碼來源:AlbumUtils.java

示例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;
}
 
開發者ID:GaneshPg,項目名稱:Musico,代碼行數:36,代碼來源:AllTracksFragment.java

示例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;
}
 
開發者ID:DmitriyG1,項目名稱:vk-music-player-android,代碼行數:31,代碼來源:VkAudioHelper.java

示例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 );
		}
	}
}
 
開發者ID:SilentCircle,項目名稱:silent-text-android,代碼行數:12,代碼來源:MediaPlayerFragmentICS.java


注:本文中的android.media.MediaMetadataRetriever.getEmbeddedPicture方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。