假设我有这个链接" https://www.youtube.com/watch?v=VgC4b9K-gYU"。现在我想获得这个视频的标题,并希望在我的WebView()中显示它... 怎么做??
这是我的代码
public class MainActivity extends AppCompatActivity {
Button btn;
WebView browser;
EditText url_text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
openURL();
}
public void openURL(){
btn = (Button) findViewById(R.id.button);
url_text =(EditText) findViewById(R.id.editText);
browser = (WebView) findViewById(R.id.webView);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url = "https://www.youtube.com/watch?v=VgC4b9K-gYU";
browser.getSettings().setLoadsImagesAutomatically(true);
browser.getSettings().setJavaScriptEnabled(true);
browser.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
browser.loadUrl(url);
browser.getSettings().getDisplayZoomControls();
}
});
}
}
我只想获取并打印网址包含的视频标题
答案 0 :(得分:0)
使用网址并不容易。您需要使用YouTube的API来获取标题。此信息来自JSON响应。
特定视频 https://developers.google.com/youtube/v3/docs/videos?csw=1
Java for Java https://developers.google.com/youtube/v3/code_samples/java
祝你好运答案 1 :(得分:0)
可以使用this
URL: https://www.googleapis.com/youtube/v3/videos?id=7lCDEYXw3mM&key=YOUR_API_KEY
&fields=items(id,snippet(channelId,title,categoryId),statistics)&part=snippet,statistics
Description: This example modifies the fields parameter from example 3 so that in the API response, each video resource's snippet object only includes the channelId, title, and categoryId properties.
API response:
{
"videos": [
{
"id": "7lCDEYXw3mM",
"snippet": {
"channelId": "UC_x5XG1OV2P6uZZ5FSM9Ttw",
"title": "Google I/O 101: Q&A On Using Google APIs",
"categoryId": "28"
},
"statistics": {
"viewCount": "3057",
"likeCount": "25",
"dislikeCount": "0",
"favoriteCount": "17",
"commentCount": "12"
}
}
]
}