2012-03-06 4 views
2

フラグメントを使用してgalaxyタブ用のアプリケーションを作成しました。外部ストレージからビデオをフラグメント化したビデオビューがあります。 (ビデオ断片は、この断片以下表示されているように)ビデオが一度点滅する前のフラグメントのonCreate

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

    } 

私はこのビデオフラグメント前断片に来て、それが一度点滅 - ここ

その断片のコードです。それは初めての時だけ起こります。私が戻ってこの断片に再び来たら、それはまばたきしません。

ビデオフラグメントの前にフラグメントのためのコード -

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

    } 

私はこの断片上の画像を示しています。ビデオフラグメントのための

XML - 助けることができる人のため事前に

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

感謝。

答えて

6

VideoViewがSurfaceViewから継承すると、SurfaceViewが原因でこの問題が発生します。 アプリが読み込まれたときに、メインビューにダミーSurfaceViewを追加してみてください(onCreate ...)。 私の問題を解決しました。

+1

私もビデオフラグメントを起動すると、最初のBG(壁紙画面)を表示し、次にビデオフラグメントを表示します。私はonPreparedListener(..)を使用しようとしましたが、同じ結果が...あなたのコードをここで共有してください? – CoDe

+0

天才、魅力的に働いた。 –

+0

こんにちは、あなたは@ Shubhが書いたものを準備しています - あなたがしたことの詳細を少し詳しく教えてください。 – Kibi

関連する問題