tv - What exactly is a "Surface" class in Android? -
i have been trying long time render video on "surface" class using mediaplayer class. playing audio, not video. everywhere search, people talk surfaceview , surfaceholder have surface object. how crack blocker?
this how tried,
public class samplevideoplayer{ private uri murl; private surface msurface; private mediaplayer mmediaplayer; private context mcontext; public samplevideoplayer(context context, string url, surface surface){ murl = uri.parse(url); msurface = surface; mmediaplayer = new mediaplayer(); mcontext = context; } public void playvideo() throws ioexception { mmediaplayer.setdatasource(mcontext, murl); mmediaplayer.setsurface(msurface); mmediaplayer.setonpreparedlistener(new mediaplayer.onpreparedlistener(){ @override public void onprepared(mediaplayer mediaplayer) { mediaplayer.start(); } }); mmediaplayer.prepareasync(); }
}
adding session object passing,
public class mytvsession extends tvinputservice.session implements handler.callback { context mcontext; string vidurl; surface msurface; samplevideoplayer player = null; samplemediaplayer mediaplayer; public mytvsession(context context){ super(context); channelxmlreader reader = new channelxmlreader(context); arraylist<channel> channels = reader.readxml(); mcontext = context; vidurl = channels.get(0).url; } @override public boolean handlemessage(message message) { log.d("handle message", message.tostring()); return true; } @override public void onrelease() { } @override public boolean onsetsurface(surface surface) { if(surface != null) log.d("not null session", "notnull"); msurface = surface; return true; } @override public void onsurfacechanged(int format, int width, int height) { super.onsurfacechanged(format, width, height); if(mediaplayer != null) mediaplayer.mmediaplayer.setsurface(msurface); log.d("onsurfacechanged", "event"); } @override public void onsetstreamvolume(float v) { } @override public boolean ontune(uri uri) { log.d("tuning channel", uri.tostring()); try { mediaplayer = new samplemediaplayer(mcontext, vidurl, msurface); mediaplayer.playvideo(); }catch(exception e){ log.d("mpexception", log.getstacktracestring(e)); } return true; } @override public void onsetcaptionenabled(boolean b) { }
}
the surface
class thin wrapper around buffer list shared backing surfaceflinger process, responsible rendering display.
you can 1 of these using surfaceview
, surfaceholder
, tied lifecycle of view. sure after being called when surface has been created.
alternatively, can use surfacetexture
created using own custom opengl context. approach can render using own opengl code or pass off media engine rendering. can surfacetexture
tied view subsystem using textureview
(but surfaceview
you'll need use @ appropriate time in lifecycle.)
Comments
Post a Comment