问题描述
我一直在努力奋斗着这个2天了...在此之后回答: http://stackoverflow.com/a/2006454/444324 - 它被提及,它可能发挥在GLSurfaceView的视频通过改变API演示的MediaPlayerDemo_Video例如:
我试图取代了SurfaceView到GLSurfaceView的建议,也使用本但它只是崩溃的开始:
07-11 14:54:22.086:E / AndroidRuntime(12373):致命异常:主要
07-11 14:54:22.086:E / AndroidRuntime(12373):显示java.lang.NullPointerException
07-11 14:54:22.086:E / AndroidRuntime(12373):在android.opengl.GLSurfaceView.surfaceCreated(GLSurfaceView.java:512)
07-11 14:54:22.086:E / AndroidRuntime(12373):在android.view.SurfaceView.updateWindow(SurfaceView.java:533)
07-11 14:54:22.086:E / AndroidRuntime(12373):在android.view.SurfaceView.access $ 000(SurfaceView.java:81)
07-11 14:54:22.086:E / AndroidRuntime(12373):在android.view.SurfaceView $ 3.on preDraw(SurfaceView.java:169)
07-11 14:54:22.086:E / AndroidRuntime(12373):在android.view.ViewTreeObserver.dispatchOn preDraw(ViewTreeObserver.java:590)
07-11 14:54:22.086:E / AndroidRuntime(12373):在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1617)
07-11 14:54:22.086:E / AndroidRuntime(12373):在android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
07-11 14:54:22.086:E / AndroidRuntime(12373):在android.os.Handler.dispatchMessage(Handler.java:99)
07-11 14:54:22.086:E / AndroidRuntime(12373):在android.os.Looper.loop(Looper.java:137)
07-11 14:54:22.086:E / AndroidRuntime(12373):在android.app.ActivityThread.main(ActivityThread.java:4575)
07-11 14:54:22.086:E / AndroidRuntime(12373):在java.lang.reflect.Method.invokeNative(本机方法)
07-11 14:54:22.086:E / AndroidRuntime(12373):在java.lang.reflect.Method.invoke(Method.java:511)
07-11 14:54:22.086:E / AndroidRuntime(12373):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:786)
07-11 14:54:22.086:E / AndroidRuntime(12373):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-11 14:54:22.086:E / AndroidRuntime(12373):在dalvik.system.NativeStart.main(本机方法)
我知道我可以使用一个VideoView播放视频,或只是留在SurfaceView与MediaPlayer的,但我必须使用一个GLSurfaceView,因为我需要这个视频摄像头表面观之上进行播放。
感谢您!
相关code:我的XML:
< XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直>
< com.commonsware.android.camera.MyGLSurfaceView
机器人:ID =@ + ID /面
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =中心/>
< / LinearLayout中>
我的类别:
公共类MediaPlayerDemo_Video扩展活动器具
OnBufferingUpdateListener,OnCompletionListener,
在preparedListener,OnVideoSizeChangedListener,SurfaceHolder.Callback {
私人MediaPlayer的mMediaPlayer;
私人MyGLSurfaceView米preVIEW;
私人SurfaceHolder持有人;
/ **
*
*第一次创建活动时调用。
* /
@覆盖
公共无效的onCreate(包冰柱){
super.onCreate(冰柱);
的setContentView(R.layout.mediaplayer_2);
米preVIEW =(MyGLSurfaceView)findViewById(R.id.surface);
持有人= M preview.getHolder();
holder.addCallback(本);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
}
MyGLSurfaceView类:
类MyGLSurfaceView扩展android.opengl.GLSurfaceView {
公共MyGLSurfaceView(上下文的背景下,ATTRS的AttributeSet){
超(背景下,ATTRS);
}
}
确定,解决了这个...我有几个错误,但最终的错误我present在我的问题是通过将本code,以解决中的onCreate:
米preview.setRenderer(新的渲染(){
@覆盖
公共无效onSurfaceCreated(GL10 GL,EGLConfig配置){
// TODO自动生成方法存根
}
@覆盖
公共无效onSurfaceChanged(GL10 GL,诠释的宽度,高度INT){
// TODO自动生成方法存根
}
@覆盖
公共无效onDrawFrame(GL10 GL){
// TODO自动生成方法存根
}
});
I've been struggling with this for 2 days now...Following this answer: http://stackoverflow.com/a/2006454/444324 - it is mentioned that it's possible to play a video in a GLSurfaceView by altering the MediaPlayerDemo_Video example in API Demos:
I tried replacing the SurfaceView to a GLSurfaceView as suggested, also using this but it just crashes on start:
07-11 14:54:22.086: E/AndroidRuntime(12373): FATAL EXCEPTION: main
07-11 14:54:22.086: E/AndroidRuntime(12373): java.lang.NullPointerException
07-11 14:54:22.086: E/AndroidRuntime(12373): at android.opengl.GLSurfaceView.surfaceCreated(GLSurfaceView.java:512)
07-11 14:54:22.086: E/AndroidRuntime(12373): at android.view.SurfaceView.updateWindow(SurfaceView.java:533)
07-11 14:54:22.086: E/AndroidRuntime(12373): at android.view.SurfaceView.access$000(SurfaceView.java:81)
07-11 14:54:22.086: E/AndroidRuntime(12373): at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:169)
07-11 14:54:22.086: E/AndroidRuntime(12373): at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:590)
07-11 14:54:22.086: E/AndroidRuntime(12373): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1617)
07-11 14:54:22.086: E/AndroidRuntime(12373): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
07-11 14:54:22.086: E/AndroidRuntime(12373): at android.os.Handler.dispatchMessage(Handler.java:99)
07-11 14:54:22.086: E/AndroidRuntime(12373): at android.os.Looper.loop(Looper.java:137)
07-11 14:54:22.086: E/AndroidRuntime(12373): at android.app.ActivityThread.main(ActivityThread.java:4575)
07-11 14:54:22.086: E/AndroidRuntime(12373): at java.lang.reflect.Method.invokeNative(Native Method)
07-11 14:54:22.086: E/AndroidRuntime(12373): at java.lang.reflect.Method.invoke(Method.java:511)
07-11 14:54:22.086: E/AndroidRuntime(12373): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-11 14:54:22.086: E/AndroidRuntime(12373): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-11 14:54:22.086: E/AndroidRuntime(12373): at dalvik.system.NativeStart.main(Native Method)
I know I can use a VideoView to play a video or just stay with SurfaceView with MediaPlayer but I must use a GLSurfaceView because I need this video to be played on top of the camera surface view.
Thank you!
Relevant code:my XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.commonsware.android.camera.MyGLSurfaceView
android:id="@+id/surface"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</LinearLayout>
My Class:
public class MediaPlayerDemo_Video extends Activity implements
OnBufferingUpdateListener, OnCompletionListener,
OnPreparedListener, OnVideoSizeChangedListener, SurfaceHolder.Callback {
private MediaPlayer mMediaPlayer;
private MyGLSurfaceView mPreview;
private SurfaceHolder holder;
/**
*
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.mediaplayer_2);
mPreview = (MyGLSurfaceView) findViewById(R.id.surface);
holder = mPreview.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
}
MyGLSurfaceView Class:
class MyGLSurfaceView extends android.opengl.GLSurfaceView {
public MyGLSurfaceView(Context context, AttributeSet attrs) {
super(context, attrs);
}
}
OK, solved this... I had several errors but the final error I present in my question is solved by adding this code to the onCreate:
mPreview.setRenderer(new Renderer() {
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
// TODO Auto-generated method stub
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
// TODO Auto-generated method stub
}
@Override
public void onDrawFrame(GL10 gl) {
// TODO Auto-generated method stub
}
});
这篇关于在GLSurfaceView播放SurfaceView的视频,而不是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!