http://www.devdiv.net/bbs/thread-33989-1-1.html
1、Video
对于视频,取第一帧作为缩略图,也就是怎样从filePath得到一个Bitmap对象。
private Bitmap createVideoThumbnail(String filePath) {
Bitmap bitmap = null;
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
retriever.setMode(MediaMetadataRetriever.MODE_CAPTURE_FRAME_ONLY);
retriever.setDataSource(filePath);
bitmap = retriever.captureFrame();
} catch(IllegalArgumentException ex) {
// Assume this is a corrupt video file
} catch (RuntimeException ex) {
// Assume this is a corrupt video file.
} finally {
try {
retriever.release();
} catch (RuntimeException ex) {
// Ignore failures while cleaning up.
}
}
return bitmap;
}
Android提供了MediaMetadataRetriever,由JNI(media_jni)实现。
看得出MediaMetadataRetriever主要有两个功能:MODE_GET_METADATA_ONLY和MODE_CAPTURE_FRAME_ONLY
这里设mode为MODE_CAPTURE_FRAME_ONLY,调用captureFrame取得一帧。
另外还有两个方法可以用:
extractMetadata 提取文件信息,ARTIST、DATE、YEAR、DURATION、RATING、FRAME_RATE、VIDEO_FORMAT
和extractAlbumArt 提取专辑信息,这个下面的音乐文件可以用到。
2、Music
对于音乐,取得AlbumImage作为缩略图,还是用MediaMetadataRetriever
private Bitmap createAlbumThumbnail(String filePath) {
Bitmap bitmap = null;
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
retriever.setMode(MediaMetadataRetriever.MODE_GET_METADATA_ONLY);
retriever.setDataSource(filePath);
byte[] art = retriever.extractAlbumArt();
bitmap = BitmapFactory.decodeByteArray(art, 0, art.length);
} catch(IllegalArgumentException ex) {
} catch (RuntimeException ex) {
} finally {
try {
retriever.release();
} catch (RuntimeException ex) {
// Ignore failures while cleaning up.
}
}
return bitmap;
}
retriever.extractAlbumArt()得到的是byte数组,还需要一步用BitmapFactory编码得到Bitmap对象。
3、Image
图片就很简单了
Bitmap bm = null;
Options op = new Options();
op.inSampleSize = inSampleSize;
op.inJustDecodeBounds = false;
bm = BitmapFactory.decodeFile(mFile.getPath(), op);
能直接得到Bitmap对象,把图片缩小到合适大小就OK。
同样上面的Video和Music,retrive到Bitmap后也需要缩小处理。
很多网站都通过User-Agent来判断浏览器类型,如果是3G手机,显示手机页面内容,如果是普通浏览器,显示普通网页内容。)User Agent (以下简称 UA)是一个浏览器的身份标识,比如我正在用的 Chromium UA 就是
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10
各个参数的含义如下表:
Chrome 8.0.552.224 Mozilla MozillaProductToken. Claims to be a Mozilla based user agent, which is only true for Gecko browsers like Firefox and Netscape. For all other user agents it means 'Mozilla-compatible'. In modern browsers, this is only used for historical reasons. It has no real meaning anymore 5.0 Mozilla Version Windows Platform U Security values:
- N for no security
- U for strong security
- I for weak security
Windows 7 en-US Language Tag, indicates the language for which the client had been localized (e.g. menus and buttons in the user interface)
en-US = English - United States AppleWebKit The Web Kit provides a set of core classes to display web content in windows 534.10 Web Kit build KHTML KHTML like Gecko like Gecko Chrome Name :
Chrome 8.0.552.224 Version Safari Based on Safari 534.10 Safari build Description: Free open-source web browser developed by Google. Chromium is the name of the open source project behind Google Chrome, released under the BSD license.
All Chrome user agent strings
谷歌Chrome浏览器,可以很方便地用来当3G手机模拟器。在Windows的【开始】-->【运行】中输入以下命令,启动谷歌浏览器,即可模拟相应手机的浏览器去访问3G手机网页:
谷歌Android:
苹果iPhone:
或
chrome.exe --user-agent="Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16"
诺基亚N97:
试一试,分别用Android、iPhone、诺基亚访问http://g.iuni.com.cn、http://www.163.com/、http://blog.s135.com/、http://www.google.com.hk/、http://3g.qq.com、http://t.sina.cn这些3G手机网页,看看有什么不同。
更多款手机的User-Agent:http://www.zytrax.com/tech/web/mobile_ids.html
如果想切换回普通浏览器模式,关掉所有Chrome浏览器,重开即可。如果不想关闭浏览器,切回普通浏览器模式,则访问:
1)FrameLayout常常与 merge 相关,关于他们各自的介绍,请参阅相关的文档。在这里,
用来合并两个透明的png图片,就像photoshop里图层合并一样。
2)Frame动画animation-list,常常用于制作短片动画或用于进程进度的一个指示标识。
先附图如下:
下面是部分代码:
res/anim/scrolling.xml
<?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" id="selected" android:oneshot="false"> <item android:drawable="@drawable/ball1" android:duration="80" /> <item android:drawable="@drawable/ball2" android:duration="80" /> <item android:drawable="@drawable/ball3" android:duration="80" /> <item android:drawable="@drawable/ball4" android:duration="80" /> <item android:drawable="@drawable/ball5" android:duration="80" /> <item android:drawable="@drawable/ball6" android:duration="80" /> </animation-list>
res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content"> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_centerHorizontal="true" android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/frame01"> <ImageView android:src="/blog_article/@drawable/line/index.html" android:layout_width="300sp" android:layout_height="200sp"> </ImageView> <ImageView android:src="/blog_article/@drawable/bar/index.html" android:layout_width="300sp" android:layout_height="200sp"> </ImageView> </FrameLayout> <ImageView android:id="@+id/scrolling_anim" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:layout_centerHorizontal="true" android:layout_below="@id/frame01" android:layout_marginTop="15sp"/> </RelativeLayout>
package com.sunflower; import java.util.Timer; import java.util.TimerTask; import android.app.Activity; import android.graphics.drawable.AnimationDrawable; import android.os.Bundle; import android.widget.ImageView; public class FrameActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); ImageView img = (ImageView)findViewById(R.id.scrolling_anim); img.setBackgroundResource(R.anim.scrolling); //设置动画的载体(画布) StopAnim mar2 = new StopAnim(); Timer t2 = new Timer(false); t2.schedule(mar2, 10000); //10秒后停止动画 } class StartUpAnim extends TimerTask { public void run() { ImageView img = (ImageView)findViewById(R.id.scrolling_anim); // Get the background, which has been compiled to an AnimationDrawable object. AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground(); // Start the animation (looped playback by default). frameAnimation.start(); } } class StopAnim extends TimerTask { public void run() { ImageView img = (ImageView)findViewById(R.id.scrolling_anim); // Get the background, which has been compiled to an AnimationDrawable object. AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground(); // stop the animation (looped playback by default). frameAnimation.stop(); } } @Override protected void onResume() { super.onResume(); StartUpAnim mar = new StartUpAnim(); //放在这里执行是让frameAnimation有足够的时间取得画布(Images's background) Timer t = new Timer(false); t.schedule(mar, 1000); //延迟1秒后才开始动画 } }
附件是整个app project.