textureview onSurfaceTextureAvailable never called inside relativelayout inside fragment

后端 未结 7 1417
走了就别回头了
走了就别回头了 2020-12-10 10:52

onSurfaceTextureAvailable in VideoView is never called...
I have this view that is holding the textureview.

public class MyMediaPlayer extends RelativeLa         


        
相关标签:
7条回答
  • 2020-12-10 11:16

    As for me ,the key to solve the problem is that add android:hardwareAccelerated="true" for the activity in the AndroidManifest.xml .

    You can use TextureView in a Scrolling-Container(Such as ListView,ScrollView,ViewPager etc) only if the activity for the TextureView with hardwareAccelerated property on.

    The last few words in this blog mentioned that

    Hope it works for you.

    0 讨论(0)
  • 2020-12-10 11:21

    try to put mTextureView.setSurfaceTextureListener() in onCreate().

    RootCause is that: onCreate() -> drawUI -> getHardwareLayer() -> callback SurfaceTextureListener. So to fix this issue: setSurfaceTextureListener() before UI draw or redraw the UI.

    0 讨论(0)
  • 2020-12-10 11:27

    onSurfaceTextureAvailable doesn't seem to get called if the SurfaceTexture is already available. You can check if it is available and call your onSurfaceTextureAvailable method like below.

    textureView.setSurfaceTextureListener(this);
    
    /*
     * onSurfaceTextureAvailable does not get called if it is already available.
     */
    if (view.isAvailable()) {
        onSurfaceTextureAvailable(view.getSurfaceTexture(), view.getWidth(), view.getHeight());
    }
    
    0 讨论(0)
  • 2020-12-10 11:30

    i had the same problem , strangely resolved it with the following code

    videoPreview = (TextureView) linearLayout.findViewById(R.id.videoView);
    FrameLayout.LayoutParams params = (FrameLayout.LayoutParams)videoPreview.getLayoutParams();
    params.height = 130;
    params.width = 508;
    videoPreview.setLayoutParams(params);
    videoPreview.setSurfaceTextureListener(this);
    

    More strangely if i set only the width or the height that dosent work either.

    0 讨论(0)
  • 2020-12-10 11:31

    In my case I initially had my TextureView invisible and then loaded after fetching some data and this was causing onSurfaceTextureAvailable not to be called. I am guessing that for TextureView to be said to be 'available', it must be visible. My solution was to just make the TextureView visible from the start.

    0 讨论(0)
  • 2020-12-10 11:32

    I have met the same issue, onSurfaceTextureAvailable never called. Finally I found my textureview is invisible before setSurfaceTextureListener. So check status of textureview at first.

    0 讨论(0)
提交回复
热议问题