Putting Views on top SurfaceView Android -
i need code on android, i've been trying , searching 3 hours , no luck
so i've library call mediaplayersdk, i'm using in application play videos. library using surfaceview play video. now, i've include getsurfaceview().setzorderontop(true) player can show video otherwise not shown ( audio). but, when i'm using getsurfaceview().setzorderontop(true) cannot put view on top of player. want build controllers player couldn't. i've tired getsurfaceview().setzordermediaoverlay(true) , same problem video not shown.
the xml code activity:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/transparent"> <framelayout android:id="@+id/playerviewlayout" android:layout_width="fill_parent" android:layout_height="wrap_content" > <textview android:text="...." android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/chtitle" android:textcolor="@color/white" android:textstyle="bold" android:layout_marginleft="5dp"/> <veg.mediaplayer.sdk.mediaplayer android:id="@+id/playerview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_alignparenttop="true" android:layout_alignparentleft="true" android:layout_alignparentstart="true" /> </framelayout> </relativelayout>
and java code is
public class playeractivity extends appcompatactivity implements mediaplayer.mediaplayercallback { private static final string tag = "tag"; private boolean playing = false; private mediaplayer player = null; private enum playerstates { busy, readyforuse }; private enum playerconnecttype { normal, reconnecting }; private playerstates player_state = playerstates.readyforuse; private playerconnecttype reconnect_type = playerconnecttype.normal; private int moldmsg = 0; // event handler private handler handler = new handler() { string strtext = "connecting"; string stext; string scode; @override public void handlemessage(message msg) { mediaplayer.playernotifycodes status = (mediaplayer.playernotifycodes) msg.obj; switch (status) { case cp_connect_starting: if (reconnect_type == playerconnecttype.reconnecting) strtext = "reconnecting"; else strtext = "connecting"; player_state = playerstates.busy; //showstatusview(); reconnect_type = playerconnecttype.normal; break; case plp_build_successful: stext = player.getpropstring(mediaplayer.playerproperties.pp_property_plp_response_text); scode = player.getpropstring(mediaplayer.playerproperties.pp_property_plp_response_code); log.i(tag, "=status plp_build_successful: response stext="+stext+" scode="+scode); break; case vrp_need_surface: player_state = playerstates.busy; //showvideoview(); break; case plp_play_successful: player_state = playerstates.readyforuse; //stopprogresstask(); break; case plp_close_starting: player_state = playerstates.busy; //stopprogresstask(); //showstatusview(); setuidisconnected(); break; case plp_close_successful: player_state = playerstates.readyforuse; //stopprogresstask(); //showstatusview(); system.gc(); setuidisconnected(); break; case plp_close_failed: player_state = playerstates.readyforuse; //stopprogresstask(); //showstatusview(); setuidisconnected(); break; case cp_connect_failed: player_state = playerstates.readyforuse; //stopprogresstask(); //showstatusview(); setuidisconnected(); break; case plp_build_failed: stext = player.getpropstring(mediaplayer.playerproperties.pp_property_plp_response_text); scode = player.getpropstring(mediaplayer.playerproperties.pp_property_plp_response_code); log.i(tag, "=status plp_build_failed: response stext="+stext+" scode="+scode); player_state = playerstates.readyforuse; //stopprogresstask(); //showstatusview(); setuidisconnected(); break; case plp_play_failed: player_state = playerstates.readyforuse; //stopprogresstask(); //showstatusview(); setuidisconnected(); break; case plp_error: player_state = playerstates.readyforuse; //stopprogresstask(); //showstatusview(); setuidisconnected(); break; case cp_interrupted: player_state = playerstates.readyforuse; //stopprogresstask(); //showstatusview(); setuidisconnected(); break; case cp_record_started: log.v(tag, "=handlemessage cp_record_started"); { string sfile = player.recordgetfilename(1); toast.maketext(getapplicationcontext(),"record started. file "+sfile, toast.length_long).show(); } break; case cp_record_stopped: log.v(tag, "=handlemessage cp_record_stopped"); { string sfile = player.recordgetfilename(0); toast.maketext(getapplicationcontext(),"record stopped. file "+sfile, toast.length_long).show(); } break; //case content_provider_error_disconnected: case cp_stopped: case vdp_stopped: case vrp_stopped: case adp_stopped: case arp_stopped: if (player_state != playerstates.busy) { //stopprogresstask(); player_state = playerstates.busy; player.close(); //showstatusview(); player_state = playerstates.readyforuse; setuidisconnected(); } break; case cp_error_disconnected: if (player_state != playerstates.busy) { player_state = playerstates.busy; player.close(); //showstatusview(); player_state = playerstates.readyforuse; setuidisconnected(); toast.maketext(getapplicationcontext(), "demo version!", toast.length_short).show(); } break; default: player_state = playerstates.busy; } } }; // callback native player @override public int onreceivedata(bytebuffer buffer, int size, long pts) { log.e(tag, "form native player onreceivedata: size: " + size + ", pts: " + pts); return 0; } // event sent event handlers @override public int status(int arg) { mediaplayer.playernotifycodes status = mediaplayer.playernotifycodes.forvalue(arg); if (handler == null || status == null) return 0; log.e(tag, "form native player status: " + arg); switch (mediaplayer.playernotifycodes.forvalue(arg)) { default: message msg = new message(); msg.obj = status; handler.removemessages(moldmsg); moldmsg = msg.what; handler.sendmessage(msg); } return 0; } intent geti; string title, path = test_url; textview channeltitle; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_myplayer); geti = getintent(); // create player instance player = (mediaplayer)findviewbyid(r.id.playerview); channeltitle = (textview) findviewbyid(r.id.chtitle); title = geti.getstringextra("title"); path = geti.getstringextra("path"); channeltitle.settext(title); player.getsurfaceview().setzordermediaoverlay(true); // necessary surfaceholder sfhtrackholder = player.getsurfaceview().getholder(); sfhtrackholder.setformat(pixelformat.transparent); player.setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(view view, motionevent motionevent) { switch (motionevent.getaction() & motionevent.action_mask) { case motionevent.action_down: { if (player.getstate() == mediaplayer.playerstate.paused) player.play(); else if (player.getstate() == mediaplayer.playerstate.started) player.pause(); } } return true; } }); if (player != null) { player.getconfig().setconnectionurl(path); if (player.getconfig().getconnectionurl().isempty()) return; //player_record.close(); player.close(); playersettings sett = new playersettings(); boolean bport = (getresources().getconfiguration().orientation == configuration.orientation_landscape); int aspect = bport ? 1 : sett.rendererenableaspectratio; mediaplayerconfig conf = new mediaplayerconfig(); player.setvisibility(view.invisible); conf.setconnectionurl(player.getconfig().getconnectionurl()); conf.setconnectionnetworkprotocol(sett.connectionprotocol); conf.setconnectiondetectiontime(sett.connectiondetectiontime); conf.setconnectionbufferingtime(sett.connectionbufferingtime); conf.setdecodingtype(sett.decodertype); conf.setrenderertype(sett.renderertype); conf.setsynchroenable(sett.synchroenable); conf.setsynchroneeddropvideoframes(sett.synchroneeddropvideoframes); conf.setenablecolorvideo(sett.rendererenablecolorvideo); conf.setenableaspectratio(aspect); conf.setdatareceivetimeout(30000); conf.setnumberofcpucores(0); // open player player.open(conf, this); //record //conf.setmode(mediaplayer.playermodes.pp_mode_record); //conf.setrecordtrimposstart(10000); //from 10th sec //conf.setrecordtrimposend(20000); //to 20th sec /*player_record.open(conf, new mediaplayercallback(){ @override public int status(int arg) { log.i(tag, "=player_record status arg="+arg); return 0; } @override public int onreceivedata(bytebuffer buffer, int size, long pts) { // todo auto-generated method stub return 0; } });*/ playing = true; } } private int[] mcolorswapbuf = null; // used saveframe() public bitmap getframeasbitmap(bytebuffer frame, int width, int height) { bitmap bmp = bitmap.createbitmap(width, height, bitmap.config.argb_8888); bmp.copypixelsfrombuffer(frame); return bmp; } protected void onpause() { log.e("sdl", "onpause()"); super.onpause(); if (player != null) player.onpause(); } @override protected void onresume() { log.e("sdl", "onresume()"); super.onresume(); if (player != null) player.onresume(); } @override protected void onstart() { log.e("sdl", "onstart()"); super.onstart(); if (player != null) player.onstart(); } @override protected void onstop() { log.e("sdl", "onstop()"); super.onstop(); if (player != null) player.onstop(); } @override public void onbackpressed() { player.close(); setuidisconnected(); if (!playing) { super.onbackpressed(); return; } } @override public void onwindowfocuschanged(boolean hasfocus) { log.e("sdl", "onwindowfocuschanged(): " + hasfocus); super.onwindowfocuschanged(hasfocus); if (player != null) player.onwindowfocuschanged(hasfocus); } @override public void onlowmemory() { log.e("sdl", "onlowmemory()"); super.onlowmemory(); if (player != null) player.onlowmemory(); } @override protected void ondestroy() { log.e("sdl", "ondestroy()"); if (player != null) player.ondestroy(); system.gc(); super.ondestroy(); } protected void setuidisconnected() { playing = false; } @override public void onconfigurationchanged(configuration newconfig) { super.onconfigurationchanged(newconfig); } }
please need on
thank
Comments
Post a Comment