我有一个 GDATA 链接,我想在我的应用程序中使用它。此链接包含一个播放列表,我希望该播放列表显示在 ListView 中。然后,用户将选择他/她想要的视频,然后可以使用本地 Youtube 应用在应用内播放。
请给我指出一个直观的教程。我知道 YouTube API 页面包含所有信息,但我可以从中得出结论。
最佳答案
我希望这会给你一个想法试试这个(只是一个例子),如果你有更好的解决方案也请告诉我。
package com.test.utubevdo;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONObject;
import android.app.Activity;
import android.app.Dialog;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.ListView;
import android.widget.VideoView;
public class AndroidThumbnailList extends Activity{
ArrayList <YTBVideo> videos = new ArrayList<YTBVideo>();
ProgressDialog progressDialog = null;
VideoView vdovw_1 = null;
String vdoURL = "";
ListView listview = null;
Gallery gallery = null;
Dialog noDataAlert = null;
Handler imageLoaderHandler = new Handler() {
public void handleMessage(final Message msg) {
progressDialog.dismiss();
if(msg.what == 1){
showErrorMessage("Communication Error", "Error Occured while retrieving the data from Youtube.\n Please try again");
}else{
System.out.println("videos ::"+videos.size());
//listview.setAdapter(new VideoViewAdapter(AndroidThumbnailList.this, videos));
gallery.setAdapter(new VideoViewAdapter1(AndroidThumbnailList.this, videos));
}
}
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
//setContentView(R.layout.imagelist_layout);
//listview = (ListView)findViewById(R.id.listView1);
setContentView(R.layout.gallery_imagelist_layout);
gallery = (Gallery) findViewById(R.id.galleryView);
gallery.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View view, int position, long id) {
Intent videoDisplayIntent = new Intent("com.test.utubevdo.VIEW_VIDEO");
System.out.println("String.valueOf(view.getTag()) :::"+((YTBVideo)videos.get(position)).getId());
videoDisplayIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
videoDisplayIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
videoDisplayIntent.putExtra("VIDEO_ID", ((YTBVideo)videos.get(position)).getId());
startActivity(videoDisplayIntent);
}
});
progressDialog = ProgressDialog.show(this, "Loading Video Images", "Loading Video Images", true, false);
// setListAdapter(new MyThumbnaildapter(AndroidThumbnailList.this, R.layout.row, videoFileList));
}
/*@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
super.onCreateContextMenu(menu, v, menuInfo);
}*/
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
try{
DownloaderTAsk downloaderTAsk = (DownloaderTAsk) new DownloaderTAsk().execute(getApplicationContext());
}catch (Exception e) {
// TODO: handle exception
}
}
class DownloaderTAsk extends AsyncTask{
@Override
protected Object doInBackground(Object... arg0) {
// TODO Auto-generated method stub
try{
printVideoFEEJSONString("http://gdata.youtube.com/feeds/api/videos?alt=jsonc&q=football+-soccer&orderby=published&start-index=11&max-results=10&v=2");
//printVideoFEEJSONString("https://gdata.youtube.com/feeds/api/videos?alt=json&q=football+-soccer&orderby=published&start-index=11&max-results=10&v=2");
imageLoaderHandler.sendEmptyMessage(0);
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
imageLoaderHandler.sendEmptyMessage(1);
}
return null;
}
@Override
protected void onPostExecute(Object result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
}
}
public void printVideoFEEJSONString(String feedURL){
BufferedReader bufferedReader = null;
try{
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(feedURL);
HttpResponse response = client.execute(request);
bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer jsonStringBuffer = new StringBuffer("");
String line = "";
String newLine = System.getProperty("line.separator");
while ((line = bufferedReader.readLine()) != null) {
jsonStringBuffer.append(line + newLine);
}
String appUpdatorJsonString = jsonStringBuffer.toString();
System.out.println("YOUTUBE VIDEO FEED JSON :"+appUpdatorJsonString);
JSONObject updaterAppJsonObject = new JSONObject(appUpdatorJsonString);
System.out.println("YOUTUBE VIDEO FEED JSON OBJECT :"+updaterAppJsonObject);
processYoutubeVideoFEEJSONObject(updaterAppJsonObject);
}catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}
}
public void processYoutubeVideoFEEJSONObject(JSONObject updaterAppJsonObject){
JSONObject dataJSONObject = null;
JSONArray itemsJSONArray = null;
JSONObject itemsJSONObject = null;
JSONObject linkJSONObject = null;
String yvURL = "";
YTBVideo yVideo = null;
try{
dataJSONObject = updaterAppJsonObject.getJSONObject("data");
itemsJSONArray = dataJSONObject.getJSONArray("items");
for(int i = 0; i < itemsJSONArray.length(); i++){
yVideo = new YTBVideo();
// for(int i = 0; i < 1; i++){
itemsJSONObject = itemsJSONArray.getJSONObject(i);
yVideo.setId(itemsJSONObject.getString("id"));
yVideo.setThumbNailURL(itemsJSONObject.getJSONObject("thumbnail").getString("sqDefault"));
yVideo.setVideoImageURL(itemsJSONObject.getJSONObject("player").getString("default"));
yVideo.setTitle(itemsJSONObject.getString("title"));
yvURL = itemsJSONObject.getJSONObject("player").getString("default");
String videoURL = yvURL.substring(0,yvURL.indexOf("&"));
vdoURL = videoURL;
System.out.println("Youtube URL is ::"+videoURL);
System.out.println("videoURL ::"+videoURL);
yVideo.setThumbnailImage(preloadBitmap(yVideo));
videos.add(yVideo);
}
}catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}
}
private Bitmap preloadBitmap(YTBVideo yTBVideo) throws MalformedURLException,IOException {
Bitmap photoBitmap= null;
try{
BitmapFactory.Options imageOptions = null;
imageOptions = new BitmapFactory.Options();
imageOptions.outHeight = 250;
imageOptions.outHeight = 150;
String FlickrPhotoPath = yTBVideo.getThumbNailURL();
URL FlickrPhotoUrl = null;
System.out.println("FlickrPhotoPath:::::::"+FlickrPhotoPath);
//try {
FlickrPhotoUrl = new URL(FlickrPhotoPath);
HttpURLConnection httpConnection = (HttpURLConnection) FlickrPhotoUrl.openConnection();
httpConnection.setDoInput(true);
httpConnection.connect();
InputStream inputStream = httpConnection.getInputStream();
//photoBitmap = BitmapFactory.decodeStream(inputStream);
photoBitmap = BitmapFactory.decodeStream(inputStream,null,imageOptions);
System.out.println("photoBitmap:::::::"+photoBitmap);
/*} catch (MalformedURLException e) {
//e.printStackTrace();
} catch (IOException e) {
//e.printStackTrace();
}*/
}catch (Exception e) {
// TODO: handle exception
//showErrorMessage("communication error", "Unable to connect to Flickr Server");
e.printStackTrace();
}
return photoBitmap;
}
protected void showErrorMessage(String messageLine1, String message)
{
noDataAlert = Utiliy.getAlertMessage(getBaseContext(), this, messageLine1.toUpperCase()+":\n"+message, 1);
noDataAlert.getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
noDataAlert.setCanceledOnTouchOutside(true);
noDataAlert.setCancelable(true);
Button yesButton = (Button)noDataAlert.findViewById(R.id.alert_popup_yes_button);
yesButton.setText(" OK ");
yesButton.setTextSize(24);
yesButton.setPadding(5, 5, 5, 5);
yesButton.setVisibility(View.VISIBLE);
yesButton.setOnClickListener(new OnClickListener(){
public void onClick(View view){
noDataAlert.dismiss();
finish();
}
});
noDataAlert.show();
}
}
package com.test.utubevdo;
import java.util.List;
import com.keyes.youtube.OpenYouTubePlayerActivity;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Bundle;
public class DisplayYoutubeVideo extends Activity {
String vdoID = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
vdoID = (String) getIntent().getExtras().get("VIDEO_ID");
System.out.println("vdoID :::"+vdoID);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
startVideo(vdoID);
}
private void startVideo ( String videoID ) { // default youtube app
Intent i = new Intent ( Intent . ACTION_VIEW , Uri . parse ( "vnd.youtube:" + videoID ));
List < ResolveInfo > list = getPackageManager (). queryIntentActivities ( i , PackageManager . MATCH_DEFAULT_ONLY );
if ( list . size () == 0 ) {
//write you own activity to display the video, if default youtube video display class is not available or else use the default class it self
}
System.out.println("Intent Actin :"+i.getAction());
startActivity ( i );
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.utubevdo"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8"/>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name="com.test.utubevdo.AndroidThumbnailList"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.test.utubevdo.DisplayYoutubeVideo"
android:label="@string/app_name">
<intent-filter>
<action android:name="com.test.utubevdo.VIEW_VIDEO" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
关于android - ListView 中显示的 Youtube 播放列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7491439/
我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
是否有类似“RVMuse1”或“RVMuselist[0]”之类的内容而不是键入整个版本号。在任何时候,我们都会看到一个可能包含5个或更多ruby的列表,我们可以轻松地键入一个数字而不是X.X.X。这也有助于rvmgemset。 最佳答案 这在RVM2.0中是可能的=>https://docs.google.com/document/d/1xW9GeEpLOWPcddDg_hOPvK4oeLxJmU3Q5FiCNT7nTAc/edit?usp=sharing-知道链接的任何人都可以发表评论
所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择
我试图在索引页中创建一个超链接,但它没有显示,也没有给出任何错误。这是我的index.html.erb代码。ListingarticlesTitleTextssss我检查了我的路线,我认为它们也没有问题。PrefixVerbURIPatternController#Actionwelcome_indexGET/welcome/index(.:format)welcome#indexarticlesGET/articles(.:format)articles#indexPOST/articles(.:format)articles#createnew_articleGET/article
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c
目前,Itembelongs_toCompany和has_manyItemVariants。我正在尝试使用嵌套的fields_for通过Item表单添加ItemVariant字段,但是使用:item_variants不显示该表单。只有当我使用单数时才会显示。我检查了我的关联,它们似乎是正确的,这可能与嵌套在公司下的项目有关,还是我遗漏了其他东西?提前致谢。注意:下面的代码片段中省略了不相关的代码。编辑:不知道这是否相关,但我正在使用CanCan进行身份验证。routes.rbresources:companiesdoresources:itemsenditem.rbclassItemi
如果我在模型中设置验证消息validates:name,:presence=>{:message=>'Thenamecantbeblank.'}我如何让该消息显示在闪光警报中,这是我迄今为止尝试过的方法defcreate@message=Message.new(params[:message])if@message.valid?ContactMailer.send_mail(@message).deliverredirect_to(root_path,:notice=>"Thanksforyourmessage,Iwillbeintouchsoon")elseflash[:error]
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路
我刚刚按照thebootsygempage上的安装说明进行操作在我保存并查看帖子内容之前,一切看起来都不错。这是输出在View中的样子:HeaderSubhead:似乎没有呈现任何html格式,因为它被引号或类似的东西转义了-其他人有这个问题吗?我没有在github页面或SO上看到任何问题来指出我正确的方向。除了遵循gem安装说明之外,我还没有做任何事情,但也许我错过了什么或者只是犯了一个愚蠢的错误。如果你还有什么想知道的,请尽管问。干杯 最佳答案 你需要有这样的东西,转义html: 关