How to extract the response of youtube channel playlist and playing the videos using RTSP url in android programamtically -
hi new youtube api concept have response youtube channel correct response (www.googleapis.com/youtube/v3/playlistitems?part=snippet&maxresults=10&pagetoken=caoqaa&playlistid=uui87jbesbbhreub9uizmkkq&key=aizasybzeqaz2zifkdjatmkif57mgbwubs5plqu) response working fine cant play video please me
my coding is:
public class youtubeadapter extends recyclerview.adapter {
list<item> feeditems; context ctx; public youtubeadapter(context context, list<item> feeditems) { this.ctx = context; this.feeditems = feeditems; } @override public videoholder oncreateviewholder(viewgroup parent, int viewtype) { view itemview = layoutinflater.from(parent.getcontext()).inflate(r.layout.activity_video_items, parent, false); return new videoholder(itemview); } @override public void onbindviewholder(final videoholder holder, final int position) { final youtubethumbnailloader.onthumbnailloadedlistener onthumbnailloadedlistener = new youtubethumbnailloader.onthumbnailloadedlistener(){ @override public void onthumbnailerror(youtubethumbnailview youtubethumbnailview, youtubethumbnailloader.errorreason errorreason) { } @override public void onthumbnailloaded(youtubethumbnailview youtubethumbnailview, string s) { youtubethumbnailview.setvisibility(view.visible); holder.relativelayoutoveryoutubethumbnailview.setvisibility(view.visible); } }; holder.youtubethumbnailview.initialize("aizasybzeqaz2zifkdjatmkif57mgbwubs5plqu", new youtubethumbnailview.oninitializedlistener() { @override public void oninitializationsuccess(youtubethumbnailview youtubethumbnailview, youtubethumbnailloader youtubethumbnailloader) { final item item = feeditems.get(position); youtubethumbnailloader.setvideo(item.getid()); youtubethumbnailview.setimagebitmap(null);
// new loadimage(youtubethumbnailview).execute(item.getsnippet().getthumbnails().getdefault().geturl());
youtubethumbnailloader.setonthumbnailloadedlistener(onthumbnailloadedlistener); } @override public void oninitializationfailure(youtubethumbnailview youtubethumbnailview, youtubeinitializationresult youtubeinitializationresult) { //write failure } }); } @override public int getitemcount() { return feeditems.size(); } public class videoholder extends recyclerview.viewholder implements view.onclicklistener { protected relativelayout relativelayoutoveryoutubethumbnailview; youtubethumbnailview youtubethumbnailview; protected imageview playbutton; public videoholder(view itemview) { super(itemview); relativelayoutoveryoutubethumbnailview = (relativelayout) itemview.findviewbyid(r.id.relativelayout_over_youtube_thumbnail); youtubethumbnailview = (youtubethumbnailview) itemview.findviewbyid(r.id.youtube_thumbnail); playbutton=(imageview)itemview.findviewbyid(r.id.btnyoutube_player); playbutton.setonclicklistener(this); } @override public void onclick(view v) { item item = feeditems.get(getlayoutposition()); if(youtubeapiserviceutil.isyoutubeapiserviceavailable(ctx).equals(youtubeinitializationresult.success)){ //this means device has youtube api service (the app) , safe launch it. intent intent = youtubestandaloneplayer.createvideointent((activity) ctx,"aizasybzeqaz2zifkdjatmkif57mgbwubs5plqu", item.getid()); ctx.startactivity(intent); }else{ // log outcome, take necessary measure, playing video in webview :) toast.maketext(ctx, "unsuccess", toast.length_short).show(); } } }
}
my mainactivity is:
public class mainactivity extends appcompatactivity {
private youtubeadapter videoadapter; private listview listview; private list<item> feeditems = new arraylist<>(); @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); retrofit retrofit = youtubeclient.getclient(); youtubeinterface apiservice = retrofit.create(youtubeinterface.class); final recyclerview recyclerview=(recyclerview)findviewbyid(r.id.list); recyclerview.sethasfixedsize(true); //to use recycleview, need layout manager. default linearlayoutmanager linearlayoutmanager linearlayoutmanager=new linearlayoutmanager(this); linearlayoutmanager.setorientation(linearlayoutmanager.vertical); recyclerview.setlayoutmanager(linearlayoutmanager); call<videos> call = apiservice.getvideos(); call.enqueue(new callback<videos>() { @override public void onresponse(call<videos> call, response<videos> response) { int statuscode = response.code(); videos posts = response.body(); feeditems = posts.getitems(); youtubeadapter adapter=new youtubeadapter(mainactivity.this,feeditems); recyclerview.setadapter(adapter); } @override public void onfailure(call<videos> call, throwable t) { } }); }
}
i have reffered lot of tutorials rtsp url has use playing videos after response
down vote accepted after reading different youtube apis found following steps consume youtube channel videos in android app.
1) create application in google account 2) enable youtube services 3) , developer key
use developer key make api calls.
4)
string url = "https://www.googleapis.com/youtube/v3/channels?part=snippet%2ccontentdetails%2cstatistics&id=ucjd0dhs3o7uiuqdzpsbadaa&key=" + developerkey.developer_key; use cannel id in above url along developer key list of videos under channel.
5) basic information of each video still cannot play video in android video player in order must have rtsp url
and url can obtain passing video id http://gdata.youtube.com/feeds/mobile/videos/1fjhyqe0rdg
that's all.
but stucked in step 5 please me..
Comments
Post a Comment