Reputation: 11
Suppose i have this link " https://www.youtube.com/watch?v=VgC4b9K-gYU ". Now i want to get the title of this video and want to show it in my WebView()... How to do this ??
this is my code
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();
}
});
}
}
I just want to get and print the title of the video that the url contains
Upvotes: 0
Views: 5256
Reputation: 360
Can use 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"
}
}
]
}
Upvotes: 1
Reputation: 3046
Not as easy just by using a URL. You are going to need to use YouTube's API to get the title. This information comes from a JSON response.
Specific videos https://developers.google.com/youtube/v3/docs/videos?csw=1
API for Java https://developers.google.com/youtube/v3/code_samples/java
Good luck
Upvotes: 0