2013-04-25 73 views
2

我有一個數組中的url字符串。如何在gridview中顯示視頻的網址,並點擊下一個屏幕中的網格播放。 如何實現這個?任何一個指導我..如何使用視頻網址字符串在網格視圖中顯示視頻

我試過像其作品fine..How實現對視頻,陣列是string..url ..

public class act extends Activity { 
/** Called when the activity is first created. */ 
//Integer[] imageIDs={R.drawable.icon,R.drawable.icon,R.drawable.icon}; 
String uri1="https://i3.ytimg.com/vi/bQaWsVQSLdY/default.jpg"; 
String uri2="https://i4.ytimg.com/vi/cJQCniWQdno/mqdefault.jpg"; 
String uri3="https://i1.ytimg.com/vi/D8dA4pE5hEY/mqdefault.jpg"; 
String[] urls={uri1,uri2,uri3}; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    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(); 
    } 
    }); 
} 
public class ImageAdapter extends BaseAdapter 
{ 
    private Context context; 
    private int itemBackground; 
    ImageAdapter(Context c) 
    { 
    context=c; 
    TypedArray a=obtainStyledAttributes(R.styleable.Gallery1); 
    itemBackground=a.getResourceId(R.styleable.Gallery1_android_galleryItemBackground,0); 
    a.recycle(); 
    } 
    public int getCount() 
    { 
     return urls.length; 
    } 
    public Object getItem(int pos) 
    { 
     return pos; 
    } 
    public long getItemId(int pos) 
    { 
     return pos; 
    } 
    public View getView(int pos,View cv,ViewGroup vg) 
    { 
     ImageView imageview=new ImageView(context); 
     imageview.setImageResource(urls.length); 
     imageview.setScaleType(ImageView.ScaleType.FIT_XY); 
     imageview.setLayoutParams(new GridView.LayoutParams(150,120)); 
     imageview.setBackgroundResource(itemBackground); 
     return imageview; 
    } 
    } 
} 

非常感謝提前....

+0

視頻快到形式在哪裏?自己的服務器或YouTube? – 2013-04-25 05:54:05

+0

將youtube鏈接存儲在服務器中,其來自服務器 – 2013-04-25 06:01:01

+0

,那麼youtube會爲您提供該視頻的縮略圖。你爲什麼不想顯示文本? – 2013-04-25 06:13:06

回答

4

你錯了,在這個舞臺上。

How to display the url of video in gridview ? 

不要嘗試將URL打印到網格視圖項目中。 YouTube會在不同的框架中提供特定視頻的縮略圖。所以請直接使用該網址並播放。

下面是YouTube的縮略圖(通過幀順序)

YouTube網址的圖片網址:http://img.youtube.com/vi/

VIDEO_ID: AxeOPU6n1_M

幀號:0.jpg

最終YouTube縮略圖網址

http://img.youtube.com/vi/AxeOPU6n1_M/0.jpg

http://img.youtube.com/vi/AxeOPU6n1_M/1.jpg

http://img.youtube.com/vi/AxeOPU6n1_M/2.jpg

所以,在結束時,你必須從網絡服務獲得youtube_img_url所以你可以使用它。

如果你不知道如何設置來自服務器的圖像,請查看下面的鏈接。

Example - 1

LazyList

兩個例子是很好的,現在你必須只需更新你的代碼按要求。

How to play on click the grid plays in next screen. 

這裏應該是通過意圖調用的新活動,這將在YouTube播放器中播放。

@Override 
     public void onCreate(Bundle savedInstanceState) 
     { 
     super.onCreate(savedInstanceState); 
      setContentView(R.layout.videoplaying); 
      String url= "Your url"; 
      Uri uri=Uri.parse(url); 
      VideoView video=(VideoView)findViewById(R.id.videoplaying); 
      video.setVideoURI(uri); 
      video.start(); 
     } 
+0

我的鏈接像這樣[https://www.youtube.com/embed/exdhhTjP00g?feature=player_detailpage] – 2013-04-25 06:53:45

+0

我不會打印的網址我應該顯示視頻的網址縮略圖在網格....你能理解.. – 2013-04-25 06:55:38

+0

請指導在代碼中顯示網格視頻的網址... – 2013-04-25 06:57:53

1

你試試這個:

選擇一個圖像時,請使用該特定網址,然後開始新的活動。

新活動代碼:

@Override 
     public void onCreate(Bundle savedInstanceState) 
     { 
     super.onCreate(savedInstanceState); 
      setContentView(R.layout.videoplaying); 
      String url= "Your url"; 
      Uri uri=Uri.parse(url); 
      VideoView video=(VideoView)findViewById(R.id.videoplaying); 
      video.setVideoURI(uri); 
      video.start(); 
     } 
+0

請先閱讀標題,他沒有問及如何播放。他想要顯示該鏈接或縮略圖。 – 2013-04-25 06:19:37

+0

@chintankhetiya你的權利..我需要在網格中的視頻縮略圖... – 2013-04-25 06:21:22

+0

@ chintan khetiya他還要求在下一個屏幕播放該視頻。這個答案是爲了.. – Subburaj 2013-04-25 06:22:18

-1
@Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.video); 
     String url= "Write your Url"; 
     Uri uri=Uri.parse(url); 
     VideoView video=(VideoView)findViewById(R.id.videoview); 
     video.setVideoURI(uri); 
     video.start(); 
    }