-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b9d0ae
commit f816312
Showing
8 changed files
with
101 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.youth.xf.utils; | ||
|
||
import android.annotation.TargetApi; | ||
import android.graphics.Bitmap; | ||
import android.media.MediaMetadataRetriever; | ||
import android.media.ThumbnailUtils; | ||
import android.os.Build; | ||
import android.provider.MediaStore; | ||
|
||
import java.util.HashMap; | ||
|
||
public class VideoUtils { | ||
|
||
/** | ||
* 获取视频缩略图,放在线程中执行,比较耗时 | ||
* @param url 网络连接 | ||
* @param width 图片宽度 | ||
* @param height 突破高度 | ||
* @return | ||
*/ | ||
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) | ||
public static Bitmap createVideoThumbnail(String url, int width, int height) { | ||
Bitmap bitmap = null; | ||
MediaMetadataRetriever retriever = new MediaMetadataRetriever(); | ||
int kind = MediaStore.Video.Thumbnails.MINI_KIND; | ||
try { | ||
if (Build.VERSION.SDK_INT >= 14) { | ||
retriever.setDataSource(url, new HashMap<String, String>()); | ||
} else { | ||
retriever.setDataSource(url); | ||
} | ||
bitmap = retriever.getFrameAtTime(); | ||
} catch (IllegalArgumentException ex) { | ||
} catch (RuntimeException ex) { | ||
} finally { | ||
try { | ||
retriever.release(); | ||
} catch (RuntimeException ex) { | ||
} | ||
} | ||
if (kind == MediaStore.Images.Thumbnails.MICRO_KIND && bitmap != null) { | ||
bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height, | ||
ThumbnailUtils.OPTIONS_RECYCLE_INPUT); | ||
} | ||
return bitmap; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,5 +46,4 @@ | |
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="自定义" /> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters