android - How to put a MediaController in a TextureView -
i'm trying put media controller in texture view have error saying
e/mediaplayer﹕ should have subtitle controller set
here code
@override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.texture_video); textureview = (textureview) findviewbyid(r.id.textureview); listview = (listview) findviewbyid(r.id.list); . . . arrayadapter<string> adapter = new arrayadapter<string>(this, android.r.layout.simple_list_item_1, android.r.id.text1, values); listview.setadapter(adapter); listview.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { if (position == 0) { ondestroy(); file_name = "test1.mp4"; textureview.setsurfacetexturelistener(videoassetactivity.this); onsurfacetextureavailable(textureview.getsurfacetexture(), view.getwidth(), view.getheight()); } else if (position == 1) { ondestroy(); file_name = "test2.mp4"; textureview.setsurfacetexturelistener(videoassetactivity.this); onsurfacetextureavailable(textureview.getsurfacetexture(), view.getwidth(), view.getheight()); } else if (position == 2) { ondestroy(); file_name = "test3.mp4"; textureview.setsurfacetexturelistener(videoassetactivity.this); onsurfacetextureavailable(textureview.getsurfacetexture(), view.getwidth(), view.getheight()); } else if (position == 3) { ondestroy(); file_name = "test4.mp4"; textureview.setsurfacetexturelistener(videoassetactivity.this); onsurfacetextureavailable(textureview.getsurfacetexture(), view.getwidth(), view.getheight()); } } }); textureview.setsurfacetexturelistener(this); } @override protected void ondestroy() { super.ondestroy(); if (mmediaplayer != null) { mmediaplayer.stop(); mmediaplayer.release(); mmediaplayer = null; } } @override public void onsurfacetextureavailable(surfacetexture surfacetexture, int i, int i2) { surface surface = new surface(surfacetexture); try { assetfiledescriptor afd = getassets().openfd(file_name); mmediaplayer = new mediaplayer(); mmediaplayer.setdatasource(afd.getfiledescriptor(), afd.getstartoffset(), afd.getlength()); mmediaplayer.setsurface(surface); mmediaplayer.setlooping(true); mmediaplayer.prepareasync(); onsurfacetextureupdated(surfacetexture); mmediaplayer.setonpreparedlistener(new mediaplayer.onpreparedlistener() { @override public void onprepared(mediaplayer mediaplayer) { // set media controller videocontroller = new mediacontroller(videoassetactivity.this); videocontroller.setanchorview(textureview); videocontroller.setpadding(0, 0, 0, 0); mediaplayer.start(); } }); } catch (illegalargumentexception e) { log.d(tag, e.getmessage()); } catch (securityexception e) { log.d(tag, e.getmessage()); } catch (illegalstateexception e) { log.d(tag, e.getmessage()); } catch (ioexception e) { log.d(tag, e.getmessage()); } }
my problem set controller doesn't shows if play other mp4. i've searched solution see audio file only. can me? thank much..
- implement
mediacontroller.mediaplayercontrol
- override needed functions
show controller code:
mediacontroller videocontroller = new mediacontroller(getactivity()); videocontroller.setmediaplayer(this);//your activity implemented mediaplayercontrol videocontroller.setanchorview(mtextureview); videocontroller.setenabled(true); videocontroller.show();
have fun!
Comments
Post a Comment