studio how change activity activities android-fragments videoview android blink

android fragments - how - Video parpadea una vez en onCreate of previous fragment



how to handle orientation change in android (1)

VideoView hereda de SurfaceView, SurfaceView causa este problema. intente agregar SurfaceView ficticio a su vista principal cuando se cargue su aplicación (en onCreate ...). me arregló el problema

He creado una aplicación para la pestaña galaxy utilizando fragmentos. Tengo una video-vista en un fragmento para reproducir videos de almacenamiento externo.

Aquí está el código para ese fragmento:

package com.example.hscroll.demo; import android.content.res.Configuration; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.MediaController; import android.widget.RelativeLayout; import android.widget.VideoView; public class FragmentVideo1 extends Fragment implements OnTouchListener{ LayoutInflater inflater; private VideoView video; private MediaController ctlr; int length = 0; boolean isPlaying = false; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstance) { this.inflater = inflater; if(container == null)return null; if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { container = (LinearLayout)inflater.inflate(R.layout.video, container, false); video=(VideoView)container.findViewById(R.id.video); video.setVideoPath("/mnt/sdcard/Ideal Solar/video1.mp4"); ctlr=new MediaController(inflater.getContext()); ctlr.setMediaPlayer(video); video.setMediaController(ctlr); video.requestFocus(); }else { container = (RelativeLayout)inflater.inflate(R.layout.video_land, container, false); video=(VideoView)container.findViewById(R.id.myVideo_land); video.setVideoPath("/mnt/sdcard/Ideal Solar/video1.mp4"); ctlr=new MediaController(inflater.getContext()); ctlr.setMediaPlayer(video); video.setMediaController(ctlr); video.requestFocus(); video.start(); } return container; } }

Cuando llego al fragmento antes de este fragmento de video, parpadea una vez (Como el fragmento de video es visible debajo de este fragmento). Sucede solo por primera vez. Si vuelvo y vuelvo a este fragmento, no parpadeará.

Código para el fragmento antes del fragmento de video -

package com.example.hscroll.demo; import java.io.BufferedInputStream; import java.io.FileInputStream; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; import com.example.hscroll.customer.BitmapWeakReference; import com.example.hscroll.library.imagezoom.ImageViewTouch; public class Fragment2 extends Fragment{ ImageViewTouch imgview ; LayoutInflater inflater; FileInputStream in; BufferedInputStream buf; BitmapWeakReference bitmap; ViewGroup con; static Fragment2 frag2; public static Fragment2 newInstance(int num) { if(frag2 == null) frag2 = new Fragment2(); return frag2; } private final String PATH = "/mnt/sdcard/Ideal Solar/page_03.png"; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstance) { this.inflater = inflater; if(container == null)return null; container = (LinearLayout)inflater.inflate(R.layout.fragment0_layout, container, false); con = container; imgview= (ImageViewTouch)container.findViewById(R.id.imageView1); bitmap = new BitmapWeakReference(imgview.selectImage(inflater.getContext(), PATH)); if(bitmap!=null) imgview.setImageBitmapReset( bitmap.get(), true ); return container; } @Override public void onDestroyView() { super.onDestroyView(); imgview.setImageBitmap(null); bitmap.clear(); bitmap = null; Fragment1.unbindDrawables(con.findViewById(R.id.ll)); System.gc(); } }

Solo estoy mostrando una imagen en este fragmento.

XML para fragmento de video -

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/header" android:background="@drawable/video_header"/> <VideoView android:id="@+id/video" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout>

Gracias de antemano por cualquier persona que pueda ayudar.