视频闪烁一次在previous片段的onCreate片段、视频、previous、onCreate

2023-09-05 04:24:20 作者:老死不相往來

我已经使用fragments.I有一个片段videoview从外部存储发青视频创造了Galaxy Tab的一个应用程序。

I have created an app for galaxy tab using fragments.I have a videoview on a fragment to paly video from external storage.

下面是code该片段 -

Here is the code for that fragment -

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;
}

    }

当我来到这个视频片段之前的片段,它闪一次(如视频片段可见该片段如下)。它只发生在第一时间。如果我回去再来这个片段,它不会闪烁。

When i come to the fragment before this video fragment,it blinks once(Like the video fragment is visible below this fragment). It happens only for the first time.If i go back and come again to this fragment it wont blink.

$ C $下的视频片段前的片段 -

Code for the fragment before video fragment -

   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();
    }

    }

我只是显示这个片段上的图像。

I am just showing an image on this fragment.

XML的视频片段 -

XML for video fragment -

<?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>

在此先感谢的人谁可以提供帮助。

Thanks in advance for anyone who can help.

推荐答案

VideoView从SurfaceView继承,SurfaceView导致此问题。 尝试添加一个虚拟SurfaceView您MAINVIEW当你的应用程序加载(中的onCreate ...)。 解决了这个问题对我来说。

VideoView inherits from SurfaceView, SurfaceView cause this problem. try adding a dummy SurfaceView to your mainView when your app loads (in onCreate...). fixed the problem for me.