quickblox video call not going -
package com.esolz.sweet_date.sweetdate.fragments; import android.app.fragment; import android.content.broadcastreceiver; import android.content.context; import android.content.intent; import android.content.intentfilter; import android.media.audiomanager; import android.media.mediaplayer; import android.os.bundle; import android.os.handler; import android.util.displaymetrics; import android.util.log; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.horizontalscrollview; import android.widget.imagebutton; import android.widget.imageview; import android.widget.linearlayout; import android.widget.textview; import android.widget.togglebutton; import com.esolz.sweet_date.sweetdate.r; import com.esolz.sweet_date.sweetdate.helper.applicationsingleton; import com.esolz.sweet_date.sweetdate.holder.dataholder; import com.esolz.sweet_date.sweetdate.activity.mainactivity; import com.esolz.sweet_date.sweetdate.sweetdate.listusersactivity; import com.quickblox.core.exception.qbresponseexception; import com.quickblox.users.qbusers; import com.quickblox.users.model.qbuser; import com.quickblox.videochat.webrtc.qbrtcsession; import com.quickblox.videochat.webrtc.qbrtctypes; import java.io.serializable; import java.util.arraylist; import java.util.list; import java.util.map; /** * created tereha on 16.02.15. */ public class videoconversationfragment extends fragment implements serializable { private string tag = videoconversationfragment.class.getsimplename(); private arraylist<integer> opponents; private int qbconferencetype; private int startreason; private string sessionid; private textview opponentnumber; private textview connectionstatus; private imageview opponentavatar; private togglebutton cameratoggle; private togglebutton switchcameratoggle; private togglebutton dynamictogglevideocall; private togglebutton mictogglevideocall; private imagebutton handupvideocall; private imageview imgmycameraoff; private textview incusername; private view view; private map<string, string> userinfo; private view opponentitemview; private horizontalscrollview camerasopponentslist; // public static linearlayout opponentsfromcall; private layoutinflater inflater; private viewgroup container; private bundle savedinstancestate; private boolean isvideoenabled = true; private boolean isaudioenabled = true; private list<qbuser> allusers = new arraylist<>(); private linearlayout actionvideobuttonslayout; private view actionbar; private string callername; private linearlayout novideoimagecontainer; private boolean ismessageprocessed; private mediaplayer ringtone; private view localvideoview; private view remotevideoview; private intentfilter intentfilter; private audiostreamreceiver audiostreamreceiver; private camerastate camerastate = camerastate.none; linearlayout actionvideobuttons; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view = inflater.inflate(r.layout.frag_chat_view, container, false); this.inflater = inflater; this.container = container; log.d(tag, "fragment. thread id: " + thread.currentthread().getid()); final handler h = new handler(); final int delay = 3000; //milliseconds actionvideobuttons=(linearlayout)view.findviewbyid(r.id.actionvideobuttons); h.postdelayed(new runnable() { public void run() { //do actionvideobuttons.setvisibility(view.visible); } }, delay); ((mainactivity) getactivity()).initactionbarwithtimer(); if (getarguments() != null) { opponents = getarguments().getintegerarraylist(applicationsingleton.opponents); qbconferencetype = getarguments().getint(applicationsingleton.conference_type); startreason = getarguments().getint(mainactivity.start_conversation_reason); sessionid = getarguments().getstring(mainactivity.session_id); callername = getarguments().getstring(mainactivity.caller_name); log.d(tag, "caller_name: " + callername); } initviews(view); initbuttonslistener(); // createopponentslist(opponents); setupuibycalltype(qbconferencetype); return view; } private void setupuibycalltype(int qbconferencetype) { if (qbconferencetype == qbrtctypes.qbconferencetype.qb_conference_type_audio.getvalue()) { // cameratoggle.setvisibility(view.gone); switchcameratoggle.setvisibility(view.invisible); localvideoview.setvisibility(view.invisible); remotevideoview.setvisibility(view.invisible); imgmycameraoff.setvisibility(view.invisible); } } public void actionbuttonsenabled(boolean enability) { // cameratoggle.setenabled(enability); switchcameratoggle.setenabled(enability); // imgmycameraoff.setenabled(enability); // mictogglevideocall.setenabled(enability); // dynamictogglevideocall.setenabled(enability); // inactivate toggle buttons //cameratoggle.setactivated(enability); switchcameratoggle.setactivated(enability); // imgmycameraoff.setactivated(enability); // mictogglevideocall.setactivated(enability); // dynamictogglevideocall.setactivated(enability); } @override public void onstart() { getactivity().registerreceiver(audiostreamreceiver, intentfilter); super.onstart(); qbrtcsession session = ((mainactivity) getactivity()).getcurrentsession(); if (!ismessageprocessed) { if (startreason == startconversetionreason.income_call_for_acception.ordinal()) { session.acceptcall(session.getuserinfo()); } else { session.startcall(session.getuserinfo()); startoutbeep(); } ismessageprocessed = true; } } private void startoutbeep() { ringtone = mediaplayer.create(getactivity(), r.raw.beep); ringtone.setlooping(true); ringtone.start(); } public void stopoutbeep() { if (ringtone != null) { try { ringtone.stop(); } catch (illegalstateexception e) { e.printstacktrace(); } catch (exception e) { e.printstacktrace(); } ringtone.release(); ringtone = null; } } @override public void oncreate(bundle savedinstancestate) { log.d(tag, "oncreate() " + tag); super.oncreate(savedinstancestate); intentfilter = new intentfilter(); intentfilter.addaction(audiomanager.action_headset_plug); intentfilter.addaction(audiomanager.action_sco_audio_state_updated); audiostreamreceiver = new audiostreamreceiver(); } private void initviews(view view) { localvideoview = view.findviewbyid(r.id.localvideovidew); remotevideoview = view.findviewbyid(r.id.remotevideoview); // opponentsfromcall = (linearlayout) view.findviewbyid(r.id.opponentsfromcall); // cameratoggle = (togglebutton) view.findviewbyid(r.id.cameratoggle); switchcameratoggle = (togglebutton) view.findviewbyid(r.id.switchcameratoggle); // dynamictogglevideocall = (togglebutton) view.findviewbyid(r.id.dynamictogglevideocall); // mictogglevideocall = (togglebutton) view.findviewbyid(r.id.mictogglevideocall); // actionvideobuttonslayout = (linearlayout) view.findviewbyid(r.id.element_set_video_buttons); handupvideocall = (imagebutton) view.findviewbyid(r.id.handupvideocall); incusername = (textview) view.findviewbyid(r.id.incusername); // incusername.settext(callername); // incusername.setbackgroundresource(listusersactivity.selectbackgrounforopponent(( // dataholder.getuserindexbyfullname(callername)) + 1)); novideoimagecontainer = (linearlayout) view.findviewbyid(r.id.novideoimagecontainer); // imgmycameraoff = (imageview) view.findviewbyid(r.id.imgmycameraoff); actionbuttonsenabled(false); } @override public void onresume() { super.onresume(); // if user changed camera state few times , last state camerastate.enabled_from_user // Жень, глянь здесь, смысл в том,
что мы здесь включаем камеру, если юзер ее не выключал // turn on cam, else nothing change if (camerastate != camerastate.disabled_from_user && qbconferencetype == qbrtctypes.qbconferencetype.qb_conference_type_video.getvalue()) { togglecamera(true); } }
@override public void onpause() { // if camera state camerastate.enabled_from_user or camerastate.none // turn off cam if(camerastate != camerastate.disabled_from_user) { togglecamera(false); } super.onpause(); } @override public void onstop() { super.onstop(); stopoutbeep(); getactivity().unregisterreceiver(audiostreamreceiver); } private void initbuttonslistener() { switchcameratoggle.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { if (((mainactivity) getactivity()).getcurrentsession() != null) { ((mainactivity) getactivity()).getcurrentsession().switchcaptureposition(new
runnable() { @override public void run() { // toast.maketext(getactivity(), "cam switched", toast.length_long).show(); } }); log.d(tag, "camera switched!"); } } });
// cameratoggle.setonclicklistener(new view.onclicklistener() { // @override // public void onclick(view v) { //// if (((mainactivity) getactivity()).getcurrentsession() != null) { // if (camerastate != camerastate.disabled_from_user) { // togglecamera(false); // camerastate = camerastate.disabled_from_user; // } else { // togglecamera(true); // camerastate = camerastate.enabled_from_user; // } //// } // // } // }); // dynamictogglevideocall.setonclicklistener(new view.onclicklistener() { // @override // public void onclick(view v) { // if (((mainactivity) getactivity()).getcurrentsession() != null) { // log.d(tag, "dynamic switched!"); // ((mainactivity) getactivity()).getcurrentsession().switchaudiooutput(); // } // } // }); // mictogglevideocall.setonclicklistener(new view.onclicklistener() { // @override // public void onclick(view v) { // if (((mainactivity) getactivity()).getcurrentsession() != null) { // if (isaudioenabled) { // log.d(tag, "mic off!"); // ((mainactivity) getactivity()).getcurrentsession().setaudioenabled(false); // isaudioenabled = false; // } else { // log.d(tag, "mic on!"); // ((mainactivity) getactivity()).getcurrentsession().setaudioenabled(true); // isaudioenabled = true; // } // } // } // }); handupvideocall.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { stopoutbeep(); actionbuttonsenabled(false); handupvideocall.setenabled(false); log.d(tag, "call stopped"); // ((mainactivity) getactivity()).getcurrentsession().hangup(userinfo); ((mainactivity) getactivity()).hangupcurrentsession(); handupvideocall.setenabled(false); handupvideocall.setactivated(false); } }); } private void togglecamera(boolean isneedenablecam) { // todo temporary insertion removed when glvideoview fixed displaymetrics displaymetrics = new displaymetrics(); displaymetrics.settodefaults(); // viewgroup.layoutparams layoutparams = imgmycameraoff.getlayoutparams(); //layoutparams.height = localvideoview.getheight(); // layoutparams.width = localvideoview.getwidth(); // imgmycameraoff.setlayoutparams(layoutparams); // log.d(tag, "width is: " + imgmycameraoff.getlayoutparams().width + " height is:" +
imgmycameraoff.getlayoutparams().height); // todo end
if (((mainactivity) getactivity()).getcurrentsession() != null) { ((mainactivity) getactivity()).getcurrentsession().setvideoenabled(isneedenablecam); // cameratoggle.setchecked(isneedenablecam); if (isneedenablecam) { log.d(tag, "camera on!"); switchcameratoggle.setvisibility(view.visible); // imgmycameraoff.setvisibility(view.invisible); } else { log.d(tag, "camera off!"); switchcameratoggle.setvisibility(view.invisible); // imgmycameraoff.setvisibility(view.visible); } } } public static enum startconversetionreason { income_call_for_acception, outcome_call_made; } private list<qbuser> getopponentsfromcall(arraylist<integer> opponents) { arraylist<qbuser> opponentslist = new arraylist<>(); (integer opponentid : opponents) { try { opponentslist.add(qbusers.getuser(opponentid)); } catch (qbresponseexception e) { e.printstacktrace(); } } return opponentslist; } // private void createopponentslist(list<integer> opponents) { // if (opponents.size() != 0) { // (integer : opponents) { // addopponentpreviewtolist(i, opponentsfromcall); // } // } // } private void addopponentpreviewtolist(integer userid, linearlayout opponentsfromcall) { if (opponentsfromcall.findviewbyid(userid) == null) { view opponentitemview = inflater.inflate(r.layout.list_item_opponent_from_call,
opponentsfromcall, false); opponentitemview.setid(userid);
opponentitemview.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { log.d(tag, "main opponent selected"); } }); textview opponentnumber = (textview) opponentitemview.findviewbyid(r.id.opponentnumber); opponentnumber.settext(string.valueof(listusersactivity.getuserindex(userid))); opponentnumber.setbackgroundresource(listusersactivity.resourceselector (listusersactivity.getuserindex(userid))); imageview opponentavatar = (imageview) opponentitemview.findviewbyid(r.id.opponentavatar); opponentavatar.setimageresource(r.drawable.ic_noavatar); opponentsfromcall.addview(opponentitemview); } else { opponentsfromcall.addview(opponentsfromcall.findviewbyid(userid)); } } private string getcallername(qbrtcsession session) { string s = new string(); int = session.getcallerid(); allusers.addall(dataholder.userslist); (qbuser usr : allusers) { if (usr.getid().equals(i)) { s = usr.getfullname(); } } return s; } private class audiostreamreceiver extends broadcastreceiver { @override public void onreceive(context context, intent intent) { if (intent.getaction().equals(audiomanager.action_headset_plug)){ log.d(tag, "action_headset_plug " + intent.getintextra("state", -1)); } else if (intent.getaction().equals(audiomanager.action_sco_audio_state_updated)){ log.d(tag, "action_sco_audio_state_updated " + intent.getintextra("extra_sco_audio_state", -2)); } if (intent.getintextra("state", -1) == 0 /*|| intent.getintextra("extra_sco_audio_state", -1) == 0*/){ // dynamictogglevideocall.setchecked(false); } else if (intent.getintextra("state", -1) == 1) { // dynamictogglevideocall.setchecked(true); } else { // toast.maketext(context, "output audio stream incorrect", toast.length_long).show(); } // dynamictogglevideocall.invalidate(); } } private enum camerastate { none, disabled_from_user, enabled_from_user } }
Comments
Post a Comment