2013-04-24 96 views
2

我在縮略圖中顯示視頻時遇到問題..如何以縮略圖顯示視頻網址?

從數據庫中檢索視頻鏈接並將其存儲在字符串數組中。

我想在縮略圖網格視圖中顯示視頻數組。如何實現這一點?它可能顯示?

任何人都可以幫助我嗎?提前致謝。

我想這....

vid = new ArrayList<String>(new ArrayList<String>(vid)); 

runOnUiThread(new Runnable() { 
    public void run() { 
     setContentView(R.layout.gallery); 
     GridView grd = (GridView)findViewById(R.id.gridView1); 
     grd.setAdapter(new ImageAdapter(this)); 
     grd.setOnItemClickListener(new OnItemClickListener() 
     { 
     public void onItemClick(AdapterView<?> parent,View v,int pos,long id) 
     { 
     Toast.makeText(getBaseContext(), 
         "pic"+(pos+1)+"select ",Toast.LENGTH_SHORT).show(); 
     } 
    }); 
} 
    }); 
     return; 
    private class ImageAdapter extends BaseAdapter { 
    private final Runnable context; 
    public ImageAdapter(Runnable runnable) { 
      context = runnable; 
    } 
    public int getCount() 
    { 
     return vid.size(); 
    } 
    public Object getItem(int position) 
    { 
     return position; 
    } 
    public long getItemId(int position) 
    { 
     return position; 
    } 
    public View getView(int position, View convertView, ViewGroup parent) 
    { 
     ImageView picturesView; 
     if (convertView == null) { 
      picturesView = new ImageView((Context) context); 
      //Creation of Thumbnail of video 
      Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(vid.get(position),0); 
      picturesView.setImageBitmap(bitmap); 
      picturesView.setScaleType(ImageView.ScaleType.FIT_XY); 
      //picturesView.setPadding(8, 8, 8, 8); 
      picturesView.setLayoutParams(new Gallery.LayoutParams(150, 120)); 
     }else { 
      picturesView = (ImageView)convertView; 
     } 
     return picturesView; 
    } 
+0

最初,您正在網格右側顯示圖像,您想要在點擊網格項目時執行什麼操作?在點擊網格項目時,應該在單獨的屏幕上播放視頻,還是必須在網格單元中播放視頻? – Padma 2013-04-24 11:26:37

+0

視頻應播放在單獨的屏幕你管視頻..在此之前,我應該顯示在網格視圖列表...指導我.. – 2013-04-24 11:48:11

+0

沒有人在那裏幫助我..請告訴我做錯了什麼我想改變 – 2013-04-24 12:33:46

回答

2

它非常簡單,而不是具有縮略圖/位圖網格項目和視頻網址類似如下字符串數組使用對象數組列表。

class video 
{ 
    Bitmap thumnail; 
    String videoURL; 
} 

從數據庫中創建此視頻類的數組列表,然後在getview中使用該數組列表。

videoList = new ArrayList<Video>(); 
// populate videolist 


public int getCount() 
{ 
    return videoList.size(); 
} 

public View getView(int position, View convertView, ViewGroup parent) 
{ 
    ImageView picturesView; 
    if (convertView == null) { 
     picturesView = new ImageView((Context) context); 
     //Creation of Thumbnail of video 
     //Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(vid.get(position),0); 
     Bitmap bitmap = videoList.get(position).thumnail; 
     picturesView.setImageBitmap(bitmap); 
     picturesView.setScaleType(ImageView.ScaleType.FIT_XY); 
     //picturesView.setPadding(8, 8, 8, 8); 
     picturesView.setLayoutParams(new Gallery.LayoutParams(150, 120)); 
    }else { 
     picturesView = (ImageView)convertView; 
    } 
    return picturesView; 
} 

然後在onitemclick,使用相同的arraylist你可以得到videourl,你可以在單獨的屏幕上播放視頻。

grd.setOnItemClickListener(new OnItemClickListener() 
    { 
    public void onItemClick(AdapterView<?> parent,View v,int pos,long id) 
    { 
    String videoLink = videoList.get(pos).videoURL; 
    // pass this video link to another activity where you want to play the video 
    } 
}); 
+0

即時通訊將視頻作爲JSONObject作爲字符串..如何將字符串存儲在ArrayList中

+0

簡單..when通過jsonObj.getString(「name_of_Field_URL」)解析json對象時,只需通過add(jsonObj.getString(「 name_of_Field_URL「)); – Jonny2Plates 2014-12-15 19:02:46