編輯:Android開發實例
和Image,Audio一樣,在Android中,Video信息也被MediaStore管理著。
和每個視頻對應的有其一個縮略圖,這個縮略圖往往是其第一幀的圖像。
下面看代碼:
- package demo.camera;
- import java.util.ArrayList;
- import java.util.List;
- import android.app.ListActivity;
- import android.content.Context;
- import android.database.Cursor;
- import android.net.Uri;
- import android.os.Bundle;
- import android.provider.MediaStore;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.BaseAdapter;
- import android.widget.ImageView;
- import android.widget.TextView;
- /**
- * 本實例,我們將通過檢索SDCard上的Video信息
- * 在MediaStore中,MediaStore.Video.Media中就有Video相關信息,
- * 同時MediaStore.Video.Thumbnails中含有各個video對應的縮略圖信息
- *
- * @author Administrator
- *
- */
- public class AdvancedVideoDemo extends ListActivity {
- private Cursor cursor;
- public void onCreate(Bundle savedInstanceState){
- super.onCreate(savedInstanceState);
- setContentView(R.layout.video_advanced);
- init();
- }
- private void init(){
- String[] thumbColumns = new String[]{
- MediaStore.Video.Thumbnails.DATA,
- MediaStore.Video.Thumbnails.VIDEO_ID
- };
- String[] mediaColumns = new String[]{
- MediaStore.Video.Media.DATA,
- MediaStore.Video.Media._ID,
- MediaStore.Video.Media.TITLE,
- MediaStore.Video.Media.MIME_TYPE
- };
- //首先檢索SDcard上所有的video
- cursor = this.managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, mediaColumns, null, null, null);
- ArrayList<VideoInfo> videoList = new ArrayList<AdvancedVideoDemo.VideoInfo>();
- if(cursor.moveToFirst()){
- do{
- VideoInfo info = new VideoInfo();
- info.filePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA));
- info.mimeType = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.MIME_TYPE));
- info.title = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.TITLE));
- //獲取當前Video對應的Id,然後根據該ID獲取其Thumb
- int id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID));
- String selection = MediaStore.Video.Thumbnails.VIDEO_ID +"=?";
- String[] selectionArgs = new String[]{
- id+""
- };
- Cursor thumbCursor = this.managedQuery(MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI, thumbColumns, selection, selectionArgs, null);
- if(thumbCursor.moveToFirst()){
- info.thumbPath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Thumbnails.DATA));
- }
- //然後將其加入到videoList
- videoList.add(info);
- }while(cursor.moveToNext());
- }
- //然後需要設置ListView的Adapter了,使用我們自定義的Adatper
- VideoAdapter adapter = new VideoAdapter(this, videoList);
- this.getListView().setAdapter(adapter);
- }
- static class VideoInfo{
- String filePath;
- String mimeType;
- String thumbPath;
- String title;
- }
- /**
- * 定義一個Adapter來顯示縮略圖和視頻title信息
- * @author Administrator
- *
- */
- static class VideoAdapter extends BaseAdapter{
- private Context context;
- private List<VideoInfo> videoItems;
- public VideoAdapter(Context context, List<VideoInfo> data){
- this.context = context;
- this.videoItems = data;
- }
- @Override
- public int getCount() {
- // TODO Auto-generated method stub
- return videoItems.size();
- }
- @Override
- public Object getItem(int p) {
- // TODO Auto-generated method stub
- return videoItems.get(p);
- }
- @Override
- public long getItemId(int p) {
- // TODO Auto-generated method stub
- return p;
- }
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- ViewHolder holder = null;
- if(convertView == null){
- holder = new ViewHolder();
- convertView = LayoutInflater.from(context).inflate(R.layout.video_item, null);
- holder.thumbImage = (ImageView)convertView.findViewById(R.id.thumb_image);
- holder.titleText = (TextView)convertView.findViewById(R.id.video_title);
- convertView.setTag(holder);
- }else{
- holder = (ViewHolder)convertView.getTag();
- }
- //顯示信息
- holder.titleText.setText(videoItems.get(position).title);
- if(videoItems.get(position).thumbPath != null){
- holder.thumbImage.setImageURI(Uri.parse(videoItems.get(position).thumbPath));
- }
- return convertView;
- }
- class ViewHolder{
- ImageView thumbImage;
- TextView titleText;
- }
- }
- }
需求:默認為00:00:00,點擊開始按鈕時清零後開始計時,出現如10:28:34。點擊停止的時候停止計時。問題:使用Calendar DateFormat的方法
今天看到一個ios寫的圖靈機器人,直接去官網(http://www.tuling123.com/openapi/)看了下API接入,太簡單了,就一個get請求~於
工廠方法模式定義: Define an interface for creating an object, but let subclasses decide w
這篇文章寫的非常好,深入淺出,關鍵還是一位大三學生自己剖析的心得。這是我喜歡此文的原因。下面請看正文: 作為一個大三的預備程序員,我學習android的一大樂趣是