1

I want to hide ImageView Thumbnail after Remote Video ready to play, means when onPrepared execute but imageView.setVisibility(View.GONE) doesn't works at all.

I have seen this answers one, two and I think cause is SurfaceView or VideoView. as per answers

I have tried using both MediaPlayer and VideoView

code using MediaPlayer and SurfaceView

mMediaPlayer = new MediaPlayer();
        holder.surfaceView.setDrawingCacheEnabled(true);
        try {
            mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            mMediaPlayer.setDataSource(mContext, Uri.parse(video_url));
            mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mp) {
                    mp.start();
                    ((Activity)mContext).runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                        holder.imgThumbnail.getParent().requestTransparentRegion(holder.imgThumbnail);
                        holder.imgThumbnail.setVisibility(View.GONE);
                        holder.imgThumbnail.getParent().requestTransparentRegion(holder.imgThumbnail);
                        }
                    });
                    Toast.makeText(mContext,"onPrepared",Toast.LENGTH_LONG).show();

                }
            });

        } catch (IllegalArgumentException | SecurityException | IllegalStateException | IOException e) {
            e.printStackTrace();
        }

        mMediaPlayer.prepareAsync();

XML of SurfaceView

<RelativeLayout
        android:layout_width="410dp"
        android:id="@+id/v_view"
        android:visibility="visible"
        android:layout_height="307.50dp">

        <SurfaceView
            android:id="@+id/video_view"
            android:layout_width="410dp"
            android:layout_height="307.50dp"
             />

        <ImageView
            android:id="@+id/imgThumbnail"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:visibility="visible"
            android:scaleType="centerCrop" />
    </RelativeLayout>

code using VideoView

videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer mediaPlayer) {
        Log.i(TAG,"onPrepared");
        new  Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                videoView.start();
                Toast.makeText(mContext,"start video",Toast.LENGTH_LONG).show();

                ((Activity)mContext).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {


                    holder.imgThumbnail.getParent().
                    requestTransparentRegion(holder.imgThumbnail);

                    holder.imgThumbnail.setVisibility(View.GONE);
                    holder.imgThumbnail.getParent().
                    requestTransparentRegion(holder.imgThumbnail);
                    }
                });
            }
        },100);
    }
});

XML of VideoView

<RelativeLayout
        android:layout_width="410dp"
        android:id="@+id/v_view"
        android:visibility="visible"
        android:layout_height="307.50dp">

        <VideoView
            android:id="@+id/video_view"
            android:layout_width="410dp"
            android:layout_height="307.50dp"
             />

        <ImageView
            android:id="@+id/imgThumbnail"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:visibility="gone"
            android:background="@color/back_orange"
            android:scaleType="centerCrop" />
    </RelativeLayout>

Please help! I'm stuck

Community
  • 1
  • 1
Kishore Jethava
  • 6,666
  • 5
  • 35
  • 51

0 Answers0