I'm building an app for Android to read twitter feed I got an issue to play video from a tweet. Currently my tweet feed is showing the thumb image and when I click on it, if it's an image I show the image and in case of a video I expect to be able to play it.
To load the image, I'm doing:
ImageLoader mImageLoader = new ImageLoader(mActivity);
mImageLoader.DisplayImage(mPicToShowUrl, tweet_pic) ;
mPicToShowUrl is coming from :
mediaEntity.getMediaURL().toString();
mediaEntity is coming from the Twitter4j Status.getExpandedURL
tweet_pic is just an ImageView
The URL get look like : example.com/xxx/status/89284924/video/1 which is mainly unusable on any player as it do not contain something like xxx.com/1.avi
This kind of URL and ImageLoader allow to load an image. I'm looking for the same method for a video
I think the twitter video is more a streaming video
Any idea how to play a video from twitter in an ImageView or any other View ?
Thanks
You need to look in the extended_entities of the response. You'll see something like
"extended_entities": {
"media": [
{
"id": 567972074346807300,
"id_str": "567972074346807296",
"indices": [
46,
68
],
"media_url": "http://pbs.twimg.com/ext_tw_video_thumb/567972074346807296/pu/img/uz53Ap4wEah7cV50.jpg",
"media_url_https": "https://pbs.twimg.com/ext_tw_video_thumb/567972074346807296/pu/img/uz53Ap4wEah7cV50.jpg",
"url": "http://t.co/cGazAn7H3E",
"display_url": "pic.twitter.com/cGazAn7H3E",
"expanded_url": "http://twitter.com/katiemoffat/status/567972190639022080/video/1",
"type": "video",
"sizes": {
"small": {
"w": 340,
"h": 340,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"medium": {
"w": 600,
"h": 600,
"resize": "fit"
},
"large": {
"w": 720,
"h": 720,
"resize": "fit"
}
},
"video_info": {
"aspect_ratio": [
1,
1
],
"duration_millis": 6605,
"variants": [
{
"bitrate": 832000,
"content_type": "video/mp4",
"url": "https://video.twimg.com/ext_tw_video/567972074346807296/pu/vid/480x480/eU1s1ig_skHgeRjB.mp4"
},
{
"content_type": "application/x-mpegURL",
"url": "https://video.twimg.com/ext_tw_video/567972074346807296/pu/pl/tr7sF7aHBPOCuL8H.m3u8"
},
{
"bitrate": 832000,
"content_type": "video/webm",
"url": "https://video.twimg.com/ext_tw_video/567972074346807296/pu/vid/480x480/eU1s1ig_skHgeRjB.webm"
},
{
"bitrate": 1280000,
"content_type": "video/mp4",
"url": "https://video.twimg.com/ext_tw_video/567972074346807296/pu/vid/720x720/njkDGgpJBpsTjQD3.mp4"
},
{
"bitrate": 320000,
"content_type": "video/mp4",
"url": "https://video.twimg.com/ext_tw_video/567972074346807296/pu/vid/240x240/Gye4gcWtlJq8zXhF.mp4"
}
]
}
}
]
},
So, you need to access extended_entities->media->video_info->variants to see all the different sizes and formats of video available.
You can choose between different sizes of MP4, a WEBM, and a stream - depending on what is suitable for the device you're playing back on.
(Taken from https://shkspr.mobi/blog/2015/02/working-with-the-twitter-videos-api/ )
Related
Can anybody tell me how can i play the live streaming cam video from this response of API world-cam..
I am getting problem to preview the video from this link directly :
{
"live": {
"available": true,
"embed": "https://api.lookr.com/embed/player/1485691420/live"
},
"day": {
"available": true,
"link": "https://www.lookr.com/lookout/1485691420#action-play-day",
"embed": "https://api.lookr.com/embed/player/1485691420/day"
},
"month": {
"available": true,
"link": "https://www.lookr.com/lookout/1485691420#action-play-month",
"embed": "https://api.lookr.com/embed/player/1485691420/month"
},
}
If you wish stream and play Video in Android App , you can use this library : Vitamio Library
i have a problem trying to retrieve some date from googleapis, youtubeapi.
here is the link:
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=UUpXSJOEKMoOhdwdh_7AJ2Vg&key=SOMEKEY
If i go to any browser and paste that url i have all the data that i need, a json like this:
{
"kind": "youtube#playlistItemListResponse",
"etag": "\"ld9biNPKjAjgjV7EZ4EKeEGrhao/CokfSR1Ka3d1R0DGLPIfTD3IZqU\"",
"nextPageToken": "CAUQAA",
"pageInfo": {
"totalResults": 993,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#playlistItem",
"etag": "\"ld9biNPKjAjgjV7EZ4EKeEGrhao/hYDAQqaQpnjwln2FQWxqH4pNDwM\"",
"id": "VVVwWFNKT0VLTW9PaGR3ZGhfN0FKMlZnLk1OMXp4Vm5WWEZv",
"snippet": {
"publishedAt": "2017-11-30T13:53:50.000Z",
"channelId": "UCpXSJOEKMoOhdwdh_7AJ2Vg",
"title": "Amaneciendo Con Dios - Celebrando La Vida Pastor General",
"description": "",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/MN1zxVnVXFo/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/MN1zxVnVXFo/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/MN1zxVnVXFo/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "TaberTV",
"playlistId": "UUpXSJOEKMoOhdwdh_7AJ2Vg",
"position": 0,
"resourceId": {
"kind": "youtube#video",
"videoId": "MN1zxVnVXFo"
}
}
},`
}
And the json goes on.
When i try to retrieve it with volley i get this error:
12-01 10:54:08.082 3690-3690/com.tabernaculo.app E/Volley: [1] 4.onErrorResponse: Error:
My code to retrieve data with volley works with other websites, how can i make it work with youtube? This is how i send the url
urlEncoded = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId="+URLEncoder.encode(playListID,"UTF-8").toString()+"&key="+URLEncoder.encode(APIKEY,"UTF-8").toString();
I have tried pasting just the parameters without URLEncoder and there's no change.
My JSON contains only name of the food categories, Looks like below
[
{
"cu_id": "2",
"cuisine_type": "American"
},
{
"cu_id": "24",
"cuisine_type": "Sandwich"
},
{
"cu_id": "17",
"cuisine_type": "Seafood"
},
{
"cu_id": "29",
"cuisine_type": "Sports Bar"
},
{
"cu_id": "5",
"cuisine_type": "Steak"
},
{
"cu_id": "20",
"cuisine_type": "Sushi"
}
]
I want to get default image automatically from Internet by searching 'cuisine_type', How to do that?
You can use pixabay api it's a free RESTful api for searching and retrieving free images and videos released on Pixabay under Creative Commons CC0.
Sending a GET request like this :
https://pixabay.com/api/?key={ KEY }&q=query&image_type=photo
where :
Key : the api key you get after creating an account
q : the queried object you need to look for
image_type : what kind of data you need (picture, video)
returned data will be something like this :
{
"total": 4692,
"totalHits": 500,
"hits": [
{
"id": 195893,
"pageURL": "https://pixabay.com/en/blossom-bloom-flower-yellow-close-195893/",
"type": "photo",
"tags": "blossom, bloom, flower",
"previewURL": "https://static.pixabay.com/photo/2013/10/15/09/12/flower-195893_150.jpg"
"previewWidth": 150,
"previewHeight": 84,
"webformatURL": "https://pixabay.com/get/35bbf209db8dc9f2fa36746403097ae226b796b9e13e39d2_640.jpg",
"webformatWidth": 640,
"webformatHeight": 360,
"imageWidth": 4000,
"imageHeight": 2250,
"imageSize": 4731420,
"views": 7671,
"downloads": 6439,
"favorites": 1,
"likes": 5,
"comments": 2,
"user_id": 48777,
"user": "Josch13",
"userImageURL": "https://static.pixabay.com/user/2013/11/05/02-10-23-764_250x250.jpg",
},
{
"id": 14724,
...
},
...
]
}
for more detail visit this link
Here is my json file i use thumbnail on listview but there no such tag that fetch videos . Define it which tag i use ?
That perfectly add thumbnail or other things
Below is my preview of Listview items
{
"kind": "youtube#playlistItemListResponse",
"etag": "\"GM4ZnRh2gk1X1BLWgHklTm-3cgQ/uvcwjZ_9_NYCLF7JAzfY5FiuzuQ\"",
"nextPageToken": "CAUQAA",
"pageInfo": {
"totalResults": 1998,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#playlistItem",
"etag": "\"GM4ZnRh2gk1X1BLWgHklTm-3cgQ/dCBViPWfe-MGrqHIcuMZ55HcLJ0\"",
"id": "VVVHaENWR1owWlNwZTVoSkhXeWlMd0hBLlZHRHFaakFMSF9N",
"snippet": {
"publishedAt": "2017-01-26T08:58:26.000Z",
"channelId": "UCGhCVGZ0ZSpe5hJHWyiLwHA",
"title": "Top 10 - Scariest scenes in Resident evil 7",
"description": "Resident Evil 7 brings the series back to its roots while mak Epidemic Sound.\nhttp://www.epidemicsound.com/youtube-creator-subscription/",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/VGDqZjALH_M/default.jpg",
"width": 120,
"height": 90
},
},
"channelTitle": "ZoominGames",
"playlistId": "UUGhCVGZ0ZSpe5hJHWyiLwHA",
"position": 0,
"resourceId": {
"kind": "youtube#video",
"videoId": "VGDqZjALH_M"
}
}
},
Well, it is true that you cannot find any url in the json output. The only thing that you can get from here is the videoId.
You can use this videoId as part of this https://www.youtube.com/watch?v="insert_videoId" to get a video link.
So in your case, this is the link https://www.youtube.com/watch?v=VGDqZjALH_M
I am trying to get all videos of a channel. I am getting the video id and thumbnails etc...but i am not able get likes, dis likes and comments count of a video.
For example: here i am using BBC News channel id in the below url.
https://www.googleapis.com/youtube/v3/search?key={MY API KEY}&channelId=UC16niRr50-MSBwiO3YDb3RA&part=snippet,id&order=date&maxResults=20
With this url i am getting viedo information but not likes, dis likes and comments count of a individual video.
Please help me. TIA
The search results just contain basic information. You have to then take the video ids from the search results and make a separate API request to get the details you want for the videos.
https://www.googleapis.com/youtube/v3/videos?key={MY API KEY}&part=statistics&id={IDs}
IDs are a comma separated list of the video id's you retrieved from the search.
It is not possible to get the search results along with the all the video information ( likecount, etc) on a single api call. However you can implement it programatically by
1) first get the search results
2) get video info of each result firing another api call
You can get all the details of the video by specifying the part as contentDetails,statistics,snippet
payload = {'id': search_result["id"]["videoId"], 'part': 'contentDetails,statistics,snippet', 'key': DEVELOPER_KEY}
l = requests.Session().get('https://www.googleapis.com/youtube/v3/videos', params=payload)
print l.text
Response will be as following:
{
"kind": "youtube#videoListResponse",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/EMbbi9ruIqgq1ERymR5oC-ODvkE\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/nk4zkCbyR6ftbwbccNAGvGN4ay0\"",
"id": "gm0iQQyKHlQ",
"snippet": {
"publishedAt": "2017-05-05T04:33:36.000Z",
"channelId": "UCsvNpjj4RxIRXnY9lOeTq-g",
"title": "Kasaba Malayalam Full Movie | Latest Mammootty Movie | New Malayalam Film | Mammootty Movies",
"description": "latest mammootty malayalam movie full HD\nkasaba malayalam movie\nmalayalam new films",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/gm0iQQyKHlQ/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/gm0iQQyKHlQ/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/gm0iQQyKHlQ/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/gm0iQQyKHlQ/sddefault.jpg",
"width": 640,
"height": 480
},
"maxres": {
"url": "https://i.ytimg.com/vi/gm0iQQyKHlQ/maxresdefault.jpg",
"width": 1280,
"height": 720
}
},
"channelTitle": "malayalam new films",
"tags": [
"malayalam new films",
"new movies",
"new movies 2017 full movies",
"latest movies",
"malayalam movie new",
"malayalam film",
"malayalam film new",
"malayalam full movie",
"new",
"film",
"movie",
"cinema",
"songs",
"kasaba malayalam movie",
"kasaba",
"kasaba full movie",
"kasaba hot",
"kasaba songs",
"kasaba scenes",
"kasaba movie",
"kasaba full movie online",
"mammootty",
"mammootty malayalam full movie",
"mammootty new movie trailer",
"mammootty songs",
"mammootty great father",
"puthan panam",
"Varalaxmi Sarathkumar",
"Neha Saxena"
],
"categoryId": "1",
"liveBroadcastContent": "none",
"localized": {
"title": "Kasaba Malayalam Full Movie | Latest Mammootty Movie | New Malayalam Film | Mammootty Movies",
"description": "latest mammootty malayalam movie full HD\nkasaba malayalam movie\nmalayalam new films"
}
},
"contentDetails": {
"duration": "PT2H15M59S",
"dimension": "2d",
"definition": "hd",
"caption": "false",
"licensedContent": true,
"regionRestriction": {
"blocked": [
"IN"
]
},
"projection": "rectangular"
},
"statistics": {
"viewCount": "437181",
"likeCount": "1135",
"dislikeCount": "391",
"favoriteCount": "0",
"commentCount": "40"
}
}
]
}